From b2a287c4012b833530ce4f84b4a23eb31a986b5c Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 23 Nov 2023 11:30:43 +0200 Subject: [PATCH] Account for simulation failure --- internal/ethapi/api.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2d29942383..cba6559c14 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1282,9 +1282,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr // Optimization: if the transaction succeeded with gasLimit set to the first execution's // usedGas + gasRefund, then return that value immediately. Else, continue with the binary search. - _, _, err = executeEstimate(ctx, b, args, state.Copy(), header, gasCap, result.UsedGas + result.GasRefund) - if err == nil { - return hexutil.Uint64(result.UsedGas + result.GasRefund), nil + optimisticGasLimit := result.UsedGas + result.GasRefund + failed, _, err = executeEstimate(ctx, b, args, state.Copy(), header, gasCap, optimisticGasLimit) + if !failed && err == nil { + return hexutil.Uint64(optimisticGasLimit), nil } // For almost any transaction, the gas consumed by the unconstrained execution above