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
This commit is contained in:
Steven Allen 2023-10-27 07:37:51 -07:00
parent 56b0348e87
commit 3a74a2422a

View File

@ -825,10 +825,11 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth
} }
rewards, totalGasUsed := calculateRewardsAndGasUsed(rewardPercentiles, txGasRewards) rewards, totalGasUsed := calculateRewardsAndGasUsed(rewardPercentiles, txGasRewards)
maxGas := build.BlockGasLimit * int64(len(ts.Blocks()))
// arrays should be reversed at the end // arrays should be reversed at the end
baseFeeArray = append(baseFeeArray, ethtypes.EthBigInt(basefee)) 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) rewardsArray = append(rewardsArray, rewards)
oldestBlkHeight = uint64(ts.Height()) oldestBlkHeight = uint64(ts.Height())
blocksIncluded++ blocksIncluded++