Skip to content

Commit 0921f8a

Browse files
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
1 parent 25b1608 commit 0921f8a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

internal/ethapi/api.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
10511051

10521052
// EstimateGas returns an estimate of the amount of gas needed to execute the
10531053
// given transaction against the current pending block.
1054-
func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error) {
1055-
blockNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
1056-
return DoEstimateGas(ctx, s.b, args, blockNrOrHash, s.b.RPCGasCap())
1054+
func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) {
1055+
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
1056+
if blockNrOrHash != nil {
1057+
bNrOrHash = *blockNrOrHash
1058+
}
1059+
return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap())
10571060
}
10581061

10591062
// ExecutionResult groups all structured logs emitted by the EVM

0 commit comments

Comments
 (0)