Add transaction timeout to agent tx submission (#150)

* Add transaction timeout to agent tx submission

* Remove ReceiptError again
pull/184/head
Nam Chu Hoai 3 years ago committed by GitHub
parent 92d941ee3c
commit 00d292c514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      rust/abacus-core/src/traits/mod.rs
  2. 48
      rust/chains/abacus-ethereum/src/macros.rs

@ -75,6 +75,9 @@ pub enum ChainCommunicationError {
/// Any other error
#[error("{0}")]
CustomError(#[from] Box<dyn StdError + Send + Sync>),
/// A transaction submission timed out
#[error("Transaction submission timed out")]
TransactionTimeout(),
}
impl<M> From<ContractError<M>> for ChainCommunicationError

@ -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())
}
}
}};
}

Loading…
Cancel
Save