diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 5f2f16627a..70cbd230e0 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -986,7 +986,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc } var ( msg = args.ToMessage(blockContext.BaseFee, true) - tx = args.ToTransaction(types.DynamicFeeTxType) + tx, _ = args.ToTransaction(types.DynamicFeeTxType) traceConfig *TraceConfig ) // Lower the basefee to 0 to avoid breaking EVM diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 4f3071cb03..7c575d190b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1371,7 +1371,12 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH } res, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(msg.GasLimit)) if err != nil { - return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.ToTransaction(types.LegacyTxType).Hash(), err) + var hash common.Hash + tx, err := args.ToTransaction(types.LegacyTxType) + if err == nil { + hash = tx.Hash() + } + return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", hash, err) } if tracer.Equal(prevTracer) { return accessList, res.UsedGas, res.Err, nil @@ -1642,7 +1647,10 @@ func (api *TransactionAPI) SendTransaction(ctx context.Context, args Transaction return common.Hash{}, err } // Assemble the transaction and sign with the wallet - tx := args.ToTransaction(types.DynamicFeeTxType) + tx, err := args.ToTransaction(types.DynamicFeeTxType) + if err != nil { + return common.Hash{}, err + } signed, err := wallet.SignTx(account, tx, api.b.ChainConfig().ChainID) if err != nil { @@ -1664,7 +1672,10 @@ func (api *TransactionAPI) FillTransaction(ctx context.Context, args Transaction return nil, err } // Assemble the transaction and obtain rlp - tx := args.ToTransaction(types.DynamicFeeTxType) + tx, err := args.ToTransaction(types.DynamicFeeTxType) + if err != nil { + return nil, err + } data, err := tx.MarshalBinary() if err != nil { return nil, err @@ -1860,7 +1871,10 @@ func (api *TransactionAPI) SignTransaction(ctx context.Context, args Transaction return nil, err } // Before actually sign the transaction, ensure the transaction fee is reasonable. - tx := args.ToTransaction(types.DynamicFeeTxType) + tx, err := args.ToTransaction(types.DynamicFeeTxType) + if err != nil { + return nil, err + } if err := checkTxFee(tx.GasPrice(), tx.Gas(), api.b.RPCTxFeeCap()); err != nil { return nil, err } @@ -1916,7 +1930,10 @@ func (api *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, if err := sendArgs.setDefaults(ctx, api.b, sidecarConfig{}); err != nil { return common.Hash{}, err } - matchTx := sendArgs.ToTransaction(types.DynamicFeeTxType) + matchTx, err := sendArgs.ToTransaction(types.DynamicFeeTxType) + if err != nil { + return common.Hash{}, err + } // Before replacing the old transaction, ensure the _new_ transaction fee is reasonable. price := matchTx.GasPrice() @@ -1946,7 +1963,11 @@ func (api *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, if gasLimit != nil && *gasLimit != 0 { sendArgs.Gas = gasLimit } - signedTx, err := api.sign(sendArgs.from(), sendArgs.ToTransaction(types.DynamicFeeTxType)) + tx, err := sendArgs.ToTransaction(types.DynamicFeeTxType) + if err != nil { + return common.Hash{}, err + } + signedTx, err := api.sign(sendArgs.from(), tx) if err != nil { return common.Hash{}, err } diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index c9396cd327..e7117cec5e 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -279,7 +279,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, return nil, nil, nil, err } var ( - tx = call.ToTransaction(types.DynamicFeeTxType) + tx, _ = call.ToTransaction(types.DynamicFeeTxType) txHash = tx.Hash() ) txes[i] = tx diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index ab709d3558..3689d1baf0 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -74,24 +74,6 @@ type TransactionArgs struct { AuthorizationList []types.SetCodeAuthorization `json:"authorizationList"` } -func (args *TransactionArgs) inferTxType(defaultType int) int { - usedType := types.LegacyTxType - switch { - case args.AuthorizationList != nil || defaultType == types.SetCodeTxType: - usedType = types.SetCodeTxType - case args.BlobHashes != nil || defaultType == types.BlobTxType: - usedType = types.BlobTxType - case args.MaxFeePerGas != nil || defaultType == types.DynamicFeeTxType: - usedType = types.DynamicFeeTxType - case args.AccessList != nil || defaultType == types.AccessListTxType: - usedType = types.AccessListTxType - } - if args.GasPrice != nil { - usedType = types.LegacyTxType - } - return usedType -} - // from retrieves the transaction sender address. func (args *TransactionArgs) from() common.Address { if args.From == nil { @@ -196,32 +178,6 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, config } else { args.ChainID = (*hexutil.Big)(want) } - - // Validate explicit transaction type if provided - if args.Type != nil { - requested := int(*args.Type) - - // Validate supported types - switch requested { - case types.LegacyTxType, - types.AccessListTxType, - types.DynamicFeeTxType, - types.BlobTxType, - types.SetCodeTxType: - // ok - default: - return fmt.Errorf("unsupported transaction type: %d", requested) - } - - inferred := args.inferTxType(types.LegacyTxType) - - if requested != inferred { - return fmt.Errorf( - "transaction type mismatch (requested=%d inferred=%d)", - requested, inferred, - ) - } - } return nil } @@ -544,7 +500,7 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int, skipNonceCheck bool) *c // ToTransaction converts the arguments to a transaction. // This assumes that setDefaults has been called. -func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction { +func (args *TransactionArgs) ToTransaction(defaultType int) (*types.Transaction, error) { usedType := types.LegacyTxType switch { case args.AuthorizationList != nil || defaultType == types.SetCodeTxType: @@ -560,6 +516,9 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction { if args.GasPrice != nil { usedType = types.LegacyTxType } + if usedType != int(*args.Type) { + return nil, fmt.Errorf("wrong tx type used, requested: %v, used: %v", args.Type, usedType) + } var data types.TxData switch usedType { case types.SetCodeTxType: @@ -649,7 +608,7 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction { Data: args.data(), } } - return types.NewTx(data) + return types.NewTx(data), nil } // IsEIP4844 returns an indicator if the args contains EIP4844 fields.