From 6f5c46c6998772b5dfabbf1e8b53bcba3746e5a6 Mon Sep 17 00:00:00 2001 From: wanwiset25 Date: Tue, 12 Mar 2024 11:37:23 +0400 Subject: [PATCH] add log deepcopy to ensure complete replica of state implement "deep copy" as go-ethereum --- core/state/statedb.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 4bedebe8b3c3..61084675ab48 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -489,8 +489,8 @@ func (self *StateDB) createObject(addr common.Address) (newobj, prev *stateObjec // CreateAccount is called during the EVM CREATE operation. The situation might arise that // a contract does the following: // -// 1. sends funds to sha(account ++ (nonce + 1)) -// 2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1) +// 1. sends funds to sha(account ++ (nonce + 1)) +// 2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1) // // Carrying over the balance ensures that Ether doesn't disappear. func (self *StateDB) CreateAccount(addr common.Address) { @@ -544,10 +544,17 @@ func (self *StateDB) Copy() *StateDB { state.stateObjects[addr] = self.stateObjects[addr].deepCopy(state, state.MarkStateObjectDirty) state.stateObjectsDirty[addr] = struct{}{} } + + // Deep copy the logs occurred in the scope of block for hash, logs := range self.logs { - state.logs[hash] = make([]*types.Log, len(logs)) - copy(state.logs[hash], logs) + cpy := make([]*types.Log, len(logs)) + for i, l := range logs { + cpy[i] = new(types.Log) + *cpy[i] = *l + } + state.logs[hash] = cpy } + for hash, preimage := range self.preimages { state.preimages[hash] = preimage }