From a3f521203e4da0b1f251e1671d1f6bce59dffbdc Mon Sep 17 00:00:00 2001 From: barryz Date: Mon, 8 Nov 2021 13:01:42 +0800 Subject: [PATCH 1/2] revert fake_msg pull request #12 --- eth/api_pre_exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/api_pre_exec.go b/eth/api_pre_exec.go index ab63e1ff16..14236c8a1f 100644 --- a/eth/api_pre_exec.go +++ b/eth/api_pre_exec.go @@ -93,7 +93,7 @@ func (api *PreExecAPI) getBlockAndMsg(origin *PreExecTx, number *big.Int) (*type tx.GasFeeCap(), tx.GasTipCap(), hexutil.MustDecode(origin.Data), - nil, true, + nil, false, ) return block, msg From 56c1660a4b16a9653b3d96c616050f1336943ab1 Mon Sep 17 00:00:00 2001 From: barryz Date: Mon, 8 Nov 2021 13:05:31 +0800 Subject: [PATCH 2/2] revert estimateGas optimization #5 --- internal/ethapi/api.go | 49 ++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a61f65f285..f6d1731dbe 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -990,17 +990,6 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, bl } func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (g hexutil.Uint64, e error) { - defer func(start time.Time) { - msg := []interface{}{"elapsed", common.PrettyDuration(time.Since(start))} - if e != nil { - to := "" - if args.To != nil { - to = args.To.String() - } - msg = append(msg, "to", to) - log.Debug("Execute estimateGas call finished", msg...) - } - }(time.Now()) // Binary search the gas requirement, as it may be higher than the amount used var ( lo uint64 = params.TxGas - 1 @@ -1083,23 +1072,6 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr } return result.Failed(), result, nil } - - // Reject the transaction as invalid if it still fails at the highest allowance - failed, result, err := executable(hi) - if err != nil { - return 0, err - } - if failed { - if result != nil && result.Err != vm.ErrOutOfGas { - if len(result.Revert()) > 0 { - return 0, newRevertError(result) - } - return 0, result.Err - } - // Otherwise, the specified gas cap is too low - return 0, fmt.Errorf("gas required exceeds allowance (%d)", cap) - } - // Execute the binary search and hone in on an executable gas limit for lo+1 < hi { mid := (hi + lo) / 2 @@ -1116,13 +1088,24 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr } else { hi = mid } - - // estimate gas approximately - if hi-lo < 4000 { - break + } + // Reject the transaction as invalid if it still fails at the highest allowance + if hi == cap { + failed, result, err := executable(hi) + if err != nil { + return 0, err + } + if failed { + if result != nil && result.Err != vm.ErrOutOfGas { + if len(result.Revert()) > 0 { + return 0, newRevertError(result) + } + return 0, result.Err + } + // Otherwise, the specified gas cap is too low + return 0, fmt.Errorf("gas required exceeds allowance (%d)", cap) } } - return hexutil.Uint64(hi), nil }