Skip to content

Commit 74d5251

Browse files
committed
[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 90fce8b)
1 parent 46a527d commit 74d5251

File tree

9 files changed

+35
-32
lines changed

9 files changed

+35
-32
lines changed

core/state/journal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type (
3636
resetObjectChange struct {
3737
prev *StateObject
3838
}
39-
deleteAccountChange struct {
39+
suicideChange struct {
4040
account *common.Address
4141
prev bool // whether account had already suicided
4242
prevbalance *big.Int
@@ -79,10 +79,10 @@ func (ch resetObjectChange) undo(s *StateDB) {
7979
s.setStateObject(ch.prev)
8080
}
8181

82-
func (ch deleteAccountChange) undo(s *StateDB) {
82+
func (ch suicideChange) undo(s *StateDB) {
8383
obj := s.GetStateObject(*ch.account)
8484
if obj != nil {
85-
obj.remove = ch.prev
85+
obj.suicided = ch.prev
8686
obj.setBalance(ch.prevbalance)
8787
}
8888
}

core/state/state_object.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ type StateObject struct {
8383
dirtyStorage Storage // Storage entries that need to be flushed to disk
8484

8585
// Cache flags.
86-
// When an object is marked for deletion it will be delete from the trie
87-
// during the "update" phase of the state transition
86+
// When an object is marked suicided it will be delete from the trie
87+
// during the "update" phase of the state transition.
8888
dirtyCode bool // true if the code was updated
89-
remove bool
89+
suicided bool
9090
deleted bool
9191
onDirty func(addr common.Address) // Callback method to mark a state object newly dirty
9292
}
@@ -123,8 +123,8 @@ func (self *StateObject) setError(err error) {
123123
}
124124
}
125125

126-
func (self *StateObject) markForDeletion() {
127-
self.remove = true
126+
func (self *StateObject) markSuicided() {
127+
self.suicided = true
128128
if self.onDirty != nil {
129129
self.onDirty(self.Address())
130130
self.onDirty = nil
@@ -266,7 +266,7 @@ func (self *StateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)
266266
stateObject.code = self.code
267267
stateObject.dirtyStorage = self.dirtyStorage.Copy()
268268
stateObject.cachedStorage = self.dirtyStorage.Copy()
269-
stateObject.remove = self.remove
269+
stateObject.suicided = self.suicided
270270
stateObject.dirtyCode = self.dirtyCode
271271
stateObject.deleted = self.deleted
272272
return stateObject

core/state/state_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestSnapshot2(t *testing.T) {
156156
so0.SetBalance(big.NewInt(42))
157157
so0.SetNonce(43)
158158
so0.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e'}), []byte{'c', 'a', 'f', 'e'})
159-
so0.remove = false
159+
so0.suicided = false
160160
so0.deleted = false
161161
state.setStateObject(so0)
162162

@@ -168,7 +168,7 @@ func TestSnapshot2(t *testing.T) {
168168
so1.SetBalance(big.NewInt(52))
169169
so1.SetNonce(53)
170170
so1.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e', '2'}), []byte{'c', 'a', 'f', 'e', '2'})
171-
so1.remove = true
171+
so1.suicided = true
172172
so1.deleted = true
173173
state.setStateObject(so1)
174174

@@ -228,8 +228,8 @@ func compareStateObjects(so0, so1 *StateObject, t *testing.T) {
228228
}
229229
}
230230

231-
if so0.remove != so1.remove {
232-
t.Fatalf("Remove mismatch: have %v, want %v", so0.remove, so1.remove)
231+
if so0.suicided != so1.suicided {
232+
t.Fatalf("suicided mismatch: have %v, want %v", so0.suicided, so1.suicided)
233233
}
234234
if so0.deleted != so1.deleted {
235235
t.Fatalf("Deleted mismatch: have %v, want %v", so0.deleted, so1.deleted)

core/state/statedb.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash {
275275
return common.Hash{}
276276
}
277277

278-
func (self *StateDB) IsDeleted(addr common.Address) bool {
278+
func (self *StateDB) HasSuicided(addr common.Address) bool {
279279
stateObject := self.GetStateObject(addr)
280280
if stateObject != nil {
281-
return stateObject.remove
281+
return stateObject.suicided
282282
}
283283
return false
284284
}
@@ -322,22 +322,22 @@ func (self *StateDB) SetState(addr common.Address, key common.Hash, value common
322322
}
323323
}
324324

325-
// Delete marks the given account as suicided.
325+
// Suicide marks the given account as suicided.
326326
// This clears the account balance.
327327
//
328328
// The account's state object is still available until the state is committed,
329-
// GetStateObject will return a non-nil account after Delete.
330-
func (self *StateDB) Delete(addr common.Address) bool {
329+
// GetStateObject will return a non-nil account after Suicide.
330+
func (self *StateDB) Suicide(addr common.Address) bool {
331331
stateObject := self.GetStateObject(addr)
332332
if stateObject == nil {
333333
return false
334334
}
335-
self.journal = append(self.journal, deleteAccountChange{
335+
self.journal = append(self.journal, suicideChange{
336336
account: &addr,
337-
prev: stateObject.remove,
337+
prev: stateObject.suicided,
338338
prevbalance: new(big.Int).Set(stateObject.Balance()),
339339
})
340-
stateObject.markForDeletion()
340+
stateObject.markSuicided()
341341
stateObject.data.Balance = new(big.Int)
342342
return true
343343
}
@@ -516,7 +516,7 @@ func (self *StateDB) GetRefund() *big.Int {
516516
func (s *StateDB) IntermediateRoot() common.Hash {
517517
for addr, _ := range s.stateObjectsDirty {
518518
stateObject := s.stateObjects[addr]
519-
if stateObject.remove {
519+
if stateObject.suicided {
520520
s.deleteStateObject(stateObject)
521521
} else {
522522
stateObject.updateRoot(s.db)
@@ -542,7 +542,7 @@ func (s *StateDB) DeleteSuicides() {
542542

543543
// If the object has been removed by a suicide
544544
// flag the object as deleted.
545-
if stateObject.remove {
545+
if stateObject.suicided {
546546
stateObject.deleted = true
547547
}
548548
delete(s.stateObjectsDirty, addr)
@@ -575,7 +575,7 @@ func (s *StateDB) commit(dbw trie.DatabaseWriter) (root common.Hash, err error)
575575

576576
// Commit objects to the trie.
577577
for addr, stateObject := range s.stateObjects {
578-
if stateObject.remove {
578+
if stateObject.suicided {
579579
// If the object has been removed, don't bother syncing it
580580
// and just mark it for deletion in the trie.
581581
s.deleteStateObject(stateObject)

core/state/statedb_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
202202
},
203203
},
204204
{
205-
name: "Delete",
205+
name: "Suicide",
206206
fn: func(a testAction, s *StateDB) {
207-
s.Delete(addr)
207+
s.Suicide(addr)
208208
},
209209
},
210210
{
@@ -323,7 +323,7 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
323323
}
324324
// Check basic accessor methods.
325325
checkeq("Exist", state.Exist(addr), checkstate.Exist(addr))
326-
checkeq("IsDeleted", state.IsDeleted(addr), checkstate.IsDeleted(addr))
326+
checkeq("HasSuicided", state.HasSuicided(addr), checkstate.HasSuicided(addr))
327327
checkeq("GetBalance", state.GetBalance(addr), checkstate.GetBalance(addr))
328328
checkeq("GetNonce", state.GetNonce(addr), checkstate.GetNonce(addr))
329329
checkeq("GetCode", state.GetCode(addr), checkstate.GetCode(addr))

core/vm/environment.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ type Database interface {
105105
GetState(common.Address, common.Hash) common.Hash
106106
SetState(common.Address, common.Hash, common.Hash)
107107

108-
Delete(common.Address) bool
108+
Suicide(common.Address) bool
109+
HasSuicided(common.Address) bool
110+
111+
// Exist reports whether the given account exists in state.
112+
// Notably this should also return true for suicided accounts.
109113
Exist(common.Address) bool
110-
IsDeleted(common.Address) bool
111114
}
112115

113116
// Account represents a contract or basic ethereum account.

core/vm/instructions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func opSuicide(instr instruction, pc *uint64, env Environment, contract *Contrac
614614
balance := env.Db().GetBalance(contract.Address())
615615
env.Db().AddBalance(common.BigToAddress(stack.pop()), balance)
616616

617-
env.Db().Delete(contract.Address())
617+
env.Db().Suicide(contract.Address())
618618
}
619619

620620
// following functions are used by the instruction jump table

core/vm/jit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func jitCalculateGasAndSize(env Environment, contract *Contract, instr instructi
425425
}
426426
gas.Set(g)
427427
case SUICIDE:
428-
if !statedb.IsDeleted(contract.Address()) {
428+
if !statedb.HasSuicided(contract.Address()) {
429429
statedb.AddRefund(params.SuicideRefundGas)
430430
}
431431
case MLOAD:

core/vm/vm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func calculateGasAndSize(env Environment, contract *Contract, caller ContractRef
311311
}
312312
gas.Set(g)
313313
case SUICIDE:
314-
if !statedb.IsDeleted(contract.Address()) {
314+
if !statedb.HasSuicided(contract.Address()) {
315315
statedb.AddRefund(params.SuicideRefundGas)
316316
}
317317
case MLOAD:

0 commit comments

Comments
 (0)