diff --git a/core/state/journal.go b/core/state/journal.go index 94099f3949..415e07a076 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -34,7 +34,7 @@ type ( account *common.Address } deleteAccountChange struct { - account *common.Address + object *StateObject } // Changes to individual accounts. @@ -65,7 +65,8 @@ type ( ) func (ch deleteAccountChange) undo(s *StateDB) { - s.createStateObject(*ch.account) + ch.object.remove = false + s.SetStateObject(ch.object) } func (ch createAccountChange) undo(s *StateDB) { diff --git a/core/state/statedb.go b/core/state/statedb.go index 62f5b91bc9..00ca9fc83c 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -212,9 +212,11 @@ func (self *StateDB) GetAccount(addr common.Address) vm.Account { func (self *StateDB) GetBalance(addr common.Address) *big.Int { stateObject := self.GetStateObject(addr) if stateObject != nil { + if stateObject.remove { + return new(big.Int) + } return stateObject.Balance() } - return common.Big0 } @@ -318,20 +320,21 @@ func (self *StateDB) SetState(addr common.Address, key common.Hash, value common } func (self *StateDB) Delete(addr common.Address) bool { - self.journal = append(self.journal, deleteAccountChange{account: &addr}) - return self.delete(addr) -} - -func (self *StateDB) delete(addr common.Address) bool { - stateObject := self.GetStateObject(addr) - if stateObject != nil { - stateObject.markForDeletion() - stateObject.data.Balance = new(big.Int) + if object := self.delete(addr); object != nil { + self.journal = append(self.journal, deleteAccountChange{object: object}) return true } return false } +func (self *StateDB) delete(addr common.Address) *StateObject { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + stateObject.markForDeletion() + } + return stateObject +} + // // Setting, updating & deleting state object methods //