Skip to content

Commit

Permalink
fix diffhash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Apr 26, 2022
1 parent dfff219 commit b56c19c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package state

import (
"bytes"
"errors"
"fmt"
"io"
"math/big"
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -274,6 +276,10 @@ func (s *StateObject) GetCommittedState(db Database, key common.Hash) common.Has
}
enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key.Bytes()))
}
// ErrSnapshotStale may occur due to diff layers in the update, so we should try again in noTrie mode.
if s.db.NoTrie() && err != nil && errors.Is(err, snapshot.ErrSnapshotStale) {
return s.GetCommittedState(db, key)
}
// If snapshot unavailable or reading from it failed, load from the database
if s.db.snap == nil || err != nil {
if meter != nil {
Expand Down
14 changes: 11 additions & 3 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,12 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *StateObject {
}
}
}

// ErrSnapshotStale may occur due to diff layers in the update, so we should try again in noTrie mode.
if s.NoTrie() && err != nil && errors.Is(err, snapshot.ErrSnapshotStale) {
return s.getDeletedStateObject(addr)
}

// If snapshot unavailable or reading from it failed, load from the database
if s.snap == nil || err != nil {
if s.trie == nil {
Expand Down Expand Up @@ -1517,9 +1523,11 @@ func (s *StateDB) Commit(failPostCommitFunc func(), postCommitFuncs ...func() er
// - head layer is paired with HEAD state
// - head-1 layer is paired with HEAD-1 state
// - head-(n-1) layer(bottom-most diff layer) is paired with HEAD-(n-1)state
if err := s.snaps.Cap(s.expectedRoot, s.snaps.CapLimit()); err != nil {
log.Warn("Failed to cap snapshot tree", "root", s.expectedRoot, "layers", s.snaps.CapLimit(), "err", err)
}
go func() {
if err := s.snaps.Cap(s.expectedRoot, s.snaps.CapLimit()); err != nil {
log.Warn("Failed to cap snapshot tree", "root", s.expectedRoot, "layers", s.snaps.CapLimit(), "err", err)
}
}()
}
}
return nil
Expand Down

0 comments on commit b56c19c

Please sign in to comment.