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

Use previous block hash to compute tx effectiveGasPrice #1280

Merged

Conversation

elfedy
Copy link
Contributor

@elfedy elfedy commented Jan 15, 2024

On Moonbeam, we were getting some discrepancies between the effectiveGasPrice reported by eth_getTransactionReceipt and the actual fee that was charged on transaction execution (As seen for example as part of the balances.Withdrawn event and then verifying the balance change in state). The fee should match gasUsed * eth_getTransactionReceipt but it is sometimes not the case for EIP-1559 transactions. An example case can be found here.

The issue was tracked down to eth_getTransactionReceipt rpc call doing the gas_price runtime api call for the same block the transaction happened to get the base fee. Since the state value (NextFeeMultiplier) on which base fee depends on in our case is updated on_finalize, the base_fee when the transaction is executed is different from base fee at the end of the block

image

This issue should be present on any chain that updates base fee during on_finalize as it is for example the case for the base fee pallet on this repo

We have made the patch on our frontier fork, with a failing test that passes on moonbeam

@elfedy elfedy requested a review from sorpaas as a code owner January 15, 2024 20:40
@elfedy elfedy force-pushed the elfedy-transaction-receipt-gas branch from 29f44ca to 1e34f95 Compare January 15, 2024 21:10
.unwrap_or_else(U256::max_value)
.min(t.max_fee_per_gas),
EthereumTransaction::EIP1559(t) => {
let parent_eth_hash = block.header.parent_hash;
Copy link
Member

Choose a reason for hiding this comment

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

If parent_hash is 0x0 then it indicates genesis block, and then we should short-circuit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified to use same block hash for the genesis block

@sorpaas sorpaas merged commit 5592ce6 into polkadot-evm:master Jan 16, 2024
4 checks passed
@elfedy elfedy deleted the elfedy-transaction-receipt-gas branch January 16, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants