@@ -19,6 +19,7 @@ package state
19
19
20
20
import (
21
21
"fmt"
22
+ "maps"
22
23
"sort"
23
24
"time"
24
25
@@ -693,18 +694,18 @@ func (s *StateDB) Copy() *StateDB {
693
694
db : s .db ,
694
695
trie : s .db .CopyTrie (s .trie ),
695
696
originalRoot : s .originalRoot ,
696
- accounts : make ( map [common. Hash ][] byte ),
697
- storages : make ( map [common. Hash ] map [common. Hash ][] byte ),
698
- accountsOrigin : make ( map [common. Address ][] byte ),
699
- storagesOrigin : make ( map [common. Address ] map [common. Hash ][] byte ),
697
+ accounts : copySet ( s . accounts ),
698
+ storages : copy2DSet ( s . storages ),
699
+ accountsOrigin : copySet ( s . accountsOrigin ),
700
+ storagesOrigin : copy2DSet ( s . storagesOrigin ),
700
701
stateObjects : make (map [common.Address ]* stateObject , len (s .journal .dirties )),
701
702
stateObjectsPending : make (map [common.Address ]struct {}, len (s .stateObjectsPending )),
702
703
stateObjectsDirty : make (map [common.Address ]struct {}, len (s .journal .dirties )),
703
- stateObjectsDestruct : make ( map [common. Address ] * types. StateAccount , len (s .stateObjectsDestruct ) ),
704
+ stateObjectsDestruct : maps . Clone (s .stateObjectsDestruct ),
704
705
refund : s .refund ,
705
706
logs : make (map [common.Hash ][]* types.Log , len (s .logs )),
706
707
logSize : s .logSize ,
707
- preimages : make ( map [common. Hash ][] byte , len (s .preimages ) ),
708
+ preimages : maps . Clone (s .preimages ),
708
709
journal : newJournal (),
709
710
hasher : crypto .NewKeccakState (),
710
711
@@ -747,16 +748,6 @@ func (s *StateDB) Copy() *StateDB {
747
748
}
748
749
state .stateObjectsDirty [addr ] = struct {}{}
749
750
}
750
- // Deep copy the destruction markers.
751
- for addr , value := range s .stateObjectsDestruct {
752
- state .stateObjectsDestruct [addr ] = value
753
- }
754
- // Deep copy the state changes made in the scope of block
755
- // along with their original values.
756
- state .accounts = copySet (s .accounts )
757
- state .storages = copy2DSet (s .storages )
758
- state .accountsOrigin = copySet (state .accountsOrigin )
759
- state .storagesOrigin = copy2DSet (state .storagesOrigin )
760
751
761
752
// Deep copy the logs occurred in the scope of block
762
753
for hash , logs := range s .logs {
@@ -767,10 +758,7 @@ func (s *StateDB) Copy() *StateDB {
767
758
}
768
759
state .logs [hash ] = cpy
769
760
}
770
- // Deep copy the preimages occurred in the scope of block
771
- for hash , preimage := range s .preimages {
772
- state .preimages [hash ] = preimage
773
- }
761
+
774
762
// Do we need to copy the access list and transient storage?
775
763
// In practice: No. At the start of a transaction, these two lists are empty.
776
764
// In practice, we only ever copy state _between_ transactions/blocks, never
0 commit comments