diff --git a/core/state_processor.go b/core/state_processor.go index 2ff45e4dd877..894ae0b36042 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -79,7 +79,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb state.StateDBI, cfg return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } statedb.SetTxContext(tx.Hash(), i) - receipt, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv) + receipt, err := applyTransaction(vmenv, msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas) if err != nil { return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } @@ -97,7 +97,10 @@ func (p *StateProcessor) Process(block *types.Block, statedb state.StateDBI, cfg return receipts, allLogs, *usedGas, nil } -func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, statedb state.StateDBI, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) { +func applyTransaction( + evm *vm.EVM, msg *Message, config *params.ChainConfig, gp *GasPool, statedb state.StateDBI, + blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, +) (*types.Receipt, error) { // Create a new context to be used in the EVM environment. txContext := NewEVMTxContext(msg) evm.Reset(txContext, statedb) @@ -142,7 +145,10 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta return receipt, err } -func applyTransactionWithResult(msg *Message, config *params.ChainConfig, author *common.Address, gp *GasPool, statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *ExecutionResult, error) { +func applyTransactionWithResult( + evm *vm.EVM, msg *Message, config *params.ChainConfig, gp *GasPool, statedb state.StateDBI, + blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, +) (*types.Receipt, *ExecutionResult, error) { // Create a new context to be used in the EVM environment. txContext := NewEVMTxContext(msg) evm.Reset(txContext, statedb) @@ -155,10 +161,10 @@ func applyTransactionWithResult(msg *Message, config *params.ChainConfig, author // Update the state with pending changes. var root []byte - if config.IsByzantium(header.Number) { + if config.IsByzantium(blockNumber) { statedb.Finalise(true) } else { - root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes() + root = statedb.IntermediateRoot(config.IsEIP158(blockNumber)).Bytes() } *usedGas += result.UsedGas @@ -179,10 +185,10 @@ func applyTransactionWithResult(msg *Message, config *params.ChainConfig, author } // Set the receipt logs and create the bloom filter. - receipt.Logs = statedb.GetLogs(tx.Hash(), header.Number.Uint64(), header.Hash()) + receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash) receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) - receipt.BlockHash = header.Hash() - receipt.BlockNumber = header.Number + receipt.BlockHash = blockHash + receipt.BlockNumber = blockNumber receipt.TransactionIndex = uint(statedb.TxIndex()) return receipt, result, err } @@ -191,7 +197,10 @@ func applyTransactionWithResult(msg *Message, config *params.ChainConfig, author // and uses the input parameters for its environment. It returns the receipt // for the transaction, gas used and an error if the transaction failed, // indicating the block was invalid. -func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) { +func ApplyTransaction( + config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, + statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, +) (*types.Receipt, error) { msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number), header.BaseFee) if err != nil { return nil, err @@ -199,10 +208,13 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo // Create a new context to be used in the EVM environment blockContext := NewEVMBlockContext(header, bc, author) vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg) - return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv) + return applyTransaction(vmenv, msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas) } -func ApplyTransactionWithResult(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, *ExecutionResult, error) { +func ApplyTransactionWithResult( + config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, + statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, +) (*types.Receipt, *ExecutionResult, error) { msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number), header.BaseFee) if err != nil { return nil, nil, err @@ -210,21 +222,27 @@ func ApplyTransactionWithResult(config *params.ChainConfig, bc ChainContext, aut // Create a new context to be used in the EVM environment blockContext := NewEVMBlockContext(header, bc, author) vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg) - return applyTransactionWithResult(msg, config, author, gp, statedb, header, tx, usedGas, vmenv) + return applyTransactionWithResult(vmenv, msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas) } -func ApplyTransactionWithEVM(vmenv *vm.EVM, config *params.ChainConfig, gp *GasPool, statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64) (*types.Receipt, error) { +func ApplyTransactionWithEVM( + vmenv *vm.EVM, config *params.ChainConfig, gp *GasPool, statedb state.StateDBI, + header *types.Header, tx *types.Transaction, usedGas *uint64, +) (*types.Receipt, error) { msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number), header.BaseFee) if err != nil { return nil, err } - return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv) + return applyTransaction(vmenv, msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas) } -func ApplyTransactionWithEVMWithResult(vmenv *vm.EVM, config *params.ChainConfig, author *common.Address, gp *GasPool, statedb state.StateDBI, header *types.Header, tx *types.Transaction, usedGas *uint64) (*types.Receipt, *ExecutionResult, error) { +func ApplyTransactionWithEVMWithResult( + vmenv *vm.EVM, config *params.ChainConfig, gp *GasPool, statedb state.StateDBI, + header *types.Header, tx *types.Transaction, usedGas *uint64, +) (*types.Receipt, *ExecutionResult, error) { msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number), header.BaseFee) if err != nil { return nil, nil, err } - return applyTransactionWithResult(msg, config, author, gp, statedb, header, tx, usedGas, vmenv) + return applyTransactionWithResult(vmenv, msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas) } diff --git a/ethapi/api.go b/ethapi/api.go index edc159823e1d..6aa82c8cb291 100644 --- a/ethapi/api.go +++ b/ethapi/api.go @@ -2240,7 +2240,9 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st coinbaseBalanceBeforeTx := state.GetBalance(coinbase) state.SetTxContext(tx.Hash(), i) - receipt, result, err := core.ApplyTransactionWithEVMWithResult(vmenv, s.b.ChainConfig(), &coinbase, gp, state, header, tx, &header.GasUsed) + receipt, result, err := core.ApplyTransactionWithEVMWithResult( + vmenv, s.b.ChainConfig(), gp, state, header, tx, &header.GasUsed, + ) if err != nil { return nil, fmt.Errorf("err: %w; txhash %s", err, tx.Hash()) }