From 3a74a2422af47d8fd58d5ec6e48a60da1c2d381f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 27 Oct 2023 07:37:51 -0700 Subject: [PATCH] fix: api: compute gasUsedRatio based on max gas in the tipset (#11354) We were computing this based on the max block gas, but this is incorrect. The new value isn't entirely correct either (we should probably compute an average of the gas used in each block in the tipset?), but it's good enough. fixes #10515 --- node/impl/full/eth.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index a4e413b12..f4d9d8371 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -825,10 +825,11 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth } rewards, totalGasUsed := calculateRewardsAndGasUsed(rewardPercentiles, txGasRewards) + maxGas := build.BlockGasLimit * int64(len(ts.Blocks())) // arrays should be reversed at the end baseFeeArray = append(baseFeeArray, ethtypes.EthBigInt(basefee)) - gasUsedRatioArray = append(gasUsedRatioArray, float64(totalGasUsed)/float64(build.BlockGasLimit)) + gasUsedRatioArray = append(gasUsedRatioArray, float64(totalGasUsed)/float64(maxGas)) rewardsArray = append(rewardsArray, rewards) oldestBlkHeight = uint64(ts.Height()) blocksIncluded++