Skip to content

Commit dcb22a9

Browse files
committed
core/state: fix account root hash update point
1 parent a4cf279 commit dcb22a9

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎core/state/statedb.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
466466
panic(fmt.Errorf("can't encode object at %x: %v", addr[:], err))
467467
}
468468
s.setError(s.trie.TryUpdate(addr[:], data))
469+
470+
// If state snapshotting is active, cache the data til commit. Note, this
471+
// update mechanism is not symmetric to the deletion, because whereas it is
472+
// enough to track account updates at commit time, deletions need tracking
473+
// at transaction boundary level to ensure we capture state clearing.
474+
if s.snap != nil {
475+
s.snapAccounts[obj.addrHash] = snapshot.AccountRLP(obj.data.Nonce, obj.data.Balance, obj.data.Root, obj.data.CodeHash)
476+
}
469477
}
470478

471479
// deleteStateObject removes the given object from the state trie.
@@ -729,19 +737,14 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
729737
// If state snapshotting is active, also mark the destruction there.
730738
// Note, we can't do this only at the end of a block because multiple
731739
// transactions within the same block might self destruct and then
732-
// ressurrect an account and the snapshotter needs both events.
740+
// ressurrect an account; but the snapshotter needs both events.
733741
if s.snap != nil {
734742
s.snapDestructs[obj.addrHash] = struct{}{} // We need to maintain account deletions explicitly (will remain set indefinitely)
735743
delete(s.snapAccounts, obj.addrHash) // Clear out any previously updated account data (may be recreated via a ressurrect)
736744
delete(s.snapStorage, obj.addrHash) // Clear out any previously updated storage data (may be recreated via a ressurrect)
737745
}
738746
} else {
739747
obj.finalise()
740-
741-
// If state snapshotting is active, cache the data til commit
742-
if s.snap != nil {
743-
s.snapAccounts[obj.addrHash] = snapshot.AccountRLP(obj.data.Nonce, obj.data.Balance, obj.data.Root, obj.data.CodeHash)
744-
}
745748
}
746749
s.stateObjectsPending[addr] = struct{}{}
747750
s.stateObjectsDirty[addr] = struct{}{}

0 commit comments

Comments
 (0)