Simulate solution on pending block #3992
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When the driver receives a solution from the solver it re-simulates it to make sure it doesn't actually revert.
Additionally the driver re-simulates a solution right before submitting it to the chain (in case it turned sour while the driver waited to be crowned the winner of the auction).
Both of these checks currently happen on the
latestblock but that is actually more risky than necessary. Instead we can also simulate on thependingblock. This effectively tells the node to simulate the transaction taking any higher priced transactions into account. If there is already a transaction in the mempool that tries to take advantage of the same arbitrage opportunity as our solution but is higher priced than our tx the solution would revert on thependingblock but not onlatest.Since we error out as early as possible to prevent the case of winning an auction with a solution that is doomed to fail it makes more sense to simulate on the
pendingblock.Changes
Changed driver code to do simulations on the
pendinginstead oflatestblockHow to test
Since this is treating a bit of an edge case and relies on actual prod traffic it would likely take quite a while running this in prod to clearly see the effects. I suggest to merge as is and re-evaluate after having this on all networks for a week.