Skip to content

Commit

Permalink
[EASY] Simulate settlement tx before submitting (#3166)
Browse files Browse the repository at this point in the history
# Description
On the `base` network, there are more settlement tx onchain reverts than
expected. According to the logs, we couldn't catch those reverts using
`estimate_gas` calls that happen only **after** the tx is submitted to
the mempool. The tx also gets simulated before submitting a solution to
the competition. However, the delay between that event and the actual
execution can cause the tx to become invalid later. So, this PR adds
additional `estimate_gas` call **before** the tx gets submitted.

## How to test
Production logs.
  • Loading branch information
squadgazzz authored Dec 17, 2024
1 parent 8761e43 commit c93d3f6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ impl Mempools {
let mut block_stream = into_stream(self.ethereum.current_block().clone());
block_stream.next().await;

// The tx is simulated before submitting the solution to the competition, but a
// delay between that and the actual execution can cause the simulation to be
// invalid which doesn't make sense to submit to the mempool anymore.
if let Err(err) = self.ethereum.estimate_gas(tx).await {
if err.is_revert() {
tracing::info!(
?err,
"settlement tx simulation reverted before submitting to the mempool"
);
return Err(Error::SimulationRevert);
} else {
tracing::warn!(
?err,
"couldn't simulate tx before submitting to the mempool"
);
}
}

let hash = mempool.submit(tx.clone(), settlement.gas, solver).await?;
tracing::debug!(?hash, "submitted tx to the mempool");

Expand Down

0 comments on commit c93d3f6

Please sign in to comment.