From 062004b2c0111d0f7968dcef52a52aa6dfd609c6 Mon Sep 17 00:00:00 2001 From: asyukii Date: Tue, 26 Sep 2023 17:49:42 +0800 Subject: [PATCH] core/state, trie: fix bad block add TODO --- core/state/state_object.go | 7 ++++++- trie/proof.go | 1 - trie/trie.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index d5979ec837..c8d20392c2 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -800,7 +800,12 @@ func (s *stateObject) fetchExpiredFromRemote(prefixKey []byte, key common.Hash, // if no prefix, query from revive trie, got the newest expired info if resolvePath { - _, err := tr.GetStorage(s.address, key.Bytes()) + val, err := tr.GetStorage(s.address, key.Bytes()) + // TODO(asyukii): temporary fix snap expired, but trie not expire, may investigate more later. + if val != nil { + s.pendingReviveState[string(crypto.Keccak256(key[:]))] = common.BytesToHash(val) + return val, nil + } enErr, ok := err.(*trie.ExpiredNodeError) if !ok { return nil, fmt.Errorf("cannot find expired state from trie, err: %v", err) diff --git a/trie/proof.go b/trie/proof.go index a88ae6eacb..c67b3d6c3b 100644 --- a/trie/proof.go +++ b/trie/proof.go @@ -120,7 +120,6 @@ func (t *StateTrie) Prove(key []byte, proofDb ethdb.KeyValueWriter) error { // it. func (t *Trie) traverseNodes(tn node, prefixKey, suffixKey []byte, nodes *[]node, epoch types.StateEpoch, updateEpoch bool) (node, error) { for len(suffixKey) > 0 && tn != nil { - log.Info("traverseNodes loop", "prefix", common.Bytes2Hex(prefixKey), "suffix", common.Bytes2Hex(suffixKey), "n", tn.fstring("")) switch n := tn.(type) { case *shortNode: if len(suffixKey) >= len(n.Key) && bytes.Equal(n.Key, suffixKey[:len(n.Key)]) { diff --git a/trie/trie.go b/trie/trie.go index 27ff3134f4..0fbb8f69ac 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -1238,8 +1238,8 @@ func (t *Trie) tryRevive(n node, key []byte, targetPrefixKey []byte, nub MPTProo n1 = n1.copy() n1.Val = newnode n1.flags = t.newFlag() - tryUpdateNodeEpoch(nub.n1, t.currentEpoch) - renew, _, err := t.updateChildNodeEpoch(nub.n1, key, pos, t.currentEpoch) + tryUpdateNodeEpoch(n1, t.currentEpoch) + renew, _, err := t.updateChildNodeEpoch(n1, key, pos, t.currentEpoch) if err != nil { return nil, false, fmt.Errorf("update child node epoch while reviving failed, err: %v", err) }