core: replace instances of 'suicide' with 'selfdestruct' to improve code consistency. (#27716)

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
This commit is contained in:
jwasinger
2023-07-15 10:35:30 -04:00
committed by GitHub
co-authored by Martin Holst Swende lightclient
parent 00408f7479
commit d233b6b23a
14 changed files with 44 additions and 45 deletions
+5 -5
View File
@@ -100,9 +100,9 @@ type (
prevAccountOrigin []byte
prevStorageOrigin map[common.Hash][]byte
}
suicideChange struct {
selfDestructChange struct {
account *common.Address
prev bool // whether account had already suicided
prev bool // whether account had already self-destructed
prevbalance *big.Int
}
@@ -184,15 +184,15 @@ func (ch resetObjectChange) dirtied() *common.Address {
return ch.account
}
func (ch suicideChange) revert(s *StateDB) {
func (ch selfDestructChange) revert(s *StateDB) {
obj := s.getStateObject(*ch.account)
if obj != nil {
obj.suicided = ch.prev
obj.selfDestructed = ch.prev
obj.setBalance(ch.prevbalance)
}
}
func (ch suicideChange) dirtied() *common.Address {
func (ch selfDestructChange) dirtied() *common.Address {
return ch.account
}
+7 -7
View File
@@ -78,12 +78,12 @@ type stateObject struct {
// Cache flags.
dirtyCode bool // true if the code was updated
// Flag whether the account was marked as suicided. The suicided account
// Flag whether the account was marked as self-destructed. The self-destructed account
// is still accessible in the scope of same transaction.
suicided bool
selfDestructed bool
// Flag whether the account was marked as deleted. The suicided account
// or the account is considered as empty will be marked as deleted at
// Flag whether the account was marked as deleted. A self-destructed account
// or an account that is considered as empty will be marked as deleted at
// the end of transaction and no longer accessible anymore.
deleted bool
}
@@ -116,8 +116,8 @@ func (s *stateObject) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &s.data)
}
func (s *stateObject) markSuicided() {
s.suicided = true
func (s *stateObject) markSelfdestructed() {
s.selfDestructed = true
}
func (s *stateObject) touch() {
@@ -446,7 +446,7 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject {
obj.dirtyStorage = s.dirtyStorage.Copy()
obj.originStorage = s.originStorage.Copy()
obj.pendingStorage = s.pendingStorage.Copy()
obj.suicided = s.suicided
obj.selfDestructed = s.selfDestructed
obj.dirtyCode = s.dirtyCode
obj.deleted = s.deleted
return obj
+2 -2
View File
@@ -208,7 +208,7 @@ func TestSnapshot2(t *testing.T) {
so0.SetBalance(big.NewInt(42))
so0.SetNonce(43)
so0.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e'}), []byte{'c', 'a', 'f', 'e'})
so0.suicided = false
so0.selfDestructed = false
so0.deleted = false
state.setStateObject(so0)
@@ -220,7 +220,7 @@ func TestSnapshot2(t *testing.T) {
so1.SetBalance(big.NewInt(52))
so1.SetNonce(53)
so1.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e', '2'}), []byte{'c', 'a', 'f', 'e', '2'})
so1.suicided = true
so1.selfDestructed = true
so1.deleted = true
state.setStateObject(so1)
+11 -12
View File
@@ -271,7 +271,7 @@ func (s *StateDB) SubRefund(gas uint64) {
}
// Exist reports whether the given account address exists in the state.
// Notably this also returns true for suicided accounts.
// Notably this also returns true for self-destructed accounts.
func (s *StateDB) Exist(addr common.Address) bool {
return s.getStateObject(addr) != nil
}
@@ -397,10 +397,10 @@ func (s *StateDB) StorageTrie(addr common.Address) (Trie, error) {
return cpy.getTrie(s.db)
}
func (s *StateDB) HasSuicided(addr common.Address) bool {
func (s *StateDB) HasSelfDestructed(addr common.Address) bool {
stateObject := s.getStateObject(addr)
if stateObject != nil {
return stateObject.suicided
return stateObject.selfDestructed
}
return false
}
@@ -474,24 +474,23 @@ func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common
}
}
// Suicide marks the given account as suicided.
// SelfDestruct marks the given account as selfdestructed.
// This clears the account balance.
//
// The account's state object is still available until the state is committed,
// getStateObject will return a non-nil account after Suicide.
func (s *StateDB) Suicide(addr common.Address) bool {
// getStateObject will return a non-nil account after SelfDestruct.
func (s *StateDB) SelfDestruct(addr common.Address) {
stateObject := s.getStateObject(addr)
if stateObject == nil {
return false
return
}
s.journal.append(suicideChange{
s.journal.append(selfDestructChange{
account: &addr,
prev: stateObject.suicided,
prev: stateObject.selfDestructed,
prevbalance: new(big.Int).Set(stateObject.Balance()),
})
stateObject.markSuicided()
stateObject.markSelfdestructed()
stateObject.data.Balance = new(big.Int)
return true
}
// SetTransientState sets transient storage for a given account. It
@@ -892,7 +891,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
// Thus, we can safely ignore it here
continue
}
if obj.suicided || (deleteEmptyObjects && obj.empty()) {
if obj.selfDestructed || (deleteEmptyObjects && obj.empty()) {
obj.deleted = true
// We need to maintain account deletions explicitly (will remain
+2 -2
View File
@@ -95,9 +95,9 @@ func newStateTestAction(addr common.Address, r *rand.Rand, index int) testAction
},
},
{
name: "Suicide",
name: "Selfdestruct",
fn: func(a testAction, s *StateDB) {
s.Suicide(addr)
s.SelfDestruct(addr)
},
},
}
+4 -4
View File
@@ -301,9 +301,9 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
},
},
{
name: "Suicide",
name: "SelfDestruct",
fn: func(a testAction, s *StateDB) {
s.Suicide(addr)
s.SelfDestruct(addr)
},
},
{
@@ -453,7 +453,7 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
}
// Check basic accessor methods.
checkeq("Exist", state.Exist(addr), checkstate.Exist(addr))
checkeq("HasSuicided", state.HasSuicided(addr), checkstate.HasSuicided(addr))
checkeq("HasSelfdestructed", state.HasSelfDestructed(addr), checkstate.HasSelfDestructed(addr))
checkeq("GetBalance", state.GetBalance(addr), checkstate.GetBalance(addr))
checkeq("GetNonce", state.GetNonce(addr), checkstate.GetNonce(addr))
checkeq("GetCode", state.GetCode(addr), checkstate.GetCode(addr))
@@ -727,7 +727,7 @@ func TestDeleteCreateRevert(t *testing.T) {
state, _ = New(root, state.db, state.snaps)
// Simulate self-destructing in one transaction, then create-reverting in another
state.Suicide(addr)
state.SelfDestruct(addr)
state.Finalise(true)
id := state.Snapshot()