Skip to content

Commit 52e5c38

Browse files
authored
core/state: copy the snap when copying the state (#22340)
* core/state: copy the snap when copying the state * core/state: deep-copy snap stuff during state Copy
1 parent e01096f commit 52e5c38

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎core/state/statedb.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,31 @@ func (s *StateDB) Copy() *StateDB {
728728
if s.prefetcher != nil {
729729
state.prefetcher = s.prefetcher.copy()
730730
}
731+
if s.snaps != nil {
732+
// In order for the miner to be able to use and make additions
733+
// to the snapshot tree, we need to copy that aswell.
734+
// Otherwise, any block mined by ourselves will cause gaps in the tree,
735+
// and force the miner to operate trie-backed only
736+
state.snaps = s.snaps
737+
state.snap = s.snap
738+
// deep copy needed
739+
state.snapDestructs = make(map[common.Hash]struct{})
740+
for k, v := range s.snapDestructs {
741+
state.snapDestructs[k] = v
742+
}
743+
state.snapAccounts = make(map[common.Hash][]byte)
744+
for k, v := range s.snapAccounts {
745+
state.snapAccounts[k] = v
746+
}
747+
state.snapStorage = make(map[common.Hash]map[common.Hash][]byte)
748+
for k, v := range s.snapStorage {
749+
temp := make(map[common.Hash][]byte)
750+
for kk, vv := range v {
751+
temp[kk] = vv
752+
}
753+
state.snapStorage[k] = temp
754+
}
755+
}
731756
return state
732757
}
733758

0 commit comments

Comments
 (0)