From 0921f8a74f1c050792453fc241eef67d7400d94c Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 10:29:48 +0200 Subject: [PATCH] internal/ethapi: add optional parameter blockNrOrHash to estimateGas (#21545) This allows users to estimate gas on top of arbitrary blocks as well as pending and latest. Tracing on pending is useful for most users as it takes into account the current txpool while tracing on latest might be useful for users that have little to know knowledge of the current transactions in the network. If blockNrOrHash is not specified, estimateGas defaults to pending --- internal/ethapi/api.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c035b7a9e..eaa743fe3 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1051,9 +1051,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash // EstimateGas returns an estimate of the amount of gas needed to execute the // given transaction against the current pending block. -func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error) { - blockNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) - return DoEstimateGas(ctx, s.b, args, blockNrOrHash, s.b.RPCGasCap()) +func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { + bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) + if blockNrOrHash != nil { + bNrOrHash = *blockNrOrHash + } + return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap()) } // ExecutionResult groups all structured logs emitted by the EVM