From 7ed3f47e8c0afab134b3d7b84361f27ff7c1fd83 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Thu, 25 Nov 2021 10:17:11 +0800 Subject: [PATCH 1/3] Problem: web3 rpc api returns wrong block gas limit Closes: #777 Solution: - pass in specific block height to the query --- rpc/ethereum/backend/backend.go | 2 +- rpc/ethereum/types/utils.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/ethereum/backend/backend.go b/rpc/ethereum/backend/backend.go index ca2da3d991..32b2308e63 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 c5cd488085..d06f676faa 100644 --- a/rpc/ethereum/types/utils.go +++ b/rpc/ethereum/types/utils.go @@ -65,8 +65,8 @@ 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) +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 } From 44181b2355710bcf8dce3ddaed7c31f8bd7bb10d Mon Sep 17 00:00:00 2001 From: yihuang Date: Thu, 25 Nov 2021 15:14:39 +0800 Subject: [PATCH 2/3] Apply suggestions from code review --- rpc/ethereum/types/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/ethereum/types/utils.go b/rpc/ethereum/types/utils.go index d06f676faa..4bfcd6cace 100644 --- a/rpc/ethereum/types/utils.go +++ b/rpc/ethereum/types/utils.go @@ -64,7 +64,7 @@ func EthHeaderFromTendermint(header tmtypes.Header, bloom ethtypes.Bloom, baseFe } } -// BlockMaxGasFromConsensusParams returns the gas limit for the latest block from the chain consensus params. +// 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 { From e276408de56305cc734c1c7694d075ab18e7f871 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Thu, 25 Nov 2021 19:21:28 +0800 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3442be0948..28e4d29f4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,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