From ba71677e4a249a37a7458e70f86831467bd85d86 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Tue, 23 Mar 2021 14:43:12 +0200 Subject: [PATCH] fix: cap the suggested fee to the gas limit --- internal/ethapi/api.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index d80a8d51a..097498f9b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1026,7 +1026,15 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash // 3. calculate the fee fee := core.CalculateRollupFee(*args.Data, uint64(gasUsed), dataPrice, executionPrice) - return (hexutil.Uint64)(fee.Uint64()), nil + + // 4. Do not allow it the fee to be higher than the gas limit + block, err := b.BlockByNumberOrHash(ctx, blockNrOrHash) + res := fee.Uint64() + if res > block.GasLimit() { + res = block.GasLimit() + } + + return (hexutil.Uint64)(res), nil } func legacyDoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap *big.Int) (hexutil.Uint64, error) {