core: remove block number assignment in log

This commit is contained in:
Gary Rong 2026-03-23 20:55:07 +08:00
parent b8939107a2
commit c86093a934
7 changed files with 13 additions and 24 deletions

View file

@ -139,10 +139,10 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *uint256.Int) bool {
}
// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int, blockNumber *big.Int, rules *params.Rules) {
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int, rules *params.Rules) {
db.SubBalance(sender, amount, tracing.BalanceChangeTransfer)
db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer)
if rules.IsAmsterdam && !amount.IsZero() && sender != recipient {
db.AddLog(types.EthTransferLog(blockNumber, sender, recipient, amount))
db.AddLog(types.EthTransferLog(sender, recipient, amount))
}
}

View file

@ -176,7 +176,7 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB,
if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) {
// Emit burn logs where accounts with non-empty balances have been deleted
for _, sd := range statedb.GetRemovedAccountsWithBalance() {
statedb.AddLog(types.EthBurnLog(blockNumber, sd.Address, sd.Balance))
statedb.AddLog(types.EthBurnLog(sd.Address, sd.Balance))
}
}
// Update the state with pending changes.

View file

@ -17,8 +17,6 @@
package types
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/params"
@ -69,7 +67,7 @@ type logMarshaling struct {
// EthTransferLog creates and ETH transfer log according to EIP-7708.
// Specification: https://eips.ethereum.org/EIPS/eip-7708
func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log {
func EthTransferLog(from, to common.Address, amount *uint256.Int) *Log {
amount32 := amount.Bytes32()
return &Log{
Address: params.SystemAddress,
@ -79,15 +77,12 @@ func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint2
common.BytesToHash(to.Bytes()),
},
Data: amount32[:],
// This is a non-consensus field, but assigned here because
// core/state doesn't know the current block number.
BlockNumber: blockNumber.Uint64(),
}
}
// EthBurnLog creates an ETH burn log according to EIP-7708.
// Specification: https://eips.ethereum.org/EIPS/eip-7708
func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log {
func EthBurnLog(from common.Address, amount *uint256.Int) *Log {
amount32 := amount.Bytes32()
return &Log{
Address: params.SystemAddress,
@ -96,8 +91,5 @@ func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int)
common.BytesToHash(from.Bytes()),
},
Data: amount32[:],
// This is a non-consensus field, but assigned here because
// core/state doesn't know the current block number.
BlockNumber: blockNumber.Uint64(),
}
}

View file

@ -35,7 +35,7 @@ type (
// CanTransferFunc is the signature of a transfer guard function
CanTransferFunc func(StateDB, common.Address, *uint256.Int) bool
// TransferFunc is the signature of a transfer function
TransferFunc func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules)
TransferFunc func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules)
// GetHashFunc returns the n'th block hash in the blockchain
// and is used by the BLOCKHASH EVM op code.
GetHashFunc func(uint64) common.Hash
@ -283,7 +283,7 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g
// Calling this is required even for zero-value transfers,
// to ensure the state clearing mechanism is applied.
if !syscall {
evm.Context.Transfer(evm.StateDB, caller, addr, value, evm.Context.BlockNumber, &evm.chainRules)
evm.Context.Transfer(evm.StateDB, caller, addr, value, &evm.chainRules)
}
if isPrecompile {
@ -568,7 +568,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas uint64, value *ui
}
gas = gas - consumed
}
evm.Context.Transfer(evm.StateDB, caller, address, value, evm.Context.BlockNumber, &evm.chainRules)
evm.Context.Transfer(evm.StateDB, caller, address, value, &evm.chainRules)
// Initialise a new contract and set the code that is to be used by the EVM.
// The contract is a scoped environment for this execution context only.

View file

@ -94,7 +94,7 @@ func TestEIP2200(t *testing.T) {
vmctx := BlockContext{
CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true },
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {},
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) {},
}
evm := NewEVM(vmctx, statedb, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}})
@ -144,7 +144,7 @@ func TestCreateGas(t *testing.T) {
statedb.Finalise(true)
vmctx := BlockContext{
CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true },
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {},
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) {},
BlockNumber: big.NewInt(0),
}
config := Config{}

View file

@ -936,9 +936,9 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro
}
if evm.chainRules.IsAmsterdam && !balance.IsZero() {
if this != beneficiary {
evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance))
evm.StateDB.AddLog(types.EthTransferLog(this, beneficiary, balance))
} else if newContract {
evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance))
evm.StateDB.AddLog(types.EthBurnLog(this, balance))
}
}
@ -1093,9 +1093,6 @@ func makeLog(size int) executionFunc {
Address: scope.Contract.Address(),
Topics: topics,
Data: d,
// This is a non-consensus field, but assigned here because
// core/state doesn't know the current block number.
BlockNumber: evm.Context.BlockNumber.Uint64(),
})
return nil, nil

View file

@ -40,7 +40,7 @@ var loopInterruptTests = []string{
func TestLoopInterrupt(t *testing.T) {
address := common.BytesToAddress([]byte("contract"))
vmctx := BlockContext{
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {},
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *params.Rules) {},
}
for i, tt := range loopInterruptTests {