diff --git a/core/state/statedb.go b/core/state/statedb.go index 79912b8865..3c7c60d65a 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -19,6 +19,7 @@ package state import ( "fmt" + "maps" "math/big" "sort" "time" @@ -637,7 +638,7 @@ func (s *StateDB) Copy() *StateDB { refund: s.refund, logs: make(map[common.Hash][]*types.Log, len(s.logs)), logSize: s.logSize, - preimages: make(map[common.Hash][]byte), + preimages: maps.Clone(s.preimages), journal: newJournal(), } // Copy the dirty states, logs, and preimages @@ -683,9 +684,6 @@ func (s *StateDB) Copy() *StateDB { state.logs[hash] = cpy } - for hash, preimage := range s.preimages { - state.preimages[hash] = preimage - } // Do we need to copy the access list? In practice: No. At the start of a // transaction, the access list is empty. In practice, we only ever copy state // _between_ transactions/blocks, never in the middle of a transaction. diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index e7d54fc3d7..0aa1f6ef4d 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -305,6 +305,15 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction { }, args: make([]int64, 2), }, + { + name: "AddPreimage", + fn: func(a testAction, s *StateDB) { + preimage := []byte{1} + hash := common.BytesToHash(preimage) + s.AddPreimage(hash, preimage) + }, + args: make([]int64, 1), + }, } action := actions[r.Intn(len(actions))] var nameargs []string