Skip to content

Commit

Permalink
Add block number to mempool_executed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Jan 1, 2025
1 parent 9d5a117 commit 3e452c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
31 changes: 24 additions & 7 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_no: Some(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,14 +240,26 @@ pub enum RevertProtection {

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Mined reverted transaction: {0:?}")]
Revert(eth::TxId),
#[error("Mined reverted transaction: {tx_id:?}")]
Revert {
tx_id: eth::TxId,
block_no: Option<BlockNo>,
},
#[error("Simulation started reverting during submission")]
SimulationRevert,
SimulationRevert(Option<BlockNo>),
#[error("Settlement did not get included in time")]
Expired,
#[error("Strategy disabled for this tx")]
Disabled,
#[error("Failed to submit: {0:?}")]
Other(#[from] anyhow::Error),
}

impl Error {
pub fn block_no(&self) -> Option<BlockNo> {
match &self {
Error::Revert { block_no, .. } | Error::SimulationRevert(block_no) => *block_no,
_ => None,
}
}
}
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
3 changes: 2 additions & 1 deletion crates/driver/src/infra/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,14 @@ pub fn mempool_executed(
?err,
%mempool,
?settlement,
block_no=err.block_no(),
"sending transaction via mempool failed",
);
}
}
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 3e452c3

Please sign in to comment.