Skip to content

Commit b56c19c

Browse files
committed
fix diffhash issue
1 parent dfff219 commit b56c19c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

core/state/state_object.go

+6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ package state
1818

1919
import (
2020
"bytes"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"math/big"
2425
"sync"
2526
"time"
2627

2728
"github.com/ethereum/go-ethereum/common"
29+
"github.com/ethereum/go-ethereum/core/state/snapshot"
2830
"github.com/ethereum/go-ethereum/crypto"
2931
"github.com/ethereum/go-ethereum/metrics"
3032
"github.com/ethereum/go-ethereum/rlp"
@@ -274,6 +276,10 @@ func (s *StateObject) GetCommittedState(db Database, key common.Hash) common.Has
274276
}
275277
enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key.Bytes()))
276278
}
279+
// ErrSnapshotStale may occur due to diff layers in the update, so we should try again in noTrie mode.
280+
if s.db.NoTrie() && err != nil && errors.Is(err, snapshot.ErrSnapshotStale) {
281+
return s.GetCommittedState(db, key)
282+
}
277283
// If snapshot unavailable or reading from it failed, load from the database
278284
if s.db.snap == nil || err != nil {
279285
if meter != nil {

core/state/statedb.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *StateObject {
674674
}
675675
}
676676
}
677+
678+
// ErrSnapshotStale may occur due to diff layers in the update, so we should try again in noTrie mode.
679+
if s.NoTrie() && err != nil && errors.Is(err, snapshot.ErrSnapshotStale) {
680+
return s.getDeletedStateObject(addr)
681+
}
682+
677683
// If snapshot unavailable or reading from it failed, load from the database
678684
if s.snap == nil || err != nil {
679685
if s.trie == nil {
@@ -1517,9 +1523,11 @@ func (s *StateDB) Commit(failPostCommitFunc func(), postCommitFuncs ...func() er
15171523
// - head layer is paired with HEAD state
15181524
// - head-1 layer is paired with HEAD-1 state
15191525
// - head-(n-1) layer(bottom-most diff layer) is paired with HEAD-(n-1)state
1520-
if err := s.snaps.Cap(s.expectedRoot, s.snaps.CapLimit()); err != nil {
1521-
log.Warn("Failed to cap snapshot tree", "root", s.expectedRoot, "layers", s.snaps.CapLimit(), "err", err)
1522-
}
1526+
go func() {
1527+
if err := s.snaps.Cap(s.expectedRoot, s.snaps.CapLimit()); err != nil {
1528+
log.Warn("Failed to cap snapshot tree", "root", s.expectedRoot, "layers", s.snaps.CapLimit(), "err", err)
1529+
}
1530+
}()
15231531
}
15241532
}
15251533
return nil

0 commit comments

Comments
 (0)