Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eth_feeHistory gasUsedRatio #313

Merged
merged 2 commits into from
May 2, 2024
Merged

Fix eth_feeHistory gasUsedRatio #313

merged 2 commits into from
May 2, 2024

Conversation

Tristan-Wilson
Copy link
Member

The intent for eth_feeHistory for Arbitrum is to return the ratio of gas used per second / the target gas per second. The logic for calculating this gets the receipts for each tx in a block and gets the cumulative gas used, but it was using the wrong hash to look up the receipts (it should be the block hash and not the receipts hash).

Note: the current implementation returns 1.0 for gasUsedRatio for the blocks at the beginning of the window specified by eth_feeHistory's blockCount and newestBlock if the prior block has the same timestamp as the first block in the window (ie time has not ticked over).

Testing done

Not tested directly. By looking at results of eth_feeHistory on arb1 we can infer from first few blocks gasUsedRatio being 1 and the rest being zero that time is progressing but currentTimestampGasUsed must be zero.

$ curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_feeHistory","id":67,"params":["20", "latest", [100.0]]}' https://arb1.arbitrum.io/rpc
{"jsonrpc":"2.0","id":67,"result":{"oldestBlock":"0xc537885","reward":[["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"],["0x0"]],"baseFeePerGas":["0x20e1b98","0x20f09e0","0x2112108","0x212f9b0","0x20f8eb0","0x211ffb0","0x2130950","0x2154b70","0x2145170","0x216f920","0x219faa8","0x2207ea0","0x21ebd68","0x2215578","0x2275888","0x22b8ea8","0x22915d8","0x22c0ba8","0x230af28","0x235cfa8","0x2351428"],"gasUsedRatio":[1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}

The only way for it to be zero is if there were no receipts. By looking at other uses of Blockchain.GetReceiptsByHash we can see it's supposed to be the block hash and not the receipts hash https://github.com/OffchainLabs/go-ethereum/blob/master/core/blockchain.go#L725, which would explain zero receipts.

The intent for eth_feeHistory for Arbitrum is to return the ratio of gas
used per second / the target gas per second. The logic for calculating
this gets the receipts for each tx in a block and gets the cumulative
gas used, but it was using the wrong hash to look up the receipts (it
should be the block hash and not the receipts hash).

Note: the current implementation returns 1.0 for gasUsedRatio for the
blocks at the beginning of the window specified by eth_feeHistory's
blockCount and newestBlock if the prior block has the same timestamp as
the first block in the window (ie time has not ticked over).
@cla-bot cla-bot bot added the s CLA signed label May 2, 2024
Copy link
Collaborator

@PlasmaPower PlasmaPower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PlasmaPower PlasmaPower enabled auto-merge May 2, 2024 15:10
@PlasmaPower PlasmaPower merged commit b031b01 into master May 2, 2024
3 of 4 checks passed
@PlasmaPower PlasmaPower deleted the fix-fee-history branch May 2, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s CLA signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants