From 32eaec8d994b66daf35bec83c7df2959913b0b08 Mon Sep 17 00:00:00 2001 From: yihuang Date: Thu, 25 Nov 2021 19:30:03 +0800 Subject: [PATCH] fix: web3 rpc api returns wrong block gas limit (#782) * Problem: web3 rpc api returns wrong block gas limit Closes: #777 Solution: - pass in specific block height to the query * Apply suggestions from code review * changelog --- CHANGELOG.md | 1 + rpc/ethereum/backend/backend.go | 2 +- rpc/ethereum/types/utils.go | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 144c10d0..48f44935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (feemarket) [tharsis#770](https://github.com/tharsis/ethermint/pull/770) Enable fee market (EIP1559) by default. * (rpc) [tharsis#769](https://github.com/tharsis/ethermint/pull/769) Fix default Ethereum signer for JSON-RPC. +* (rpc) [tharsis#782](https://github.com/tharsis/ethermint/pull/782) Fix wrong block gas limit returned by JSON-RPC. ## [v0.8.0] - 2021-11-17 diff --git a/rpc/ethereum/backend/backend.go b/rpc/ethereum/backend/backend.go index ca2da3d9..32b2308e 100644 --- a/rpc/ethereum/backend/backend.go +++ b/rpc/ethereum/backend/backend.go @@ -429,7 +429,7 @@ func (e *EVMBackend) EthBlockFromTendermint( validatorAddr := common.BytesToAddress(addr) - gasLimit, err := types.BlockMaxGasFromConsensusParams(ctx, e.clientCtx) + gasLimit, err := types.BlockMaxGasFromConsensusParams(ctx, e.clientCtx, block.Height) if err != nil { e.logger.Error("failed to query consensus params", "error", err.Error()) } diff --git a/rpc/ethereum/types/utils.go b/rpc/ethereum/types/utils.go index c5cd4880..4bfcd6ca 100644 --- a/rpc/ethereum/types/utils.go +++ b/rpc/ethereum/types/utils.go @@ -64,9 +64,9 @@ func EthHeaderFromTendermint(header tmtypes.Header, bloom ethtypes.Bloom, baseFe } } -// BlockMaxGasFromConsensusParams returns the gas limit for the latest block from the chain consensus params. -func BlockMaxGasFromConsensusParams(ctx context.Context, clientCtx client.Context) (int64, error) { - resConsParams, err := clientCtx.Client.ConsensusParams(ctx, nil) +// BlockMaxGasFromConsensusParams returns the gas limit for the current block from the chain consensus params. +func BlockMaxGasFromConsensusParams(goCtx context.Context, clientCtx client.Context, blockHeight int64) (int64, error) { + resConsParams, err := clientCtx.Client.ConsensusParams(goCtx, &blockHeight) if err != nil { return int64(^uint32(0)), err }