Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, tra
context := NewEVMBlockContext(header, p.bc, nil)
evm := vm.NewEVM(context, tracingStateDB, tradingState, p.config, cfg)
signer := types.MakeSigner(p.config, blockNumber)
coinbaseOwner := getCoinbaseOwner(p.bc, statedb, header, nil)

if p.config.IsPrague(block.Number()) {
ProcessParentBlockHash(block.ParentHash(), evm)
Expand Down Expand Up @@ -146,7 +145,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, tra
}
statedb.SetTxContext(tx.Hash(), i)

receipt, gas, tokenFeeUsed, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, tx, usedGas, evm, balanceFee, coinbaseOwner)
receipt, gas, tokenFeeUsed, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, tx, usedGas, evm, balanceFee)
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
Expand Down Expand Up @@ -207,7 +206,6 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
context := NewEVMBlockContext(header, p.bc, nil)
evm := vm.NewEVM(context, tracingStateDB, tradingState, p.config, cfg)
signer := types.MakeSigner(p.config, blockNumber)
coinbaseOwner := getCoinbaseOwner(p.bc, statedb, header, nil)

if p.config.IsPrague(block.Number()) {
ProcessParentBlockHash(block.ParentHash(), evm)
Expand Down Expand Up @@ -253,7 +251,7 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
}
statedb.SetTxContext(tx.Hash(), i)

receipt, gas, tokenFeeUsed, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, tx, usedGas, evm, balanceFee, coinbaseOwner)
receipt, gas, tokenFeeUsed, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, tx, usedGas, evm, balanceFee)
if err != nil {
return nil, nil, 0, err
}
Expand All @@ -279,7 +277,7 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
// ApplyTransactionWithEVM attempts to apply a transaction to the given state database
// and uses the input parameters for its environment similar to ApplyTransaction. However,
// this method takes an already created EVM instance as input.
func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, balanceFee *big.Int, coinbaseOwner common.Address) (receipt *types.Receipt, gasUsed uint64, tokenFeeUsed bool, err error) {
func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, balanceFee *big.Int) (receipt *types.Receipt, gasUsed uint64, tokenFeeUsed bool, err error) {
if hooks := evm.Config.Tracer; hooks != nil {
if hooks.OnTxStart != nil {
hooks.OnTxStart(evm.GetVMContext(), tx, msg.From)
Expand Down Expand Up @@ -458,6 +456,7 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB,
// End Bypass denylist address

// Apply the transaction to the current state (included in the env)
coinbaseOwner := statedb.GetOwner(evm.Context.Coinbase)
result, err := ApplyMessage(evm, msg, gp, coinbaseOwner)
if err != nil {
Comment thread
gzliudan marked this conversation as resolved.
Comment thread
gzliudan marked this conversation as resolved.
return nil, 0, false, err
Expand Down Expand Up @@ -506,17 +505,6 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
return receipt
}

func getCoinbaseOwner(bc *BlockChain, statedb *state.StateDB, header *types.Header, author *common.Address) common.Address {
// If we don't have an explicit author (i.e. not mining), extract from the header
var beneficiary common.Address
if author == nil {
beneficiary, _ = bc.Engine().Author(header) // Ignore error, we're past header validation
} else {
beneficiary = *author
}
return statedb.GetOwner(beneficiary)
}

// ApplyTransaction attempts to apply a transaction to the given state database
// and uses the input parameters for its environment. It returns the receipt
// for the transaction, gas used and an error if the transaction failed,
Expand All @@ -534,8 +522,7 @@ func ApplyTransaction(tokensFee map[common.Address]*big.Int, evm *vm.EVM, gp *Ga
if err != nil {
return nil, 0, false, err
}
coinbaseOwner := statedb.GetOwner(evm.Context.Coinbase)
return ApplyTransactionWithEVM(msg, gp, statedb, header.Number, header.Hash(), tx, usedGas, evm, balanceFee, coinbaseOwner)
return ApplyTransactionWithEVM(msg, gp, statedb, header.Number, header.Hash(), tx, usedGas, evm, balanceFee)
}

func ApplySignTransaction(msg *Message, config *params.ChainConfig, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (receipt *types.Receipt, gasUsed uint64, tokenFeeUsed bool, err error) {
Expand Down
4 changes: 2 additions & 2 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func TestApplyTransactionWithEVMTracer(t *testing.T) {

// Apply transaction
var usedGas uint64
_, _, _, err = ApplyTransactionWithEVM(msg, gasPool, statedb, blockNumber, blockHash, signedTx, &usedGas, evm, big.NewInt(0), common.Address{})
_, _, _, err = ApplyTransactionWithEVM(msg, gasPool, statedb, blockNumber, blockHash, signedTx, &usedGas, evm, big.NewInt(0))
// NOTE: Some special transactions (like BlockSignersBinary or XDCXAddrBinary)
// may fail in test environment due to missing configuration or state, but
// the tracer should still be called at the beginning of ApplyTransactionWithEVM.
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestApplyTransactionWithEVMStateChangeHooks(t *testing.T) {

gasPool := new(GasPool).AddGas(1000000)
var usedGas uint64
_, _, _, err = ApplyTransactionWithEVM(msg, gasPool, statedb, big.NewInt(1), genesis.Hash(), signedTx, &usedGas, evmenv, nil, common.Address{})
_, _, _, err = ApplyTransactionWithEVM(msg, gasPool, statedb, big.NewInt(1), genesis.Hash(), signedTx, &usedGas, evmenv, nil)
if err != nil {
t.Fatalf("ApplyTransactionWithEVM failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor

// Call SetTxContext to clear out the statedb access list
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)
_, _, _, err = core.ApplyTransactionWithEVM(message, new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, evm, balance, common.Address{})
_, _, _, err = core.ApplyTransactionWithEVM(message, new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, evm, balance)
if err != nil {
return nil, fmt.Errorf("tracing failed: %w", err)
}
Expand Down
Loading