Skip to content

Commit

Permalink
add log deepcopy to ensure complete replica of state
Browse files Browse the repository at this point in the history
implement "deep copy" as go-ethereum
  • Loading branch information
wanwiset25 committed Mar 20, 2024
1 parent 42c57c6 commit 6f5c46c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6f5c46c

Please sign in to comment.