From bdb678726072908d1e6b0d4f5c90842d0a3b3694 Mon Sep 17 00:00:00 2001 From: 0xbundler <124862913+0xbundler@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:25:29 +0800 Subject: [PATCH] trie: support revive from prefix; --- trie/trie.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/trie/trie.go b/trie/trie.go index f8976bd433..d7149b23a5 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -1301,11 +1301,9 @@ func (t *Trie) tryRevive(n node, key []byte, targetPrefixKey []byte, nub MPTProo } if pos == len(targetPrefixKey) { - - // TODO(0xbundler): just revive the path, it may expire or prune by old state - //if !isExpired { - // return nil, false, NewReviveNotExpiredErr(targetPrefixKey[:pos], epoch) - //} + if !t.isExpiredNode(n, targetPrefixKey, epoch, isExpired) { + return nil, false, NewReviveNotExpiredErr(targetPrefixKey[:pos], epoch) + } hn, ok := n.(hashNode) if !ok { return nil, false, fmt.Errorf("not match hashNode stub") @@ -1758,3 +1756,18 @@ func (t *Trie) UpdateRootEpoch(epoch types.StateEpoch) { func (t *Trie) UpdateCurrentEpoch(epoch types.StateEpoch) { t.currentEpoch = epoch } + +// isExpiredNode check if expired or missed, it may prune by old state snap +func (t *Trie) isExpiredNode(n node, targetPrefixKey []byte, epoch types.StateEpoch, expired bool) bool { + if expired { + return true + } + + // check if there miss the trie node + _, err := t.resolve(n, targetPrefixKey, epoch) + if _, ok := err.(*MissingNodeError); ok { + return true + } + + return false +}