Skip to content

Commit

Permalink
[EASY] Improve settlement tx cancellation logging (#3165)
Browse files Browse the repository at this point in the history
# Description
ATM, it is not possible to understand whether a settlement cancellation
tx succeeded. This PR adds logs with the cancellation tx hash, so it
will be possible to check the transaction on chain later. Also,
additional context is added when working with the cancellation tx
submission since, currently, it is impossible to distinguish between the
actual settlement tx submission error.
  • Loading branch information
squadgazzz authored Dec 17, 2024
1 parent 6fe5635 commit 53ec067
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ use {
eth,
},
crate::{
domain::{competition::solution::Settlement, eth::TxStatus, BlockNo},
domain::{
competition::solution::Settlement,
eth::{TxId, TxStatus},
BlockNo,
},
infra::{self, observe, solver::Solver, Ethereum},
},
anyhow::Context,
ethrpc::block_stream::into_stream,
futures::{future::select_ok, FutureExt, StreamExt},
thiserror::Error,
Expand Down Expand Up @@ -123,24 +128,32 @@ impl Mempools {
TxStatus::Pending => {
// Check if the current block reached the submission deadline block number
if block.number >= submission_deadline {
let cancellation_tx_hash = self
.cancel(mempool, settlement.gas.price, solver)
.await
.context("cancellation tx due to deadline failed")?;
tracing::info!(
?hash,
settle_tx_hash = ?hash,
deadline = submission_deadline,
current_block = block.number,
?cancellation_tx_hash,
"tx not confirmed in time, cancelling",
);
self.cancel(mempool, settlement.gas.price, solver).await?;
return Err(Error::Expired);
}
// Check if transaction still simulates
if let Err(err) = self.ethereum.estimate_gas(tx).await {
if err.is_revert() {
let cancellation_tx_hash = self
.cancel(mempool, settlement.gas.price, solver)
.await
.context("cancellation tx due to revert failed")?;
tracing::info!(
?hash,
settle_tx_hash = ?hash,
?cancellation_tx_hash,
?err,
"tx started failing in mempool, cancelling"
);
self.cancel(mempool, settlement.gas.price, solver).await?;
return Err(Error::SimulationRevert);
} else {
tracing::warn!(?hash, ?err, "couldn't re-simulate tx");
Expand Down Expand Up @@ -173,7 +186,7 @@ impl Mempools {
mempool: &infra::mempool::Mempool,
pending: eth::GasPrice,
solver: &Solver,
) -> Result<(), Error> {
) -> Result<TxId, Error> {
let cancellation = eth::Tx {
from: solver.address(),
to: solver.address(),
Expand All @@ -186,8 +199,7 @@ impl Mempools {
limit: CANCELLATION_GAS_AMOUNT.into(),
price: pending * GAS_PRICE_BUMP,
};
mempool.submit(cancellation, gas, solver).await?;
Ok(())
mempool.submit(cancellation, gas, solver).await
}
}

Expand Down

0 comments on commit 53ec067

Please sign in to comment.