Skip to content

Commit

Permalink
core/state, trie: fix bad block
Browse files Browse the repository at this point in the history
add TODO

api fix
  • Loading branch information
asyukii committed Sep 27, 2023
1 parent 10efce7 commit c535e92
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,12 @@ func (s *BlockChainAPI) GetStorageReviveProof(ctx context.Context, stateRoot com
}

stateDb, header, _ = s.b.StateAndHeaderByNumber(ctx, rpc.LatestBlockNumber)
storageTrie, err = s.b.StorageTrie(stateRoot, address, root)
blockNum = hexutil.Uint64(header.Number.Uint64())

storageTrie, err = s.b.StorageTrie(stateRoot, address, root)
if (err != nil || storageTrie == nil) && stateDb != nil {
storageTrie, err = openStorageTrie(stateDb, header, address)
blockNum = hexutil.Uint64(header.Number.Uint64())
log.Info("GetStorageReviveProof from latest block number", "blockNum", blockNum, "blockHash", header.Hash().Hex())
}

if err != nil || storageTrie == nil {
Expand Down
1 change: 0 additions & 1 deletion trie/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)]) {
Expand Down
4 changes: 2 additions & 2 deletions trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c535e92

Please sign in to comment.