mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
core/state: properly restore suicided accounts
This commit is contained in:
parent
e376b473fd
commit
7c613c0fb8
2 changed files with 16 additions and 12 deletions
|
|
@ -34,7 +34,7 @@ type (
|
||||||
account *common.Address
|
account *common.Address
|
||||||
}
|
}
|
||||||
deleteAccountChange struct {
|
deleteAccountChange struct {
|
||||||
account *common.Address
|
object *StateObject
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes to individual accounts.
|
// Changes to individual accounts.
|
||||||
|
|
@ -65,7 +65,8 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ch deleteAccountChange) undo(s *StateDB) {
|
func (ch deleteAccountChange) undo(s *StateDB) {
|
||||||
s.createStateObject(*ch.account)
|
ch.object.remove = false
|
||||||
|
s.SetStateObject(ch.object)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch createAccountChange) undo(s *StateDB) {
|
func (ch createAccountChange) undo(s *StateDB) {
|
||||||
|
|
|
||||||
|
|
@ -212,9 +212,11 @@ func (self *StateDB) GetAccount(addr common.Address) vm.Account {
|
||||||
func (self *StateDB) GetBalance(addr common.Address) *big.Int {
|
func (self *StateDB) GetBalance(addr common.Address) *big.Int {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
|
if stateObject.remove {
|
||||||
|
return new(big.Int)
|
||||||
|
}
|
||||||
return stateObject.Balance()
|
return stateObject.Balance()
|
||||||
}
|
}
|
||||||
|
|
||||||
return common.Big0
|
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 {
|
func (self *StateDB) Delete(addr common.Address) bool {
|
||||||
self.journal = append(self.journal, deleteAccountChange{account: &addr})
|
if object := self.delete(addr); object != nil {
|
||||||
return self.delete(addr)
|
self.journal = append(self.journal, deleteAccountChange{object: object})
|
||||||
}
|
|
||||||
|
|
||||||
func (self *StateDB) delete(addr common.Address) bool {
|
|
||||||
stateObject := self.GetStateObject(addr)
|
|
||||||
if stateObject != nil {
|
|
||||||
stateObject.markForDeletion()
|
|
||||||
stateObject.data.Balance = new(big.Int)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
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
|
// Setting, updating & deleting state object methods
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue