From 5e54fe0cd68a347f840f032c70f558594a0925ee Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Fri, 21 Feb 2025 09:44:44 +0100 Subject: [PATCH] Move msg.SetIsFree to core.ApplyMessage (#13880) See Issue #9259 --- accounts/abi/bind/backends/simulated.go | 1 + cmd/state/exec3/historical_trace_worker.go | 9 +---- cmd/state/exec3/state.go | 9 +---- cmd/state/exec3/trace_worker.go | 9 +---- core/blockchain.go | 18 ++++++--- core/state/txtask.go | 11 +++--- core/state_processor.go | 10 +---- core/state_transition.go | 17 ++++++++- core/types/access_list_tx.go | 6 +-- core/types/blob_tx.go | 8 ++-- core/types/blob_tx_wrapper.go | 2 +- core/types/dynamic_fee_tx.go | 8 ++-- core/types/legacy_tx.go | 4 +- core/types/set_code_tx.go | 10 ++--- core/types/transaction.go | 38 +++++++++---------- .../internal/tracetest/calltrace_test.go | 2 +- polygon/bridge/reader.go | 6 +-- polygon/tracer/trace_bor_state_sync_txn.go | 2 +- tests/state_test_util.go | 5 +-- turbo/adapter/ethapi/api.go | 16 ++++---- turbo/jsonrpc/eth_block.go | 2 +- turbo/jsonrpc/eth_call.go | 8 ++-- turbo/jsonrpc/eth_callMany.go | 4 +- turbo/jsonrpc/otterscan_api.go | 2 +- turbo/jsonrpc/otterscan_search_trace.go | 2 +- turbo/jsonrpc/overlay_api.go | 6 +-- .../receipts/bor_receipts_generator.go | 4 +- turbo/jsonrpc/trace_adhoc.go | 28 +++++++------- turbo/jsonrpc/trace_filtering.go | 24 ++---------- turbo/jsonrpc/tracing.go | 15 ++------ turbo/transactions/call.go | 7 ++-- turbo/transactions/tracing.go | 14 ++----- 32 files changed, 134 insertions(+), 173 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 24b9048ecda..e8bb54a6cd5 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -856,6 +856,7 @@ func (m callMsg) Data() []byte { return m.CallMsg.Data func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList } func (m callMsg) Authorizations() []types.Authorization { return m.CallMsg.Authorizations } func (m callMsg) IsFree() bool { return false } +func (m callMsg) SetIsFree(_ bool) {} func (m callMsg) BlobGas() uint64 { return misc.GetBlobGasUsed(len(m.CallMsg.BlobHashes)) } func (m callMsg) MaxFeePerBlobGas() *uint256.Int { return m.CallMsg.MaxFeePerBlobGas } diff --git a/cmd/state/exec3/historical_trace_worker.go b/cmd/state/exec3/historical_trace_worker.go index 146807802b9..6be9a294eac 100644 --- a/cmd/state/exec3/historical_trace_worker.go +++ b/cmd/state/exec3/historical_trace_worker.go @@ -194,13 +194,6 @@ func (rw *HistoricalTraceWorker) RunTxTask(txTask *state.TxTask) { ibs.SetTxContext(txTask.TxIndex) msg := txTask.TxAsMessage msg.SetCheckNonce(!rw.vmConfig.StatelessExec) - if msg.FeeCap().IsZero() { - // Only zero-gas transactions may be service ones - syscall := func(contract common.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, rw.execArgs.ChainConfig, ibs, header, rw.execArgs.Engine, true /* constCall */) - } - msg.SetIsFree(rw.execArgs.Engine.IsServiceTransaction(msg.From(), syscall)) - } txContext := core.NewEVMTxContext(msg) if rw.vmConfig.TraceJumpDest { @@ -209,7 +202,7 @@ func (rw *HistoricalTraceWorker) RunTxTask(txTask *state.TxTask) { rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, txContext, ibs, *rw.vmConfig, rules) // MA applytx - applyRes, err := core.ApplyMessage(rw.evm, msg, rw.taskGasPool, true /* refunds */, false /* gasBailout */) + applyRes, err := core.ApplyMessage(rw.evm, msg, rw.taskGasPool, true /* refunds */, false /* gasBailout */, rw.execArgs.Engine) if err != nil { txTask.Error = err } else { diff --git a/cmd/state/exec3/state.go b/cmd/state/exec3/state.go index 852897ffa41..cbbe56f383a 100644 --- a/cmd/state/exec3/state.go +++ b/cmd/state/exec3/state.go @@ -268,18 +268,11 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining bool) { rw.vmCfg.SkipAnalysis = txTask.SkipAnalysis ibs.SetTxContext(txTask.TxIndex) msg := txTask.TxAsMessage - if msg.FeeCap().IsZero() && rw.engine != nil { - // Only zero-gas transactions may be service ones - syscall := func(contract libcommon.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, rw.chainConfig, ibs, header, rw.engine, true /* constCall */) - } - msg.SetIsFree(rw.engine.IsServiceTransaction(msg.From(), syscall)) - } rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, rw.vmCfg, rules) // MA applytx - applyRes, err := core.ApplyMessage(rw.evm, msg, rw.taskGasPool, true /* refunds */, false /* gasBailout */) + applyRes, err := core.ApplyMessage(rw.evm, msg, rw.taskGasPool, true /* refunds */, false /* gasBailout */, rw.engine) if err != nil { txTask.Error = err } else { diff --git a/cmd/state/exec3/trace_worker.go b/cmd/state/exec3/trace_worker.go index 7b80c49992b..7a03ccd3097 100644 --- a/cmd/state/exec3/trace_worker.go +++ b/cmd/state/exec3/trace_worker.go @@ -114,13 +114,6 @@ func (e *TraceWorker) ExecTxn(txNum uint64, txIndex int, txn types.Transaction, return nil, err } msg.SetCheckNonce(!e.vmConfig.StatelessExec) - if msg.FeeCap().IsZero() { - // Only zero-gas transactions may be service ones - syscall := func(contract common.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, e.chainConfig, e.ibs, e.header, e.engine, true /* constCall */) - } - msg.SetIsFree(e.engine.IsServiceTransaction(msg.From(), syscall)) - } txContext := core.NewEVMTxContext(msg) if e.vmConfig.TraceJumpDest { @@ -129,7 +122,7 @@ func (e *TraceWorker) ExecTxn(txNum uint64, txIndex int, txn types.Transaction, e.evm.ResetBetweenBlocks(*e.blockCtx, txContext, e.ibs, *e.vmConfig, e.rules) gp := new(core.GasPool).AddGas(txn.GetGas()).AddBlobGas(txn.GetBlobGas()) - res, err := core.ApplyMessage(e.evm, msg, gp, true /* refunds */, gasBailout /* gasBailout */) + res, err := core.ApplyMessage(e.evm, msg, gp, true /* refunds */, gasBailout /* gasBailout */, e.engine) if err != nil { return nil, fmt.Errorf("%w: blockNum=%d, txNum=%d, %s", err, e.blockNum, txNum, e.ibs.Error()) } diff --git a/core/blockchain.go b/core/blockchain.go index 44fe8e0ac5a..f51d451f256 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -250,7 +250,19 @@ func rlpHash(x interface{}) (h libcommon.Hash) { return h } -func SysCallContract(contract libcommon.Address, data []byte, chainConfig *chain.Config, ibs *state.IntraBlockState, header *types.Header, engine consensus.EngineReader, constCall bool) (result []byte, err error) { +func SysCallContract(contract libcommon.Address, data []byte, chainConfig *chain.Config, ibs evmtypes.IntraBlockState, header *types.Header, engine consensus.EngineReader, constCall bool) (result []byte, err error) { + isBor := chainConfig.Bor != nil + var author *libcommon.Address + if isBor { + author = &header.Coinbase + } else { + author = &state.SystemAddress + } + blockContext := NewEVMBlockContext(header, GetHashFn(header, nil), engine, author, chainConfig) + return SysCallContractWithBlockContext(contract, data, chainConfig, ibs, blockContext, engine, constCall) +} + +func SysCallContractWithBlockContext(contract libcommon.Address, data []byte, chainConfig *chain.Config, ibs evmtypes.IntraBlockState, blockContext evmtypes.BlockContext, engine consensus.EngineReader, constCall bool) (result []byte, err error) { msg := types.NewMessage( state.SystemAddress, &contract, @@ -266,15 +278,11 @@ func SysCallContract(contract libcommon.Address, data []byte, chainConfig *chain // Create a new context to be used in the EVM environment isBor := chainConfig.Bor != nil var txContext evmtypes.TxContext - var author *libcommon.Address if isBor { - author = &header.Coinbase txContext = evmtypes.TxContext{} } else { - author = &state.SystemAddress txContext = NewEVMTxContext(msg) } - blockContext := NewEVMBlockContext(header, GetHashFn(header, nil), engine, author, chainConfig) evm := vm.NewEVM(blockContext, txContext, ibs, chainConfig, vmConfig) ret, _, err := evm.Call( diff --git a/core/state/txtask.go b/core/state/txtask.go index af38e935e2a..af30192240d 100644 --- a/core/state/txtask.go +++ b/core/state/txtask.go @@ -23,17 +23,16 @@ import ( "sync" "time" - "github.com/erigontech/erigon-lib/common/dbg" - "github.com/erigontech/erigon-lib/log/v3" - - "github.com/erigontech/erigon-lib/kv" - "github.com/erigontech/erigon/core/rawdb/rawtemporaldb" "github.com/holiman/uint256" "github.com/erigontech/erigon-lib/chain" libcommon "github.com/erigontech/erigon-lib/common" + "github.com/erigontech/erigon-lib/common/dbg" + "github.com/erigontech/erigon-lib/kv" + "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon-lib/state" "github.com/erigontech/erigon-lib/types/accounts" + "github.com/erigontech/erigon/core/rawdb/rawtemporaldb" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/core/vm/evmtypes" ) @@ -58,7 +57,7 @@ type TxTask struct { Failed bool Tx types.Transaction GetHashFn func(n uint64) libcommon.Hash - TxAsMessage types.Message + TxAsMessage *types.Message EvmBlockContext evmtypes.BlockContext HistoryExecution bool // use history reader for that txn instead of state reader diff --git a/core/state_processor.go b/core/state_processor.go index 43cebae1845..a18dd25c9de 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -45,14 +45,6 @@ func applyTransaction(config *chain.Config, engine consensus.EngineReader, gp *G } msg.SetCheckNonce(!cfg.StatelessExec) - if msg.FeeCap().IsZero() && engine != nil { - // Only zero-gas transactions may be service ones - syscall := func(contract libcommon.Address, data []byte) ([]byte, error) { - return SysCallContract(contract, data, config, ibs, header, engine, true /* constCall */) - } - msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall)) - } - txContext := NewEVMTxContext(msg) if cfg.TraceJumpDest { txContext.TxHash = txn.Hash() @@ -60,7 +52,7 @@ func applyTransaction(config *chain.Config, engine consensus.EngineReader, gp *G // Update the evm with the new transaction context. evm.Reset(txContext, ibs) - result, err := ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + result, err := ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, engine) if err != nil { return nil, nil, err } diff --git a/core/state_transition.go b/core/state_transition.go index c241ec96d83..5d3925a58d5 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -33,6 +33,8 @@ import ( "github.com/erigontech/erigon-lib/common/u256" "github.com/erigontech/erigon-lib/crypto" "github.com/erigontech/erigon-lib/log/v3" + "github.com/erigontech/erigon/consensus" + "github.com/erigontech/erigon/core/state" "github.com/erigontech/erigon/core/tracing" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/core/vm" @@ -102,7 +104,8 @@ type Message interface { BlobHashes() []libcommon.Hash Authorizations() []types.Authorization - IsFree() bool + IsFree() bool // service transactions on Gnosis are exempt from EIP-1559 mandatory fees + SetIsFree(bool) } // NewStateTransition initialises and returns a new state transition object. @@ -133,7 +136,17 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition // `refunds` is false when it is not required to apply gas refunds // `gasBailout` is true when it is not required to fail transaction if the balance is not enough to pay gas. // for trace_call to replicate OE/Parity behaviour -func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, refunds bool, gasBailout bool) (*evmtypes.ExecutionResult, error) { +func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, refunds bool, gasBailout bool, engine consensus.EngineReader) ( + *evmtypes.ExecutionResult, error) { + // Only zero-gas transactions may be service ones + if msg.FeeCap().IsZero() && !msg.IsFree() && engine != nil { + blockContext := evm.Context + blockContext.Coinbase = state.SystemAddress + syscall := func(contract libcommon.Address, data []byte) ([]byte, error) { + return SysCallContractWithBlockContext(contract, data, evm.ChainConfig(), evm.IntraBlockState(), blockContext, engine, true /* constCall */) + } + msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall)) + } return NewStateTransition(evm, msg, gp).TransitionDb(refunds, gasBailout) } diff --git a/core/types/access_list_tx.go b/core/types/access_list_tx.go index d4484f33388..34b51485964 100644 --- a/core/types/access_list_tx.go +++ b/core/types/access_list_tx.go @@ -411,7 +411,7 @@ func (tx *AccessListTx) DecodeRLP(s *rlp.Stream) error { } // AsMessage returns the transaction as a core.Message. -func (tx *AccessListTx) AsMessage(s Signer, _ *big.Int, rules *chain.Rules) (Message, error) { +func (tx *AccessListTx) AsMessage(s Signer, _ *big.Int, rules *chain.Rules) (*Message, error) { msg := Message{ nonce: tx.Nonce, gasLimit: tx.Gas, @@ -426,12 +426,12 @@ func (tx *AccessListTx) AsMessage(s Signer, _ *big.Int, rules *chain.Rules) (Mes } if !rules.IsBerlin { - return msg, errors.New("eip-2930 transactions require Berlin") + return nil, errors.New("eip-2930 transactions require Berlin") } var err error msg.from, err = tx.Sender(s) - return msg, err + return &msg, err } func (tx *AccessListTx) WithSignature(signer Signer, sig []byte) (Transaction, error) { diff --git a/core/types/blob_tx.go b/core/types/blob_tx.go index 08a6db83af6..1d662c5e846 100644 --- a/core/types/blob_tx.go +++ b/core/types/blob_tx.go @@ -62,7 +62,7 @@ func (stx *BlobTx) GetBlobGas() uint64 { return fixedgas.BlobGasPerBlob * uint64(len(stx.BlobVersionedHashes)) } -func (stx *BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) { +func (stx *BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (*Message, error) { msg := Message{ nonce: stx.Nonce, gasLimit: stx.Gas, @@ -76,12 +76,12 @@ func (stx *BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Me checkNonce: true, } if !rules.IsCancun { - return msg, errors.New("BlobTx transactions require Cancun") + return nil, errors.New("BlobTx transactions require Cancun") } if baseFee != nil { overflow := msg.gasPrice.SetFromBig(baseFee) if overflow { - return msg, errors.New("gasPrice higher than 2^256-1") + return nil, errors.New("gasPrice higher than 2^256-1") } } msg.gasPrice.Add(&msg.gasPrice, stx.Tip) @@ -92,7 +92,7 @@ func (stx *BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Me msg.from, err = stx.Sender(s) msg.maxFeePerBlobGas = *stx.MaxFeePerBlobGas msg.blobHashes = stx.BlobVersionedHashes - return msg, err + return &msg, err } func (stx *BlobTx) cachedSender() (sender libcommon.Address, ok bool) { diff --git a/core/types/blob_tx_wrapper.go b/core/types/blob_tx_wrapper.go index 41be050d167..e444fcfc413 100644 --- a/core/types/blob_tx_wrapper.go +++ b/core/types/blob_tx_wrapper.go @@ -312,7 +312,7 @@ func (txw *BlobTxWrapper) GetBlobGas() uint64 { return txw.Tx.GetBlobGas( func (txw *BlobTxWrapper) GetValue() *uint256.Int { return txw.Tx.GetValue() } func (txw *BlobTxWrapper) GetTo() *libcommon.Address { return txw.Tx.GetTo() } -func (txw *BlobTxWrapper) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) { +func (txw *BlobTxWrapper) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (*Message, error) { return txw.Tx.AsMessage(s, baseFee, rules) } func (txw *BlobTxWrapper) WithSignature(signer Signer, sig []byte) (Transaction, error) { diff --git a/core/types/dynamic_fee_tx.go b/core/types/dynamic_fee_tx.go index a165b0109c5..bda76e3a5a6 100644 --- a/core/types/dynamic_fee_tx.go +++ b/core/types/dynamic_fee_tx.go @@ -329,7 +329,7 @@ func (tx *DynamicFeeTransaction) DecodeRLP(s *rlp.Stream) error { } // AsMessage returns the transaction as a core.Message. -func (tx *DynamicFeeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) { +func (tx *DynamicFeeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (*Message, error) { msg := Message{ nonce: tx.Nonce, gasLimit: tx.Gas, @@ -343,12 +343,12 @@ func (tx *DynamicFeeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *ch checkNonce: true, } if !rules.IsLondon { - return msg, errors.New("eip-1559 transactions require London") + return nil, errors.New("eip-1559 transactions require London") } if baseFee != nil { overflow := msg.gasPrice.SetFromBig(baseFee) if overflow { - return msg, errors.New("gasPrice higher than 2^256-1") + return nil, errors.New("gasPrice higher than 2^256-1") } } msg.gasPrice.Add(&msg.gasPrice, tx.Tip) @@ -358,7 +358,7 @@ func (tx *DynamicFeeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *ch var err error msg.from, err = tx.Sender(s) - return msg, err + return &msg, err } // Hash computes the hash (but not for signatures!) diff --git a/core/types/legacy_tx.go b/core/types/legacy_tx.go index fb57987566f..62781f534f7 100644 --- a/core/types/legacy_tx.go +++ b/core/types/legacy_tx.go @@ -343,7 +343,7 @@ func (tx *LegacyTx) DecodeRLP(s *rlp.Stream) error { } // AsMessage returns the transaction as a core.Message. -func (tx *LegacyTx) AsMessage(s Signer, _ *big.Int, _ *chain.Rules) (Message, error) { +func (tx *LegacyTx) AsMessage(s Signer, _ *big.Int, _ *chain.Rules) (*Message, error) { msg := Message{ nonce: tx.Nonce, gasLimit: tx.Gas, @@ -359,7 +359,7 @@ func (tx *LegacyTx) AsMessage(s Signer, _ *big.Int, _ *chain.Rules) (Message, er var err error msg.from, err = tx.Sender(s) - return msg, err + return &msg, err } func (tx *LegacyTx) WithSignature(signer Signer, sig []byte) (Transaction, error) { diff --git a/core/types/set_code_tx.go b/core/types/set_code_tx.go index 85edb0a53bb..adc004003be 100644 --- a/core/types/set_code_tx.go +++ b/core/types/set_code_tx.go @@ -114,7 +114,7 @@ func (tx *SetCodeTransaction) MarshalBinary(w io.Writer) error { return nil } -func (tx *SetCodeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) { +func (tx *SetCodeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (*Message, error) { msg := Message{ nonce: tx.Nonce, gasLimit: tx.Gas, @@ -128,12 +128,12 @@ func (tx *SetCodeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain checkNonce: true, } if !rules.IsPrague { - return msg, errors.New("SetCodeTransaction is only supported in Prague") + return nil, errors.New("SetCodeTransaction is only supported in Prague") } if baseFee != nil { overflow := msg.gasPrice.SetFromBig(baseFee) if overflow { - return msg, errors.New("gasPrice higher than 2^256-1") + return nil, errors.New("gasPrice higher than 2^256-1") } } msg.gasPrice.Add(&msg.gasPrice, tx.Tip) @@ -142,13 +142,13 @@ func (tx *SetCodeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain } if len(tx.Authorizations) == 0 { - return msg, errors.New("SetCodeTransaction without authorizations is invalid") + return nil, errors.New("SetCodeTransaction without authorizations is invalid") } msg.authorizations = tx.Authorizations var err error msg.from, err = tx.Sender(s) - return msg, err + return &msg, err } func (tx *SetCodeTransaction) Sender(signer Signer) (libcommon.Address, error) { diff --git a/core/types/transaction.go b/core/types/transaction.go index caf686184ee..9356b1e9964 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -69,7 +69,7 @@ type Transaction interface { GetBlobGas() uint64 GetValue() *uint256.Int GetTo() *libcommon.Address - AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) + AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (*Message, error) WithSignature(signer Signer, sig []byte) (Transaction, error) Hash() libcommon.Hash SigningHash(chainID *big.Int) libcommon.Hash @@ -376,7 +376,7 @@ type Message struct { func NewMessage(from libcommon.Address, to *libcommon.Address, nonce uint64, amount *uint256.Int, gasLimit uint64, gasPrice *uint256.Int, feeCap, tip *uint256.Int, data []byte, accessList AccessList, checkNonce bool, isFree bool, maxFeePerBlobGas *uint256.Int, -) Message { +) *Message { m := Message{ from: from, to: to, @@ -400,28 +400,28 @@ func NewMessage(from libcommon.Address, to *libcommon.Address, nonce uint64, amo if maxFeePerBlobGas != nil { m.maxFeePerBlobGas.Set(maxFeePerBlobGas) } - return m + return &m } -func (m Message) From() libcommon.Address { return m.from } -func (m Message) To() *libcommon.Address { return m.to } -func (m Message) GasPrice() *uint256.Int { return &m.gasPrice } -func (m Message) FeeCap() *uint256.Int { return &m.feeCap } -func (m Message) Tip() *uint256.Int { return &m.tip } -func (m Message) Value() *uint256.Int { return &m.amount } -func (m Message) Gas() uint64 { return m.gasLimit } -func (m Message) Nonce() uint64 { return m.nonce } -func (m Message) Data() []byte { return m.data } -func (m Message) AccessList() AccessList { return m.accessList } -func (m Message) Authorizations() []Authorization { return m.authorizations } +func (m *Message) From() libcommon.Address { return m.from } +func (m *Message) To() *libcommon.Address { return m.to } +func (m *Message) GasPrice() *uint256.Int { return &m.gasPrice } +func (m *Message) FeeCap() *uint256.Int { return &m.feeCap } +func (m *Message) Tip() *uint256.Int { return &m.tip } +func (m *Message) Value() *uint256.Int { return &m.amount } +func (m *Message) Gas() uint64 { return m.gasLimit } +func (m *Message) Nonce() uint64 { return m.nonce } +func (m *Message) Data() []byte { return m.data } +func (m *Message) AccessList() AccessList { return m.accessList } +func (m *Message) Authorizations() []Authorization { return m.authorizations } func (m *Message) SetAuthorizations(authorizations []Authorization) { m.authorizations = authorizations } -func (m Message) CheckNonce() bool { return m.checkNonce } +func (m *Message) CheckNonce() bool { return m.checkNonce } func (m *Message) SetCheckNonce(checkNonce bool) { m.checkNonce = checkNonce } -func (m Message) IsFree() bool { return m.isFree } +func (m *Message) IsFree() bool { return m.isFree } func (m *Message) SetIsFree(isFree bool) { m.isFree = isFree } @@ -442,13 +442,13 @@ func (m *Message) ChangeGas(globalGasCap, desiredGas uint64) { m.gasLimit = gas } -func (m Message) BlobGas() uint64 { return fixedgas.BlobGasPerBlob * uint64(len(m.blobHashes)) } +func (m *Message) BlobGas() uint64 { return fixedgas.BlobGasPerBlob * uint64(len(m.blobHashes)) } -func (m Message) MaxFeePerBlobGas() *uint256.Int { +func (m *Message) MaxFeePerBlobGas() *uint256.Int { return &m.maxFeePerBlobGas } -func (m Message) BlobHashes() []libcommon.Hash { return m.blobHashes } +func (m *Message) BlobHashes() []libcommon.Hash { return m.blobHashes } func DecodeSSZ(data []byte, dest codec.Deserializable) error { err := dest.Deserialize(codec.NewDecodingReader(bytes.NewReader(data), uint64(len(data)))) diff --git a/eth/tracers/internal/tracetest/calltrace_test.go b/eth/tracers/internal/tracetest/calltrace_test.go index 087d0ad2312..19404e70d39 100644 --- a/eth/tracers/internal/tracetest/calltrace_test.go +++ b/eth/tracers/internal/tracetest/calltrace_test.go @@ -165,7 +165,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) { } txContext := core.NewEVMTxContext(msg) evm := vm.NewEVM(context, txContext, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer}) - vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddBlobGas(tx.GetBlobGas()), true /* refunds */, false /* gasBailout */) + vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddBlobGas(tx.GetBlobGas()), true /* refunds */, false /* gasBailout */, nil /* engine */) if err != nil { t.Fatalf("failed to execute transaction: %v", err) } diff --git a/polygon/bridge/reader.go b/polygon/bridge/reader.go index 87e07a9ca6a..b6de1268e2d 100644 --- a/polygon/bridge/reader.go +++ b/polygon/bridge/reader.go @@ -105,7 +105,7 @@ func (r *Reader) Events(ctx context.Context, blockNum uint64) ([]*types.Message, nil, ) - eventsRaw = append(eventsRaw, &msg) + eventsRaw = append(eventsRaw, msg) } return eventsRaw, nil @@ -196,7 +196,7 @@ func messageFromData(to libcommon.Address, data []byte) *types.Message { nil, ) - return &msg + return msg } // NewStateSyncEventMessages creates a corresponding message that can be passed to EVM for multiple state sync events @@ -219,7 +219,7 @@ func NewStateSyncEventMessages(stateSyncEvents []rlp.RawValue, stateReceiverCont nil, // maxFeePerBlobGas ) - msgs[i] = &msg + msgs[i] = msg } return msgs diff --git a/polygon/tracer/trace_bor_state_sync_txn.go b/polygon/tracer/trace_bor_state_sync_txn.go index a032b28153c..cafab3f2ad1 100644 --- a/polygon/tracer/trace_bor_state_sync_txn.go +++ b/polygon/tracer/trace_bor_state_sync_txn.go @@ -117,7 +117,7 @@ func traceBorStateSyncTxn( } gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) - _, err := core.ApplyMessage(evm, msg, gp, refunds, false /* gasBailout */) + _, err := core.ApplyMessage(evm, msg, gp, refunds, false /* gasBailout */, nil /* engine */) if err != nil { return nil, err } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 1727cd7bc6b..292f4d16440 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -41,10 +41,9 @@ import ( "github.com/erigontech/erigon-lib/crypto" "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon-lib/log/v3" + "github.com/erigontech/erigon-lib/rlp" state2 "github.com/erigontech/erigon-lib/state" "github.com/erigontech/erigon-lib/wrap" - - "github.com/erigontech/erigon-lib/rlp" "github.com/erigontech/erigon/consensus/misc" "github.com/erigontech/erigon/core" "github.com/erigontech/erigon/core/state" @@ -270,7 +269,7 @@ func (t *StateTest) RunNoVerify(tx kv.RwTx, subtest StateSubtest, vmconfig vm.Co snapshot := statedb.Snapshot() gaspool := new(core.GasPool) gaspool.AddGas(block.GasLimit()).AddBlobGas(config.GetMaxBlobGasPerBlock(header.Time)) - if _, err = core.ApplyMessage(evm, msg, gaspool, true /* refunds */, false /* gasBailout */); err != nil { + if _, err = core.ApplyMessage(evm, msg, gaspool, true /* refunds */, false /* gasBailout */, nil /* engine */); err != nil { statedb.RevertToSnapshot(snapshot) } diff --git a/turbo/adapter/ethapi/api.go b/turbo/adapter/ethapi/api.go index fb4360d11a7..243c3631f8d 100644 --- a/turbo/adapter/ethapi/api.go +++ b/turbo/adapter/ethapi/api.go @@ -63,10 +63,10 @@ func (arg *CallArgs) from() libcommon.Address { } // ToMessage converts CallArgs to the Message type used by the core evm -func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (types.Message, error) { +func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (*types.Message, error) { // Reject invalid combinations of pre- and post-1559 fee styles if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) { - return types.Message{}, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") + return nil, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") } // Set sender address or use zero address if none specified. addr := args.from() @@ -96,7 +96,7 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type if args.GasPrice != nil { overflow := gasPrice.SetFromBig(args.GasPrice.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } } gasFeeCap, gasTipCap = gasPrice, gasPrice @@ -107,7 +107,7 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type gasPrice = new(uint256.Int) overflow := gasPrice.SetFromBig(args.GasPrice.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } gasFeeCap, gasTipCap = gasPrice, gasPrice } else { @@ -116,14 +116,14 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type if args.MaxFeePerGas != nil { overflow := gasFeeCap.SetFromBig(args.MaxFeePerGas.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } } gasTipCap = new(uint256.Int) if args.MaxPriorityFeePerGas != nil { overflow := gasTipCap.SetFromBig(args.MaxPriorityFeePerGas.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } } // Backfill the legacy gasPrice for EVM execution, unless we're all zeroes @@ -135,7 +135,7 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type if args.MaxFeePerBlobGas != nil { blobFee, overflow := uint256.FromBig(args.MaxFeePerBlobGas.ToInt()) if overflow { - return types.Message{}, errors.New("args.MaxFeePerBlobGas higher than 2^256-1") + return nil, errors.New("args.MaxFeePerBlobGas higher than 2^256-1") } maxFeePerBlobGas = blobFee } @@ -145,7 +145,7 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type if args.Value != nil { overflow := value.SetFromBig(args.Value.ToInt()) if overflow { - return types.Message{}, errors.New("args.Value higher than 2^256-1") + return nil, errors.New("args.Value higher than 2^256-1") } } var data []byte diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index 02af78f9e11..bb8d0ed0fa4 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -180,7 +180,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat return nil, err } // Execute the transaction message - result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, engine) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_call.go b/turbo/jsonrpc/eth_call.go index d0f982c526b..7aed0ebab2f 100644 --- a/turbo/jsonrpc/eth_call.go +++ b/turbo/jsonrpc/eth_call.go @@ -280,7 +280,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs // Create a helper to check if a gas allowance results in an executable transaction executable := func(gas uint64) (bool, *evmtypes.ExecutionResult, error) { - result, err := caller.DoCallWithNewGas(ctx, gas) + result, err := caller.DoCallWithNewGas(ctx, gas, engine) if err != nil { if errors.Is(err, core.ErrIntrinsicGas) { // Special case, raise gas limit @@ -838,15 +838,13 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs, // Set the accesslist to the last al args.AccessList = &accessList - var msg types.Message - var baseFee *uint256.Int = nil // check if EIP-1559 if header.BaseFee != nil { baseFee, _ = uint256.FromBig(header.BaseFee) } - msg, err = args.ToMessage(api.GasCap, baseFee) + msg, err := args.ToMessage(api.GasCap, baseFee) if err != nil { return nil, err } @@ -859,7 +857,7 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs, evm := vm.NewEVM(blockCtx, txCtx, state, chainConfig, config) gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) - res, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + res, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, engine) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_callMany.go b/turbo/jsonrpc/eth_callMany.go index c1725860bd2..091414eb7f7 100644 --- a/turbo/jsonrpc/eth_callMany.go +++ b/turbo/jsonrpc/eth_callMany.go @@ -217,7 +217,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont txCtx = core.NewEVMTxContext(msg) evm = vm.NewEVM(blockCtx, txCtx, evm.IntraBlockState(), chainConfig, vm.Config{Debug: false}) // Execute the transaction message - _, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + _, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, api.engine()) if err != nil { return nil, err } @@ -277,7 +277,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont } txCtx = core.NewEVMTxContext(msg) evm = vm.NewEVM(blockCtx, txCtx, evm.IntraBlockState(), chainConfig, vm.Config{Debug: false}) - result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, api.engine()) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/otterscan_api.go b/turbo/jsonrpc/otterscan_api.go index b2a9af1cbeb..55627045443 100644 --- a/turbo/jsonrpc/otterscan_api.go +++ b/turbo/jsonrpc/otterscan_api.go @@ -163,7 +163,7 @@ func (api *OtterscanAPIImpl) runTracer(ctx context.Context, tx kv.TemporalTx, ha } vmenv := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vmConfig) - result, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()), true, false /* gasBailout */) + result, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()), true, false /* gasBailout */, engine) if err != nil { return nil, fmt.Errorf("tracing failed: %v", err) } diff --git a/turbo/jsonrpc/otterscan_search_trace.go b/turbo/jsonrpc/otterscan_search_trace.go index 2e2ca3909db..f96bd74f700 100644 --- a/turbo/jsonrpc/otterscan_search_trace.go +++ b/turbo/jsonrpc/otterscan_search_trace.go @@ -121,7 +121,7 @@ func (api *OtterscanAPIImpl) traceBlock(dbtx kv.TemporalTx, ctx context.Context, TxContext := core.NewEVMTxContext(msg) vmenv := vm.NewEVM(BlockContext, TxContext, ibs, chainConfig, vm.Config{Debug: true, Tracer: tracer}) - if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(txn.GetGas()).AddBlobGas(txn.GetBlobGas()), true /* refunds */, false /* gasBailout */); err != nil { + if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(txn.GetGas()).AddBlobGas(txn.GetBlobGas()), true /* refunds */, false /* gasBailout */, engine); err != nil { return false, nil, err } _ = ibs.FinalizeTx(rules, cachedWriter) diff --git a/turbo/jsonrpc/overlay_api.go b/turbo/jsonrpc/overlay_api.go index 4396c13d754..45fbdaf86bd 100644 --- a/turbo/jsonrpc/overlay_api.go +++ b/turbo/jsonrpc/overlay_api.go @@ -193,7 +193,7 @@ func (api *OverlayAPIImpl) CallConstructor(ctx context.Context, address common.A txCtx = core.NewEVMTxContext(msg) evm = vm.NewEVM(blockCtx, txCtx, evm.IntraBlockState(), chainConfig, vm.Config{Debug: false}) // Execute the transaction message - _, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + _, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, api.engine()) if err != nil { return nil, err } @@ -222,7 +222,7 @@ func (api *OverlayAPIImpl) CallConstructor(ctx context.Context, address common.A evm = vm.NewEVM(blockCtx, txCtx, evm.IntraBlockState(), chainConfig, vm.Config{Debug: true, Tracer: &ct}) // Execute the transaction message - _, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */) + _, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */, api.engine()) if ct.err != nil { return nil, err } @@ -528,7 +528,7 @@ func (api *OverlayAPIImpl) replayBlock(ctx context.Context, blockNum uint64, sta evm.TxContext = txCtx // Execute the transaction message - res, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */) + res, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */, api.engine()) if err != nil { log.Error(err.Error()) return nil, err diff --git a/turbo/jsonrpc/receipts/bor_receipts_generator.go b/turbo/jsonrpc/receipts/bor_receipts_generator.go index 0a0ba66a458..26a7a83be66 100644 --- a/turbo/jsonrpc/receipts/bor_receipts_generator.go +++ b/turbo/jsonrpc/receipts/bor_receipts_generator.go @@ -2,7 +2,6 @@ package receipts import ( "context" - "github.com/erigontech/erigon/core/rawdb/rawtemporaldb" lru "github.com/hashicorp/golang-lru/v2" @@ -12,6 +11,7 @@ import ( "github.com/erigontech/erigon-lib/kv/rawdbv3" "github.com/erigontech/erigon/consensus" "github.com/erigontech/erigon/core" + "github.com/erigontech/erigon/core/rawdb/rawtemporaldb" "github.com/erigontech/erigon/core/state" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/core/vm" @@ -82,7 +82,7 @@ func applyBorTransaction(msgs []*types.Message, evm *vm.EVM, gp *core.GasPool, i txContext := core.NewEVMTxContext(msg) evm.Reset(txContext, ibs) - _, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + _, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, nil /* engine */) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/trace_adhoc.go b/turbo/jsonrpc/trace_adhoc.go index 6608df25f79..4368d7c778d 100644 --- a/turbo/jsonrpc/trace_adhoc.go +++ b/turbo/jsonrpc/trace_adhoc.go @@ -22,8 +22,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/erigontech/erigon-lib/kv/rawdbv3" - "github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" "math" "strings" @@ -33,6 +31,7 @@ import ( "github.com/erigontech/erigon-lib/common/hexutil" math2 "github.com/erigontech/erigon-lib/common/math" "github.com/erigontech/erigon-lib/kv" + "github.com/erigontech/erigon-lib/kv/rawdbv3" "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon-lib/types/accounts" "github.com/erigontech/erigon/core" @@ -45,6 +44,7 @@ import ( "github.com/erigontech/erigon/rpc" "github.com/erigontech/erigon/turbo/rpchelper" "github.com/erigontech/erigon/turbo/shards" + "github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" "github.com/erigontech/erigon/turbo/transactions" ) @@ -149,7 +149,7 @@ type VmTraceStore struct { } // ToMessage converts CallArgs to the Message type used by the core evm -func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (types.Message, error) { +func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (*types.Message, error) { // Set sender address or use zero address if none specified. var addr libcommon.Address if args.From != nil { @@ -180,7 +180,7 @@ func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int) if args.GasPrice != nil { overflow := gasPrice.SetFromBig(args.GasPrice.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } } gasFeeCap, gasTipCap = gasPrice, gasPrice @@ -191,7 +191,7 @@ func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int) // User specified the legacy gas field, convert to 1559 gas typing gasPrice, overflow = uint256.FromBig(args.GasPrice.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } gasFeeCap, gasTipCap = gasPrice, gasPrice } else { @@ -200,14 +200,14 @@ func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int) if args.MaxFeePerGas != nil { overflow := gasFeeCap.SetFromBig(args.MaxFeePerGas.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } } gasTipCap = new(uint256.Int) if args.MaxPriorityFeePerGas != nil { overflow := gasTipCap.SetFromBig(args.MaxPriorityFeePerGas.ToInt()) if overflow { - return types.Message{}, errors.New("args.GasPrice higher than 2^256-1") + return nil, errors.New("args.GasPrice higher than 2^256-1") } } // Backfill the legacy gasPrice for EVM execution, unless we're all zeroes @@ -228,7 +228,7 @@ func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int) if args.Value != nil { overflow := value.SetFromBig(args.Value.ToInt()) if overflow { - return types.Message{}, errors.New("args.Value higher than 2^256-1") + return nil, errors.New("args.Value higher than 2^256-1") } } var data []byte @@ -1093,7 +1093,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) var execResult *evmtypes.ExecutionResult ibs.SetTxContext(0) - execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */) + execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */, engine) if err != nil { return nil, err } @@ -1192,7 +1192,7 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, pa return nil, errors.New("header.BaseFee uint256 overflow") } } - msgs := make([]types.Message, len(callParams)) + msgs := make([]*types.Message, len(callParams)) for i, args := range callParams { msgs[i], err = args.ToMessage(api.gasCap, baseFee) if err != nil { @@ -1221,7 +1221,7 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, pa func (api *TraceAPIImpl) doCallBlock(ctx context.Context, dbtx kv.Tx, stateReader state.StateReader, stateCache *shards.StateCache, cachedWriter state.StateWriter, ibs *state.IntraBlockState, - msgs []types.Message, callParams []TraceCallParam, + msgs []*types.Message, callParams []TraceCallParam, parentNrOrHash *rpc.BlockNumberOrHash, header *types.Header, gasBailout bool, traceConfig *config.TraceConfig, ) ([]*TraceCallResult, error) { @@ -1377,7 +1377,7 @@ func (api *TraceAPIImpl) doCallBlock(ctx context.Context, dbtx kv.Tx, stateReade evm := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vmConfig) gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) - execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, gasBailout /*gasBailout*/) + execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, gasBailout /*gasBailout*/, engine) } if err != nil { return nil, fmt.Errorf("first run for txIndex %d error: %w", txIndex, err) @@ -1421,7 +1421,7 @@ func (api *TraceAPIImpl) doCallBlock(ctx context.Context, dbtx kv.Tx, stateReade func (api *TraceAPIImpl) doCall(ctx context.Context, dbtx kv.Tx, stateReader state.StateReader, stateCache *shards.StateCache, cachedWriter state.StateWriter, ibs *state.IntraBlockState, - msg types.Message, callParam TraceCallParam, + msg *types.Message, callParam TraceCallParam, parentNrOrHash *rpc.BlockNumberOrHash, header *types.Header, gasBailout bool, txIndex int, traceConfig *config.TraceConfig, ) (*TraceCallResult, error) { @@ -1575,7 +1575,7 @@ func (api *TraceAPIImpl) doCall(ctx context.Context, dbtx kv.Tx, stateReader sta evm := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vmConfig) gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) - execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, gasBailout /*gasBailout*/) + execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, gasBailout /*gasBailout*/, engine) } if err != nil { return nil, fmt.Errorf("first run for txIndex %d error: %w", txIndex, err) diff --git a/turbo/jsonrpc/trace_filtering.go b/turbo/jsonrpc/trace_filtering.go index b8ce037e9bc..33aa1358007 100644 --- a/turbo/jsonrpc/trace_filtering.go +++ b/turbo/jsonrpc/trace_filtering.go @@ -614,7 +614,7 @@ func (api *TraceAPIImpl) filterV3(ctx context.Context, dbtx kv.TemporalTx, fromB gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) ibs.SetTxContext(txIndex) var execResult *evmtypes.ExecutionResult - execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, gasBailOut) + execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, gasBailOut, engine) if err != nil { if first { first = false @@ -789,11 +789,11 @@ func (api *TraceAPIImpl) callBlock( return nil, nil, err } - msgs := make([]types.Message, len(txs)) + msgs := make([]*types.Message, len(txs)) for i, txn := range txs { isBorStateSyncTxn := txn == borStateSyncTxn var txnHash common.Hash - var msg types.Message + var msg *types.Message var err error if isBorStateSyncTxn { txnHash = borStateSyncTxnHash @@ -804,14 +804,6 @@ func (api *TraceAPIImpl) callBlock( if err != nil { return nil, nil, fmt.Errorf("convert txn into msg: %w", err) } - - // gnosis might have a fee free account here - if msg.FeeCap().IsZero() && engine != nil { - syscall := func(contract common.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, cfg, ibs, header, engine, true /* constCall */) - } - msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall)) - } } callParams = append(callParams, TraceCallParam{ @@ -916,7 +908,7 @@ func (api *TraceAPIImpl) callTransaction( } var txnHash common.Hash - var msg types.Message + var msg *types.Message if cfg.Bor != nil { txnHash = borStateSyncTxnHash // we use an empty message for bor state sync txn since it gets handled differently @@ -926,14 +918,6 @@ func (api *TraceAPIImpl) callTransaction( if err != nil { return nil, nil, fmt.Errorf("convert txn into msg: %w", err) } - - // gnosis might have a fee free account here - if msg.FeeCap().IsZero() && engine != nil { - syscall := func(contract common.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, cfg, ibs, header, engine, true /* constCall */) - } - msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall)) - } } callParam := TraceCallParam{ diff --git a/turbo/jsonrpc/tracing.go b/turbo/jsonrpc/tracing.go index b9b53c563c2..88f681f3cdb 100644 --- a/turbo/jsonrpc/tracing.go +++ b/turbo/jsonrpc/tracing.go @@ -162,13 +162,6 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp ibs.SetTxContext(txnIndex) msg, _ := txn.AsMessage(*signer, block.BaseFee(), rules) - if msg.FeeCap().IsZero() && engine != nil { - syscall := func(contract common.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, chainConfig, ibs, block.Header(), engine, true /* constCall */) - } - msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall)) - } - txCtx := evmtypes.TxContext{ TxHash: txnHash, Origin: msg.From(), @@ -201,7 +194,7 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp usedGas += _usedGas } else { var _usedGas uint64 - _usedGas, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, block.Hash(), txnIndex, ibs, config, chainConfig, stream, api.evmCallTimeout) + _usedGas, err = transactions.TraceTx(ctx, engine, msg, blockCtx, txCtx, block.Hash(), txnIndex, ibs, config, chainConfig, stream, api.evmCallTimeout) usedGas += _usedGas } if err == nil { @@ -365,7 +358,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo } // Trace the transaction and return - _, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, block.Hash(), txnIndex, ibs, config, chainConfig, stream, api.evmCallTimeout) + _, err = transactions.TraceTx(ctx, engine, msg, blockCtx, txCtx, block.Hash(), txnIndex, ibs, config, chainConfig, stream, api.evmCallTimeout) return err } @@ -434,7 +427,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA blockCtx := transactions.NewEVMBlockContext(engine, header, blockNrOrHash.RequireCanonical, dbtx, api._blockReader, chainConfig) txCtx := core.NewEVMTxContext(msg) // Trace the transaction and return - _, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, hash, 0, ibs, config, chainConfig, stream, api.evmCallTimeout) + _, err = transactions.TraceTx(ctx, engine, msg, blockCtx, txCtx, hash, 0, ibs, config, chainConfig, stream, api.evmCallTimeout) return err } @@ -572,7 +565,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun } txCtx = core.NewEVMTxContext(msg) ibs.SetTxContext(txnIndex) - _, err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, block.Hash(), txnIndex, evm.IntraBlockState(), config, chainConfig, stream, api.evmCallTimeout) + _, err = transactions.TraceTx(ctx, api.engine(), msg, blockCtx, txCtx, block.Hash(), txnIndex, evm.IntraBlockState(), config, chainConfig, stream, api.evmCallTimeout) if err != nil { stream.WriteArrayEnd() stream.WriteArrayEnd() diff --git a/turbo/transactions/call.go b/turbo/transactions/call.go index ccfebaa001d..644db44d2bb 100644 --- a/turbo/transactions/call.go +++ b/turbo/transactions/call.go @@ -110,7 +110,7 @@ func DoCall( }() gp := new(core.GasPool).AddGas(msg.Gas()).AddBlobGas(msg.BlobGas()) - result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) + result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */, engine) if err != nil { return nil, err } @@ -156,6 +156,7 @@ type ReusableCaller struct { func (r *ReusableCaller) DoCallWithNewGas( ctx context.Context, newGas uint64, + engine consensus.EngineReader, ) (*evmtypes.ExecutionResult, error) { var cancel context.CancelFunc if r.callTimeout > 0 { @@ -183,7 +184,7 @@ func (r *ReusableCaller) DoCallWithNewGas( gp := new(core.GasPool).AddGas(r.message.Gas()).AddBlobGas(r.message.BlobGas()) - result, err := core.ApplyMessage(r.evm, r.message, gp, true /* refunds */, false /* gasBailout */) + result, err := core.ApplyMessage(r.evm, r.message, gp, true /* refunds */, false /* gasBailout */, engine) if err != nil { return nil, err } @@ -243,6 +244,6 @@ func NewReusableCaller( gasCap: gasCap, callTimeout: callTimeout, stateReader: stateReader, - message: &msg, + message: msg, }, nil } diff --git a/turbo/transactions/tracing.go b/turbo/transactions/tracing.go index ffd7db24f59..5f5e6394690 100644 --- a/turbo/transactions/tracing.go +++ b/turbo/transactions/tracing.go @@ -83,15 +83,8 @@ func ComputeTxContext(statedb *state.IntraBlockState, engine consensus.EngineRea txn := block.Transactions()[txIndex] statedb.SetTxContext(txIndex) msg, _ := txn.AsMessage(*signer, block.BaseFee(), rules) - if msg.FeeCap().IsZero() && engine != nil { - syscall := func(contract libcommon.Address, data []byte) ([]byte, error) { - return core.SysCallContract(contract, data, cfg, statedb, block.HeaderNoCopy(), engine, true /* constCall */) - } - msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall)) - } - - TxContext := core.NewEVMTxContext(msg) - return msg, TxContext, nil + txContext := core.NewEVMTxContext(msg) + return msg, txContext, nil } // TraceTx configures a new tracer according to the provided configuration, and @@ -99,6 +92,7 @@ func ComputeTxContext(statedb *state.IntraBlockState, engine consensus.EngineRea // be tracer dependent. func TraceTx( ctx context.Context, + engine consensus.EngineReader, message core.Message, blockCtx evmtypes.BlockContext, txCtx evmtypes.TxContext, @@ -120,7 +114,7 @@ func TraceTx( execCb := func(evm *vm.EVM, refunds bool) (*evmtypes.ExecutionResult, error) { gp := new(core.GasPool).AddGas(message.Gas()).AddBlobGas(message.BlobGas()) - res, err := core.ApplyMessage(evm, message, gp, refunds, false /* gasBailout */) + res, err := core.ApplyMessage(evm, message, gp, refunds, false /* gasBailout */, engine) if err != nil { return res, err }