From e907c1802ffe5a437bff548ffc2977d459885013 Mon Sep 17 00:00:00 2001 From: bendanzhentan <455462586@qq.com> Date: Tue, 16 Jan 2024 18:16:06 +0800 Subject: [PATCH] wip --- trie/proof.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/trie/proof.go b/trie/proof.go index 5aa18b4c4..768dc1795 100644 --- a/trie/proof.go +++ b/trie/proof.go @@ -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" @@ -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 @@ -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:] @@ -64,13 +69,13 @@ 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)) } @@ -78,6 +83,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e hasher := newHasher(false) defer returnHasherToPool(hasher) + pushed := 0 for i, n := range nodes { if fromLevel > 0 { fromLevel-- @@ -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 }