Skip to content

Commit

Permalink
core/state: copy the snap when copying the state (ethereum#22340)
Browse files Browse the repository at this point in the history
* core/state: copy the snap when copying the state

* core/state: deep-copy snap stuff during state Copy
  • Loading branch information
holiman authored Feb 18, 2021
1 parent e01096f commit 52e5c38
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,31 @@ func (s *StateDB) Copy() *StateDB {
if s.prefetcher != nil {
state.prefetcher = s.prefetcher.copy()
}
if s.snaps != nil {
// In order for the miner to be able to use and make additions
// to the snapshot tree, we need to copy that aswell.
// Otherwise, any block mined by ourselves will cause gaps in the tree,
// and force the miner to operate trie-backed only
state.snaps = s.snaps
state.snap = s.snap
// deep copy needed
state.snapDestructs = make(map[common.Hash]struct{})
for k, v := range s.snapDestructs {
state.snapDestructs[k] = v
}
state.snapAccounts = make(map[common.Hash][]byte)
for k, v := range s.snapAccounts {
state.snapAccounts[k] = v
}
state.snapStorage = make(map[common.Hash]map[common.Hash][]byte)
for k, v := range s.snapStorage {
temp := make(map[common.Hash][]byte)
for kk, vv := range v {
temp[kk] = vv
}
state.snapStorage[k] = temp
}
}
return state
}

Expand Down

0 comments on commit 52e5c38

Please sign in to comment.