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

This reverts commit 50cb341607.
This commit is contained in:
devopsbo3 2023-11-10 12:27:53 -06:00 committed by GitHub
parent cae472418a
commit 18c9dc5df3
14 changed files with 45 additions and 44 deletions

View file

@ -29,7 +29,7 @@ import (
var ( var (
// ErrNoCode is returned by call and transact operations for which the requested // ErrNoCode is returned by call and transact operations for which the requested
// recipient contract to operate on does not exist in the state db or does not // recipient contract to operate on does not exist in the state db or does not
// have any code associated with it (i.e. self-destructed). // have any code associated with it (i.e. suicided).
ErrNoCode = errors.New("no contract code at given address") ErrNoCode = errors.New("no contract code at given address")
// ErrNoPendingState is raised when attempting to perform a pending state action // ErrNoPendingState is raised when attempting to perform a pending state action

View file

@ -239,7 +239,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
if miningReward >= 0 { if miningReward >= 0 {
// Add mining reward. The mining reward may be `0`, which only makes a difference in the cases // Add mining reward. The mining reward may be `0`, which only makes a difference in the cases
// where // where
// - the coinbase self-destructed, or // - the coinbase suicided, or
// - there are only 'bad' transactions, which aren't executed. In those cases, // - there are only 'bad' transactions, which aren't executed. In those cases,
// the coinbase gets no txfee, so isn't created, and thus needs to be touched // the coinbase gets no txfee, so isn't created, and thus needs to be touched
var ( var (

View file

@ -100,9 +100,9 @@ type (
prevAccountOrigin []byte prevAccountOrigin []byte
prevStorageOrigin map[common.Hash][]byte prevStorageOrigin map[common.Hash][]byte
} }
selfDestructChange struct { suicideChange struct {
account *common.Address account *common.Address
prev bool // whether account had already self-destructed prev bool // whether account had already suicided
prevbalance *big.Int prevbalance *big.Int
} }
@ -184,15 +184,15 @@ func (ch resetObjectChange) dirtied() *common.Address {
return ch.account return ch.account
} }
func (ch selfDestructChange) revert(s *StateDB) { func (ch suicideChange) revert(s *StateDB) {
obj := s.getStateObject(*ch.account) obj := s.getStateObject(*ch.account)
if obj != nil { if obj != nil {
obj.selfDestructed = ch.prev obj.suicided = ch.prev
obj.setBalance(ch.prevbalance) obj.setBalance(ch.prevbalance)
} }
} }
func (ch selfDestructChange) dirtied() *common.Address { func (ch suicideChange) dirtied() *common.Address {
return ch.account return ch.account
} }

View file

@ -78,12 +78,12 @@ type stateObject struct {
// Cache flags. // Cache flags.
dirtyCode bool // true if the code was updated dirtyCode bool // true if the code was updated
// Flag whether the account was marked as self-destructed. The self-destructed account // Flag whether the account was marked as suicided. The suicided account
// is still accessible in the scope of same transaction. // is still accessible in the scope of same transaction.
selfDestructed bool suicided bool
// Flag whether the account was marked as deleted. A self-destructed account // Flag whether the account was marked as deleted. The suicided account
// or an account that is considered as empty will be marked as deleted at // or the account is considered as empty will be marked as deleted at
// the end of transaction and no longer accessible anymore. // the end of transaction and no longer accessible anymore.
deleted bool deleted bool
} }
@ -116,8 +116,8 @@ func (s *stateObject) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &s.data) return rlp.Encode(w, &s.data)
} }
func (s *stateObject) markSelfdestructed() { func (s *stateObject) markSuicided() {
s.selfDestructed = true s.suicided = true
} }
func (s *stateObject) touch() { func (s *stateObject) touch() {
@ -446,7 +446,7 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject {
obj.dirtyStorage = s.dirtyStorage.Copy() obj.dirtyStorage = s.dirtyStorage.Copy()
obj.originStorage = s.originStorage.Copy() obj.originStorage = s.originStorage.Copy()
obj.pendingStorage = s.pendingStorage.Copy() obj.pendingStorage = s.pendingStorage.Copy()
obj.selfDestructed = s.selfDestructed obj.suicided = s.suicided
obj.dirtyCode = s.dirtyCode obj.dirtyCode = s.dirtyCode
obj.deleted = s.deleted obj.deleted = s.deleted
return obj return obj

View file

@ -208,7 +208,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.selfDestructed = false so0.suicided = false
so0.deleted = false so0.deleted = false
state.setStateObject(so0) state.setStateObject(so0)
@ -220,7 +220,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.selfDestructed = true so1.suicided = true
so1.deleted = true so1.deleted = true
state.setStateObject(so1) state.setStateObject(so1)

View file

@ -271,7 +271,7 @@ func (s *StateDB) SubRefund(gas uint64) {
} }
// Exist reports whether the given account address exists in the state. // Exist reports whether the given account address exists in the state.
// Notably this also returns true for self-destructed accounts. // Notably this also returns true for suicided accounts.
func (s *StateDB) Exist(addr common.Address) bool { func (s *StateDB) Exist(addr common.Address) bool {
return s.getStateObject(addr) != nil return s.getStateObject(addr) != nil
} }
@ -397,10 +397,10 @@ func (s *StateDB) StorageTrie(addr common.Address) (Trie, error) {
return cpy.getTrie(s.db) return cpy.getTrie(s.db)
} }
func (s *StateDB) HasSelfDestructed(addr common.Address) bool { func (s *StateDB) HasSuicided(addr common.Address) bool {
stateObject := s.getStateObject(addr) stateObject := s.getStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.selfDestructed return stateObject.suicided
} }
return false return false
} }
@ -474,23 +474,24 @@ func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common
} }
} }
// SelfDestruct marks the given account as selfdestructed. // 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 SelfDestruct. // getStateObject will return a non-nil account after Suicide.
func (s *StateDB) SelfDestruct(addr common.Address) { func (s *StateDB) Suicide(addr common.Address) bool {
stateObject := s.getStateObject(addr) stateObject := s.getStateObject(addr)
if stateObject == nil { if stateObject == nil {
return return false
} }
s.journal.append(selfDestructChange{ s.journal.append(suicideChange{
account: &addr, account: &addr,
prev: stateObject.selfDestructed, prev: stateObject.suicided,
prevbalance: new(big.Int).Set(stateObject.Balance()), prevbalance: new(big.Int).Set(stateObject.Balance()),
}) })
stateObject.markSelfdestructed() stateObject.markSuicided()
stateObject.data.Balance = new(big.Int) stateObject.data.Balance = new(big.Int)
return true
} }
// SetTransientState sets transient storage for a given account. It // SetTransientState sets transient storage for a given account. It
@ -891,7 +892,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
// Thus, we can safely ignore it here // Thus, we can safely ignore it here
continue continue
} }
if obj.selfDestructed || (deleteEmptyObjects && obj.empty()) { if obj.suicided || (deleteEmptyObjects && obj.empty()) {
obj.deleted = true obj.deleted = true
// We need to maintain account deletions explicitly (will remain // We need to maintain account deletions explicitly (will remain

View file

@ -95,9 +95,9 @@ func newStateTestAction(addr common.Address, r *rand.Rand, index int) testAction
}, },
}, },
{ {
name: "Selfdestruct", name: "Suicide",
fn: func(a testAction, s *StateDB) { fn: func(a testAction, s *StateDB) {
s.SelfDestruct(addr) s.Suicide(addr)
}, },
}, },
} }

View file

@ -301,9 +301,9 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
}, },
}, },
{ {
name: "SelfDestruct", name: "Suicide",
fn: func(a testAction, s *StateDB) { fn: func(a testAction, s *StateDB) {
s.SelfDestruct(addr) s.Suicide(addr)
}, },
}, },
{ {
@ -453,7 +453,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("HasSelfdestructed", state.HasSelfDestructed(addr), checkstate.HasSelfDestructed(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))
@ -727,7 +727,7 @@ func TestDeleteCreateRevert(t *testing.T) {
state, _ = New(root, state.db, state.snaps) state, _ = New(root, state.db, state.snaps)
// Simulate self-destructing in one transaction, then create-reverting in another // Simulate self-destructing in one transaction, then create-reverting in another
state.SelfDestruct(addr) state.Suicide(addr)
state.Finalise(true) state.Finalise(true)
id := state.Snapshot() id := state.Snapshot()

View file

@ -472,7 +472,7 @@ func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
} }
} }
if !evm.StateDB.HasSelfDestructed(contract.Address()) { if !evm.StateDB.HasSuicided(contract.Address()) {
evm.StateDB.AddRefund(params.SelfdestructRefundGas) evm.StateDB.AddRefund(params.SelfdestructRefundGas)
} }
return gas, nil return gas, nil

View file

@ -408,7 +408,7 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
// emptyCodeHash. If the precompile account is not transferred any amount on a private or // emptyCodeHash. If the precompile account is not transferred any amount on a private or
// customized chain, the return value will be zero. // customized chain, the return value will be zero.
// //
// 5. Caller tries to get the code hash for an account which is marked as self-destructed // 5. Caller tries to get the code hash for an account which is marked as suicided
// in the current transaction, the code hash of this account should be returned. // in the current transaction, the code hash of this account should be returned.
// //
// 6. Caller tries to get the code hash for an account which is marked as deleted, this // 6. Caller tries to get the code hash for an account which is marked as deleted, this
@ -821,7 +821,7 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
beneficiary := scope.Stack.pop() beneficiary := scope.Stack.pop()
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address()) balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance) interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
interpreter.evm.StateDB.SelfDestruct(scope.Contract.Address()) interpreter.evm.StateDB.Suicide(scope.Contract.Address())
if tracer := interpreter.evm.Config.Tracer; tracer != nil { if tracer := interpreter.evm.Config.Tracer; tracer != nil {
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance) tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
tracer.CaptureExit([]byte{}, 0, nil) tracer.CaptureExit([]byte{}, 0, nil)

View file

@ -51,11 +51,11 @@ type StateDB interface {
GetTransientState(addr common.Address, key common.Hash) common.Hash GetTransientState(addr common.Address, key common.Hash) common.Hash
SetTransientState(addr common.Address, key, value common.Hash) SetTransientState(addr common.Address, key, value common.Hash)
SelfDestruct(common.Address) Suicide(common.Address) bool
HasSelfDestructed(common.Address) bool HasSuicided(common.Address) bool
// Exist reports whether the given account exists in state. // Exist reports whether the given account exists in state.
// Notably this should also return true for self-destructed accounts. // Notably this should also return true for suicided accounts.
Exist(common.Address) bool Exist(common.Address) bool
// Empty returns whether the given account is empty. Empty // Empty returns whether the given account is empty. Empty
// is defined according to EIP161 (balance = nonce = code = 0). // is defined according to EIP161 (balance = nonce = code = 0).

View file

@ -235,7 +235,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc {
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 { if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
gas += params.CreateBySelfdestructGas gas += params.CreateBySelfdestructGas
} }
if refundsEnabled && !evm.StateDB.HasSelfDestructed(contract.Address()) { if refundsEnabled && !evm.StateDB.HasSuicided(contract.Address()) {
evm.StateDB.AddRefund(params.SelfdestructRefundGas) evm.StateDB.AddRefund(params.SelfdestructRefundGas)
} }
return gas, nil return gas, nil

View file

@ -248,7 +248,7 @@ func flatFromNested(input *callFrame, traceAddress []int, convertErrs bool, ctx
case vm.CREATE, vm.CREATE2: case vm.CREATE, vm.CREATE2:
frame = newFlatCreate(input) frame = newFlatCreate(input)
case vm.SELFDESTRUCT: case vm.SELFDESTRUCT:
frame = newFlatSelfdestruct(input) frame = newFlatSuicide(input)
case vm.CALL, vm.STATICCALL, vm.CALLCODE, vm.DELEGATECALL: case vm.CALL, vm.STATICCALL, vm.CALLCODE, vm.DELEGATECALL:
frame = newFlatCall(input) frame = newFlatCall(input)
default: default:
@ -330,7 +330,7 @@ func newFlatCall(input *callFrame) *flatCallFrame {
} }
} }
func newFlatSelfdestruct(input *callFrame) *flatCallFrame { func newFlatSuicide(input *callFrame) *flatCallFrame {
return &flatCallFrame{ return &flatCallFrame{
Type: "suicide", Type: "suicide",
Action: flatCallAction{ Action: flatCallAction{

View file

@ -197,7 +197,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bo
} }
post := t.json.Post[subtest.Fork][subtest.Index] post := t.json.Post[subtest.Fork][subtest.Index]
// N.B: We need to do this in a two-step process, because the first Commit takes care // N.B: We need to do this in a two-step process, because the first Commit takes care
// of self-destructs, and we need to touch the coinbase _after_ it has potentially self-destructed. // of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
if root != common.Hash(post.Root) { if root != common.Hash(post.Root) {
return snaps, statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root) return snaps, statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
} }
@ -275,7 +275,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
} }
// Add 0-value mining reward. This only makes a difference in the cases // Add 0-value mining reward. This only makes a difference in the cases
// where // where
// - the coinbase self-destructed, or // - the coinbase suicided, or
// - there are only 'bad' transactions, which aren't executed. In those cases, // - there are only 'bad' transactions, which aren't executed. In those cases,
// the coinbase gets no txfee, so isn't created, and thus needs to be touched // the coinbase gets no txfee, so isn't created, and thus needs to be touched
statedb.AddBalance(block.Coinbase(), new(big.Int)) statedb.AddBalance(block.Coinbase(), new(big.Int))