From 97a4b1257c0be9e7451b738b9b951fa7da7758d4 Mon Sep 17 00:00:00 2001 From: SangIlMo Date: Wed, 8 May 2024 23:41:14 +0900 Subject: [PATCH 1/4] internal/ethapi: recap higher args.Gas with block GasLimit in DoEstimateGas --- internal/ethapi/api.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index d308cead627f..fda0341a170c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1202,6 +1202,11 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil { return 0, err } + // when gas is over header.GasLimit, just recap with header.GasLimit + if uint64(*args.Gas) > header.GasLimit { + *args.Gas = (hexutil.Uint64)(header.GasLimit) + } + call := args.ToMessage(header.BaseFee) // Run the gas estimation andwrap any revertals into a custom return estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap) From 8465891486f50c37239fba36a5b20774866288a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 3 Jun 2024 15:06:46 +0300 Subject: [PATCH 2/4] internal/ethapi: fix gas estimator capping code --- internal/ethapi/api.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index fda0341a170c..37e0a75fc8cd 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1199,15 +1199,16 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr State: state, ErrorRatio: estimateGasErrorRatio, } + // Set any required transaction default, but make sure the gas cap itself is not messed with + nilGas := args.Gas == nil if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil { return 0, err } - // when gas is over header.GasLimit, just recap with header.GasLimit - if uint64(*args.Gas) > header.GasLimit { - *args.Gas = (hexutil.Uint64)(header.GasLimit) + if nilGas && args.Gas != nil { + args.Gas = nil } - call := args.ToMessage(header.BaseFee) + // Run the gas estimation andwrap any revertals into a custom return estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap) if err != nil { From 92d1f2f9ff81c8ab393756139e61176707ddc8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 3 Jun 2024 15:36:26 +0300 Subject: [PATCH 3/4] internal/ethapi: fix test --- internal/ethapi/api.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index e700164d9032..bf8faeacab78 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1200,16 +1200,16 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr ErrorRatio: estimateGasErrorRatio, } // Set any required transaction default, but make sure the gas cap itself is not messed with - nilGas := args.Gas == nil + // if it was not specified in the original argument list. + if args.Gas == nil { + args.Gas = new(hexutil.Uint64) + } if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil { return 0, err } - if nilGas && args.Gas != nil { - args.Gas = nil - } call := args.ToMessage(header.BaseFee) - // Run the gas estimation and wrap any revertals into a custom return + // Run the gas estimation and wrap any revertals into a custom return estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap) if err != nil { if len(revert) > 0 { From e2d35606a1ac6219adda3a5316b9b085335da079 Mon Sep 17 00:00:00 2001 From: SangIlMo Date: Tue, 4 Jun 2024 16:12:29 +0900 Subject: [PATCH 4/4] fix goimports lint (remove space) --- internal/ethapi/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index bf8faeacab78..f211dcc6598b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1209,7 +1209,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr } call := args.ToMessage(header.BaseFee) - // Run the gas estimation and wrap any revertals into a custom return + // Run the gas estimation and wrap any revertals into a custom return estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap) if err != nil { if len(revert) > 0 {