From 80ba2b74af75e016b604777defac18139e04e88a Mon Sep 17 00:00:00 2001 From: William Morriss Date: Tue, 7 May 2024 18:10:22 -0700 Subject: [PATCH] remove ErrorRatio --- eth/gasestimator/gasestimator.go | 11 ----------- internal/ethapi/api.go | 4 ---- internal/ethapi/api_test.go | 2 +- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/eth/gasestimator/gasestimator.go b/eth/gasestimator/gasestimator.go index ac3b59e97e..10238f8d26 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -42,8 +42,6 @@ type Options struct { Chain core.ChainContext // Chain context to access past block hashes Header *types.Header // Header defining the block context to execute in State *state.StateDB // Pre-state on top of which to estimate the gas - - ErrorRatio float64 // Allowed overestimation ratio for faster estimation termination } // Estimate returns the lowest possible gas limit that allows the transaction to @@ -159,15 +157,6 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin } // Binary search for the smallest gas limit that allows the tx to execute successfully. for lo+1 < hi { - if opts.ErrorRatio > 0 { - // It is a bit pointless to return a perfect estimation, as changing - // network conditions require the caller to bump it up anyway. Since - // wallets tend to use 20-25% bump, allowing a small approximation - // error is fine (as long as it's upwards). - if float64(hi-lo)/float64(hi) < opts.ErrorRatio { - break - } - } mid := (hi + lo) / 2 if mid > lo*2 { // Most txs don't need much higher gas limit than their gas used, and most txs don't diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index d308cead62..e01d997c59 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -53,9 +53,6 @@ import ( "github.com/ethereum/go-ethereum/trie" ) -// estimateGasErrorRatio is the amount of overestimation eth_estimateGas is -// allowed to produce in order to speed up calculations. -const estimateGasErrorRatio = 0.015 var errBlobTxNotSupported = errors.New("signing blob transactions not supported") @@ -1197,7 +1194,6 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr Chain: NewChainContext(ctx, b), Header: header, State: state, - ErrorRatio: estimateGasErrorRatio, } if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil { return 0, err diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index a717ebdfae..c8c171de51 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -773,7 +773,7 @@ func TestEstimateGas(t *testing.T) { t.Errorf("test %d: want no error, have %v", i, err) continue } - if float64(result) > float64(tc.want)*(1+estimateGasErrorRatio) { + if uint64(result) != tc.want { t.Errorf("test %d, result mismatch, have\n%v\n, want\n%v\n", i, uint64(result), tc.want) } }