Skip to content

Commit 328de18

Browse files
committed
core/state: fix resurrection state clearing and access
1 parent dcb22a9 commit 328de18

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎core/state/state_object.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
204204
if metrics.EnabledExpensive {
205205
defer func(start time.Time) { s.db.SnapshotStorageReads += time.Since(start) }(time.Now())
206206
}
207+
// If the object was destructed in *this* block (and potentially resurrected),
208+
// the storage has been cleared out, and we should *not* consult the previous
209+
// snapshot about any storage values. The only possible alternatives are:
210+
// 1) resurrect happened, and new slot values were set -- those should
211+
// have been handles via pendingStorage above.
212+
// 2) we don't have new values, and can deliver empty response back
213+
if _, destructed := s.db.snapDestructs[s.addrHash]; destructed {
214+
return common.Hash{}
215+
}
207216
enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key[:]))
208217
}
209218
// If snapshot unavailable or reading from it failed, load from the database

‎core/state/statedb.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ func (s *StateDB) CreateAccount(addr common.Address) {
595595
if prev != nil {
596596
newObj.setBalance(prev.data.Balance)
597597
}
598+
if s.snap != nil && prev != nil {
599+
s.snapDestructs[prev.addrHash] = struct{}{}
600+
}
598601
}
599602

600603
func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error {
@@ -855,7 +858,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
855858
log.Warn("Failed to cap snapshot tree", "root", root, "layers", 127, "err", err)
856859
}
857860
}
858-
s.snap, s.snapAccounts, s.snapStorage = nil, nil, nil
861+
s.snap, s.snapDestructs, s.snapAccounts, s.snapStorage = nil, nil, nil, nil
859862
}
860863
return root, err
861864
}

0 commit comments

Comments
 (0)