-
Notifications
You must be signed in to change notification settings - Fork 20.9k
ethclient: Add EstimateGasAt[Hash] to estimate gas against a specific block #27508
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
ethclient: Add EstimateGasAt[Hash] to estimate gas against a specific block #27508
Conversation
I just was bitten by this: I had a contract that (sometimes) calls blockhash against the latest block, and it was returning 0 in EstimateGas due to default of latest over pending. I think it does make sense for EstimateGas to run over latest state instead of pending, since who knows what will actually end up the pending state of the blockchain when the tx actually executes. But perhaps it could be made to think the block.number is the pending block, since we do know that (ignoring re-orgs) it will execute at a strictly higher block.number than "latest". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, judging from the RPC spec, specifying the blocknumber is already part of the spec, so all clients should ™️ support it, so we can add it to ethclient. Not sure about the blockhash though
cc @lightclient
…c block (ethereum#27508) The main use case I see of this is that it allows users to estimate gas against the same state that they query for their nonce, and the same state they base the data of their transaction against. This helps ensure that gas estimation won't fail and the transaction won't revert on-chain because of a mismatch between the state used for gas estimation and the state used to generate the inputs to gas estimation or the transaction's nonce when submitted to the mempool. This PR also updates the EstimateGas comment based on the new geth `eth_estimateGas` default of using latest state as of v1.12.0: ethereum#24363 --------- Co-authored-by: Felix Lange <[email protected]>
…c block (ethereum#27508) The main use case I see of this is that it allows users to estimate gas against the same state that they query for their nonce, and the same state they base the data of their transaction against. This helps ensure that gas estimation won't fail and the transaction won't revert on-chain because of a mismatch between the state used for gas estimation and the state used to generate the inputs to gas estimation or the transaction's nonce when submitted to the mempool. This PR also updates the EstimateGas comment based on the new geth `eth_estimateGas` default of using latest state as of v1.12.0: ethereum#24363 --------- Co-authored-by: Felix Lange <[email protected]>
…c block (ethereum#27508) The main use case I see of this is that it allows users to estimate gas against the same state that they query for their nonce, and the same state they base the data of their transaction against. This helps ensure that gas estimation won't fail and the transaction won't revert on-chain because of a mismatch between the state used for gas estimation and the state used to generate the inputs to gas estimation or the transaction's nonce when submitted to the mempool. This PR also updates the EstimateGas comment based on the new geth `eth_estimateGas` default of using latest state as of v1.12.0: ethereum#24363 --------- Co-authored-by: Felix Lange <[email protected]>
The main use case I see of this is that it allows users to estimate gas against the same state that they query for their nonce, and the same state they base the data of their transaction against. This helps ensure that gas estimation won't fail and the transaction won't revert on-chain because of a mismatch between the state used for gas estimation and the state used to generate the inputs to gas estimation or the transaction's nonce when submitted to the mempool.
This PR also updates the EstimateGas comment based on the new geth
eth_estimateGas
default of using latest state as of v1.12.0: #24363