Simulate txs on the latest block instead of pending#4387
Simulate txs on the latest block instead of pending#4387MartinquaXD wants to merge 2 commits intomainfrom
latest block instead of pending#4387Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the estimate_gas function in crates/driver/src/infra/blockchain/mod.rs to target the latest block instead of the pending block. This change is intended to avoid false positive reverts when re-checking transactions after they have been submitted to the mempool. No critical issues found.
This is a pretty interesting hypothesis. Do you have concrete evidence that this is causing reverts (e.g. example solutions where we can now see that they should still simulate successfully at n+1). I'd expect nodes to deduplicate pending transactions from the same sender/nonce. The other issue with |
Description
Currently the reference driver struggles to get transactions mined reliably. I think the reason is that we simulate the tx on the
pendingblock instead oflatest.For context
latestmeans simulate my tx on top of the last mined block whilependingmeans simulating on the latest block AND all txs in the mempool that have a higher gas price than my tx.I think this together with our logic that re-checks the tx on every new block (to detect reverts early and mine a cheaper cancellation tx instead of a more expensive revert) leads to seeing false reverts.
If we submit our tx on block
nand it's not included in blockn+1it would still be in the mempool for blockn+2. So if we re-simulate onpendingat blockn+1our previously submitted tx would already be in the set of pending txs that get applied before our simulation happens and since both txs touch the same state the second one will revert.Technically the optimal approach would be:
pendingwith the locked in gas pricelatestto avoid txs interfering with each other.But for the sake of simplicity I think it makes sense to first go with always using
latestinstead to see if this even has the desired impact in the first place.Changes
Always simulate txs on the
latestblock.How to test
Temporarily deploy this to prod to see how this effects inclusion times / rates.