From 00d292c514cc4d7d90ee311f6269fa002084a928 Mon Sep 17 00:00:00 2001 From: Nam Chu Hoai Date: Wed, 2 Mar 2022 09:26:55 -0500 Subject: [PATCH] Add transaction timeout to agent tx submission (#150) * Add transaction timeout to agent tx submission * Remove ReceiptError again --- rust/abacus-core/src/traits/mod.rs | 3 ++ rust/chains/abacus-ethereum/src/macros.rs | 48 ++++++++++++++++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/rust/abacus-core/src/traits/mod.rs b/rust/abacus-core/src/traits/mod.rs index 21ed21e60..a3c94e19f 100644 --- a/rust/abacus-core/src/traits/mod.rs +++ b/rust/abacus-core/src/traits/mod.rs @@ -75,6 +75,9 @@ pub enum ChainCommunicationError { /// Any other error #[error("{0}")] CustomError(#[from] Box), + /// A transaction submission timed out + #[error("Transaction submission timed out")] + TransactionTimeout(), } impl From> for ChainCommunicationError diff --git a/rust/chains/abacus-ethereum/src/macros.rs b/rust/chains/abacus-ethereum/src/macros.rs index 752e7ff8e..1b7b3d97f 100644 --- a/rust/chains/abacus-ethereum/src/macros.rs +++ b/rust/chains/abacus-ethereum/src/macros.rs @@ -23,19 +23,47 @@ macro_rules! report_tx { to = ?to, data = %data, tx_hash = ?tx_hash, - "Dispatched tx with tx_hash {:?}", - tx_hash + "Dispatched tx" ); - let result = dispatched - .await? - .ok_or_else(|| abacus_core::ChainCommunicationError::DroppedError(tx_hash))?; - tracing::info!( - "confirmed transaction with tx_hash {:?}", - result.transaction_hash - ); - result + let wrapped_tx_submission = tokio::time::timeout(std::time::Duration::from_secs(300), dispatched); + + match wrapped_tx_submission.await { + Ok(tx_submission) => { + match tx_submission { + Ok(Some(receipt)) => { + tracing::info!( + tx_hash = ?tx_hash, + "confirmed transaction" + ); + + receipt + } + // ethers-rs will return None if it can no longer poll for the tx in the mempool + Ok(None) => { + return Err(abacus_core::ChainCommunicationError::DroppedError(tx_hash)) + } + // Pass through this error + Err(x) => { + tracing::error!( + tx_hash = ?tx_hash, + error = ?x, + "encountered error when waiting for receipt", + ); + return Err(x.into()) + } + } + } + Err(x) => { + tracing::error!( + tx_hash = ?tx_hash, + error = ?x, + "waiting for receipt timed out", + ); + return Err(abacus_core::ChainCommunicationError::TransactionTimeout()) + } + } }}; }