[release/1.4.16] core/state: rename Delete/IsDeleted to Suicide/HasSuicided

The delete/remove naming has caused endless confusion in the past.

(cherry picked from commit 90fce8bfa6)
pull/3098/head
Felix Lange 8 years ago
parent 46a527d014
commit 74d5251b70
  1. 6
      core/state/journal.go
  2. 12
      core/state/state_object.go
  3. 8
      core/state/state_test.go
  4. 22
      core/state/statedb.go
  5. 6
      core/state/statedb_test.go
  6. 7
      core/vm/environment.go
  7. 2
      core/vm/instructions.go
  8. 2
      core/vm/jit.go
  9. 2
      core/vm/vm.go

@ -36,7 +36,7 @@ type (
resetObjectChange struct { resetObjectChange struct {
prev *StateObject prev *StateObject
} }
deleteAccountChange struct { suicideChange struct {
account *common.Address account *common.Address
prev bool // whether account had already suicided prev bool // whether account had already suicided
prevbalance *big.Int prevbalance *big.Int
@ -79,10 +79,10 @@ func (ch resetObjectChange) undo(s *StateDB) {
s.setStateObject(ch.prev) s.setStateObject(ch.prev)
} }
func (ch deleteAccountChange) undo(s *StateDB) { func (ch suicideChange) undo(s *StateDB) {
obj := s.GetStateObject(*ch.account) obj := s.GetStateObject(*ch.account)
if obj != nil { if obj != nil {
obj.remove = ch.prev obj.suicided = ch.prev
obj.setBalance(ch.prevbalance) obj.setBalance(ch.prevbalance)
} }
} }

@ -83,10 +83,10 @@ type StateObject struct {
dirtyStorage Storage // Storage entries that need to be flushed to disk dirtyStorage Storage // Storage entries that need to be flushed to disk
// Cache flags. // Cache flags.
// When an object is marked for deletion it will be delete from the trie // When an object is marked suicided it will be delete from the trie
// during the "update" phase of the state transition // during the "update" phase of the state transition.
dirtyCode bool // true if the code was updated dirtyCode bool // true if the code was updated
remove bool suicided bool
deleted bool deleted bool
onDirty func(addr common.Address) // Callback method to mark a state object newly dirty onDirty func(addr common.Address) // Callback method to mark a state object newly dirty
} }
@ -123,8 +123,8 @@ func (self *StateObject) setError(err error) {
} }
} }
func (self *StateObject) markForDeletion() { func (self *StateObject) markSuicided() {
self.remove = true self.suicided = true
if self.onDirty != nil { if self.onDirty != nil {
self.onDirty(self.Address()) self.onDirty(self.Address())
self.onDirty = nil self.onDirty = nil
@ -266,7 +266,7 @@ func (self *StateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)
stateObject.code = self.code stateObject.code = self.code
stateObject.dirtyStorage = self.dirtyStorage.Copy() stateObject.dirtyStorage = self.dirtyStorage.Copy()
stateObject.cachedStorage = self.dirtyStorage.Copy() stateObject.cachedStorage = self.dirtyStorage.Copy()
stateObject.remove = self.remove stateObject.suicided = self.suicided
stateObject.dirtyCode = self.dirtyCode stateObject.dirtyCode = self.dirtyCode
stateObject.deleted = self.deleted stateObject.deleted = self.deleted
return stateObject return stateObject

@ -156,7 +156,7 @@ func TestSnapshot2(t *testing.T) {
so0.SetBalance(big.NewInt(42)) so0.SetBalance(big.NewInt(42))
so0.SetNonce(43) so0.SetNonce(43)
so0.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e'}), []byte{'c', 'a', 'f', 'e'}) so0.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e'}), []byte{'c', 'a', 'f', 'e'})
so0.remove = false so0.suicided = false
so0.deleted = false so0.deleted = false
state.setStateObject(so0) state.setStateObject(so0)
@ -168,7 +168,7 @@ func TestSnapshot2(t *testing.T) {
so1.SetBalance(big.NewInt(52)) so1.SetBalance(big.NewInt(52))
so1.SetNonce(53) so1.SetNonce(53)
so1.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e', '2'}), []byte{'c', 'a', 'f', 'e', '2'}) so1.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e', '2'}), []byte{'c', 'a', 'f', 'e', '2'})
so1.remove = true so1.suicided = true
so1.deleted = true so1.deleted = true
state.setStateObject(so1) state.setStateObject(so1)
@ -228,8 +228,8 @@ func compareStateObjects(so0, so1 *StateObject, t *testing.T) {
} }
} }
if so0.remove != so1.remove { if so0.suicided != so1.suicided {
t.Fatalf("Remove mismatch: have %v, want %v", so0.remove, so1.remove) t.Fatalf("suicided mismatch: have %v, want %v", so0.suicided, so1.suicided)
} }
if so0.deleted != so1.deleted { if so0.deleted != so1.deleted {
t.Fatalf("Deleted mismatch: have %v, want %v", so0.deleted, so1.deleted) t.Fatalf("Deleted mismatch: have %v, want %v", so0.deleted, so1.deleted)

@ -275,10 +275,10 @@ func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash {
return common.Hash{} return common.Hash{}
} }
func (self *StateDB) IsDeleted(addr common.Address) bool { func (self *StateDB) HasSuicided(addr common.Address) bool {
stateObject := self.GetStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.remove return stateObject.suicided
} }
return false return false
} }
@ -322,22 +322,22 @@ func (self *StateDB) SetState(addr common.Address, key common.Hash, value common
} }
} }
// Delete marks the given account as suicided. // Suicide marks the given account as suicided.
// This clears the account balance. // This clears the account balance.
// //
// The account's state object is still available until the state is committed, // The account's state object is still available until the state is committed,
// GetStateObject will return a non-nil account after Delete. // GetStateObject will return a non-nil account after Suicide.
func (self *StateDB) Delete(addr common.Address) bool { func (self *StateDB) Suicide(addr common.Address) bool {
stateObject := self.GetStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject == nil { if stateObject == nil {
return false return false
} }
self.journal = append(self.journal, deleteAccountChange{ self.journal = append(self.journal, suicideChange{
account: &addr, account: &addr,
prev: stateObject.remove, prev: stateObject.suicided,
prevbalance: new(big.Int).Set(stateObject.Balance()), prevbalance: new(big.Int).Set(stateObject.Balance()),
}) })
stateObject.markForDeletion() stateObject.markSuicided()
stateObject.data.Balance = new(big.Int) stateObject.data.Balance = new(big.Int)
return true return true
} }
@ -516,7 +516,7 @@ func (self *StateDB) GetRefund() *big.Int {
func (s *StateDB) IntermediateRoot() common.Hash { func (s *StateDB) IntermediateRoot() common.Hash {
for addr, _ := range s.stateObjectsDirty { for addr, _ := range s.stateObjectsDirty {
stateObject := s.stateObjects[addr] stateObject := s.stateObjects[addr]
if stateObject.remove { if stateObject.suicided {
s.deleteStateObject(stateObject) s.deleteStateObject(stateObject)
} else { } else {
stateObject.updateRoot(s.db) stateObject.updateRoot(s.db)
@ -542,7 +542,7 @@ func (s *StateDB) DeleteSuicides() {
// If the object has been removed by a suicide // If the object has been removed by a suicide
// flag the object as deleted. // flag the object as deleted.
if stateObject.remove { if stateObject.suicided {
stateObject.deleted = true stateObject.deleted = true
} }
delete(s.stateObjectsDirty, addr) delete(s.stateObjectsDirty, addr)
@ -575,7 +575,7 @@ func (s *StateDB) commit(dbw trie.DatabaseWriter) (root common.Hash, err error)
// Commit objects to the trie. // Commit objects to the trie.
for addr, stateObject := range s.stateObjects { for addr, stateObject := range s.stateObjects {
if stateObject.remove { if stateObject.suicided {
// If the object has been removed, don't bother syncing it // If the object has been removed, don't bother syncing it
// and just mark it for deletion in the trie. // and just mark it for deletion in the trie.
s.deleteStateObject(stateObject) s.deleteStateObject(stateObject)

@ -202,9 +202,9 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
}, },
}, },
{ {
name: "Delete", name: "Suicide",
fn: func(a testAction, s *StateDB) { fn: func(a testAction, s *StateDB) {
s.Delete(addr) s.Suicide(addr)
}, },
}, },
{ {
@ -323,7 +323,7 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
} }
// Check basic accessor methods. // Check basic accessor methods.
checkeq("Exist", state.Exist(addr), checkstate.Exist(addr)) checkeq("Exist", state.Exist(addr), checkstate.Exist(addr))
checkeq("IsDeleted", state.IsDeleted(addr), checkstate.IsDeleted(addr)) checkeq("HasSuicided", state.HasSuicided(addr), checkstate.HasSuicided(addr))
checkeq("GetBalance", state.GetBalance(addr), checkstate.GetBalance(addr)) checkeq("GetBalance", state.GetBalance(addr), checkstate.GetBalance(addr))
checkeq("GetNonce", state.GetNonce(addr), checkstate.GetNonce(addr)) checkeq("GetNonce", state.GetNonce(addr), checkstate.GetNonce(addr))
checkeq("GetCode", state.GetCode(addr), checkstate.GetCode(addr)) checkeq("GetCode", state.GetCode(addr), checkstate.GetCode(addr))

@ -105,9 +105,12 @@ type Database interface {
GetState(common.Address, common.Hash) common.Hash GetState(common.Address, common.Hash) common.Hash
SetState(common.Address, common.Hash, common.Hash) SetState(common.Address, common.Hash, common.Hash)
Delete(common.Address) bool Suicide(common.Address) bool
HasSuicided(common.Address) bool
// Exist reports whether the given account exists in state.
// Notably this should also return true for suicided accounts.
Exist(common.Address) bool Exist(common.Address) bool
IsDeleted(common.Address) bool
} }
// Account represents a contract or basic ethereum account. // Account represents a contract or basic ethereum account.

@ -614,7 +614,7 @@ func opSuicide(instr instruction, pc *uint64, env Environment, contract *Contrac
balance := env.Db().GetBalance(contract.Address()) balance := env.Db().GetBalance(contract.Address())
env.Db().AddBalance(common.BigToAddress(stack.pop()), balance) env.Db().AddBalance(common.BigToAddress(stack.pop()), balance)
env.Db().Delete(contract.Address()) env.Db().Suicide(contract.Address())
} }
// following functions are used by the instruction jump table // following functions are used by the instruction jump table

@ -425,7 +425,7 @@ func jitCalculateGasAndSize(env Environment, contract *Contract, instr instructi
} }
gas.Set(g) gas.Set(g)
case SUICIDE: case SUICIDE:
if !statedb.IsDeleted(contract.Address()) { if !statedb.HasSuicided(contract.Address()) {
statedb.AddRefund(params.SuicideRefundGas) statedb.AddRefund(params.SuicideRefundGas)
} }
case MLOAD: case MLOAD:

@ -311,7 +311,7 @@ func calculateGasAndSize(env Environment, contract *Contract, caller ContractRef
} }
gas.Set(g) gas.Set(g)
case SUICIDE: case SUICIDE:
if !statedb.IsDeleted(contract.Address()) { if !statedb.HasSuicided(contract.Address()) {
statedb.AddRefund(params.SuicideRefundGas) statedb.AddRefund(params.SuicideRefundGas)
} }
case MLOAD: case MLOAD:

Loading…
Cancel
Save