Skip to content

Commit

Permalink
fix: timeout pending transaction (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw authored Jun 11, 2024
1 parent feba059 commit 7a2f5a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/eth/relayer/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sqlx::postgres::PgPoolOptions;
use sqlx::PgPool;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
use tokio::time::timeout;
use tokio::time::Instant;
use tracing::Span;

Expand Down Expand Up @@ -142,7 +143,12 @@ impl ExternalRelayer {
let start = Instant::now();
let mut substrate_receipt = substrate_pending_transaction;
loop {
match substrate_receipt.await {
let Ok(receipt) = timeout(Duration::from_secs(30), substrate_receipt).await else {
tracing::error!(?tx_hash, "no receipt returned by substrate for more than 30 seconds, retrying block");
return Err(RelayError::CompareTimeout(anyhow!("no receipt returned by substrate for more than 30 seconds")));
};

match receipt {
Ok(Some(substrate_receipt)) =>
if let Err(compare_error) = substrate_receipt.compare(&stratus_receipt) {
let err_string = compare_error.to_string();
Expand Down
4 changes: 2 additions & 2 deletions src/infra/blockchain_client/pending_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> Future for PendingTransaction<'a> {

fn poll(self: Pin<&mut Self>, ctx: &mut Context) -> Poll<Self::Output> {
let this = self.project();
tracing::debug!(?this.state);
tracing::debug!(?this.state, ?this.retries_remaining);

match this.state {
PendingTxState::InitialDelay(fut) => {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a> Future for PendingTransaction<'a> {
let tx_opt = tx_res.unwrap();

if tx_opt.is_none() {
if *this.retries_remaining == 0 {
if *this.retries_remaining <= 0 {
*this.state = PendingTxState::Completed;
return Poll::Ready(Ok(None));
}
Expand Down

0 comments on commit 7a2f5a4

Please sign in to comment.