From 0fc9cca9949b70a5028e63e7af01f3fe9032b10e Mon Sep 17 00:00:00 2001 From: jwasinger Date: Fri, 8 Nov 2024 21:33:43 +0900 Subject: [PATCH] internal/ethapi: Set basefee for `AccessList` based on given block, not chain tip (#30538) --- internal/ethapi/api.go | 11 ++++++++++- internal/ethapi/transaction_args.go | 5 ++--- internal/ethapi/transaction_args_test.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index bea615bf44..a508b0ca5b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1287,9 +1287,18 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH } // Ensure any missing fields are filled, extract the recipient and input data - if err := args.setDefaults(ctx, b, true); err != nil { + if err = args.setFeeDefaults(ctx, b, header); err != nil { return nil, 0, nil, err } + if args.Nonce == nil { + nonce := hexutil.Uint64(db.GetNonce(args.from())) + args.Nonce = &nonce + } + blockCtx := core.NewEVMBlockContext(header, NewChainContext(ctx, b), nil) + if err = args.CallDefaults(b.RPCGasCap(), blockCtx.BaseFee, b.ChainConfig().ChainID); err != nil { + return nil, 0, nil, err + } + var to common.Address if args.To != nil { to = *args.To diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index b6346e910d..91e05544dc 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -100,7 +100,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGas if err := args.setBlobTxSidecar(ctx); err != nil { return err } - if err := args.setFeeDefaults(ctx, b); err != nil { + if err := args.setFeeDefaults(ctx, b, b.CurrentHeader()); err != nil { return err } @@ -183,8 +183,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, skipGas } // setFeeDefaults fills in default fee values for unspecified tx fields. -func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) error { - head := b.CurrentHeader() +func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend, head *types.Header) error { // Sanity check the EIP-4844 fee parameters. if args.BlobFeeCap != nil && args.BlobFeeCap.ToInt().Sign() == 0 { return errors.New("maxFeePerBlobGas, if specified, must be non-zero") diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index a3bf19b686..5f59b491e1 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -238,7 +238,7 @@ func TestSetFeeDefaults(t *testing.T) { t.Fatalf("failed to set fork: %v", err) } got := test.in - err := got.setFeeDefaults(ctx, b) + err := got.setFeeDefaults(ctx, b, b.CurrentHeader()) if err != nil { if test.err == nil { t.Fatalf("test %d (%s): unexpected error: %s", i, test.name, err)