Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanzhentan committed Jan 16, 2024
1 parent 815c7c9 commit e907c18
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion trie/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/status-im/keycard-go/hexutils"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
Expand All @@ -40,10 +41,13 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e
nodes []node
tn = t.root
)
i := 0
marker := hexutils.BytesToHex(keybytesToHex(key))
key = keybytesToHex(key)
for len(key) > 0 && tn != nil {
switch n := tn.(type) {
case *shortNode:
log.Info("bilibili loop", "marker", marker, "i", i, "type", "ShortNode", "n", n, "key", key, "n.Key", n.Key)
if len(key) < len(n.Key) || !bytes.Equal(n.Key, key[:len(n.Key)]) {
// The trie doesn't contain the key.
tn = nil
Expand All @@ -54,6 +58,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e
}
nodes = append(nodes, n)
case *fullNode:
log.Info("bilibili loop", "marker", marker, "i", i, "type", "FullNode", "n", n, "key", key)
tn = n.Children[key[0]]
prefix = append(prefix, key[0])
key = key[1:]
Expand All @@ -64,20 +69,21 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e
// loaded blob will be tracked, while it's not required here since
// all loaded nodes won't be linked to trie at all and track nodes
// may lead to out-of-memory issue.
log.Info("bilibili loop", "marker", marker, "i", i, "type", "HashNode", "n", n, "key", key)
var err error
tn, err = t.reader.node(prefix, common.BytesToHash(n))
if err != nil {
log.Error("Unhandled trie error in Trie.Prove", "err", err)
return err
}
nodes = append(nodes, n)
default:
panic(fmt.Sprintf("%T: invalid node: %v", tn, tn))
}
}
hasher := newHasher(false)
defer returnHasherToPool(hasher)

pushed := 0
for i, n := range nodes {
if fromLevel > 0 {
fromLevel--
Expand All @@ -93,11 +99,13 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e
hash = hasher.hashData(enc)
}
proofDb.Put(hash, enc)
pushed++
log.Info("bilibili pushed", "i", i, "node", n)
} else {
log.Info("bilibili discard", "i", i, "node", n)
}
}
log.Info("bilibili finish", "marker", marker, "nodes", len(nodes), "i", "pushed", pushed)
return nil
}

Expand Down

0 comments on commit e907c18

Please sign in to comment.