Skip to content

Commit

Permalink
trie: support revive from prefix;
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbundler committed Nov 3, 2023
1 parent 9825ce3 commit bdb6787
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

0 comments on commit bdb6787

Please sign in to comment.