Skip to content

Commit

Permalink
Add block number to mempool_executed logs (#3200)
Browse files Browse the repository at this point in the history
# Description
Add block number to mempool_executed logs, so we can simulate failed
submissions in order to debug the reason of the failure.

---------

Co-authored-by: ilya <[email protected]>
  • Loading branch information
m-lord-renkse and squadgazzz authored Jan 6, 2025
1 parent 4d82068 commit 9b6743a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
24 changes: 16 additions & 8 deletions crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Mempools {
// settlement. This way we only run iterations in blocks that can potentially
// include the settlement.
let mut block_stream = into_stream(self.ethereum.current_block().clone());
block_stream.next().await;
let block = 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
Expand All @@ -116,7 +116,7 @@ impl Mempools {
?err,
"settlement tx simulation reverted before submitting to the mempool"
);
return Err(Error::SimulationRevert);
return Err(Error::SimulationRevert(block.map(|block| block.number)));
} else {
tracing::warn!(
?err,
Expand All @@ -142,7 +142,12 @@ impl Mempools {
});
match receipt {
TxStatus::Executed => return Ok(hash.clone()),
TxStatus::Reverted => return Err(Error::Revert(hash.clone())),
TxStatus::Reverted => {
return Err(Error::Revert {
tx_id: hash.clone(),
block_number: block.number,
})
}
TxStatus::Pending => {
// Check if the current block reached the submission deadline block number
if block.number >= submission_deadline {
Expand Down Expand Up @@ -172,7 +177,7 @@ impl Mempools {
?err,
"tx started failing in mempool, cancelling"
);
return Err(Error::SimulationRevert);
return Err(Error::SimulationRevert(Some(block.number)));
} else {
tracing::warn!(?hash, ?err, "couldn't re-simulate tx");
}
Expand Down Expand Up @@ -235,10 +240,13 @@ pub enum RevertProtection {

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Mined reverted transaction: {0:?}")]
Revert(eth::TxId),
#[error("Simulation started reverting during submission")]
SimulationRevert,
#[error("Mined reverted transaction: {tx_id:?}, block number: {block_number}")]
Revert {
tx_id: eth::TxId,
block_number: BlockNo,
},
#[error("Simulation started reverting during submission, block number: {0:?}")]
SimulationRevert(Option<BlockNo>),
#[error("Settlement did not get included in time")]
Expired,
#[error("Strategy disabled for this tx")]
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/infra/notify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub fn executed(
) {
let kind = match res {
Ok(hash) => notification::Settlement::Success(hash.clone()),
Err(Error::Revert(hash)) => notification::Settlement::Revert(hash.clone()),
Err(Error::SimulationRevert) => notification::Settlement::SimulationRevert,
Err(Error::Revert { tx_id: hash, .. }) => notification::Settlement::Revert(hash.clone()),
Err(Error::SimulationRevert { .. }) => notification::Settlement::SimulationRevert,
Err(Error::Expired) => notification::Settlement::Expired,
Err(Error::Other(_) | Error::Disabled) => notification::Settlement::Fail,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pub fn mempool_executed(
}
let result = match res {
Ok(_) => "Success",
Err(mempools::Error::Revert(_) | mempools::Error::SimulationRevert) => "Revert",
Err(mempools::Error::Revert { .. } | mempools::Error::SimulationRevert { .. }) => "Revert",
Err(mempools::Error::Expired) => "Expired",
Err(mempools::Error::Other(_)) => "Other",
Err(mempools::Error::Disabled) => "Disabled",
Expand Down

0 comments on commit 9b6743a

Please sign in to comment.