Skip to content

Commit

Permalink
fix: err with retries
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Jan 8, 2025
1 parent ad09bbe commit 8fd0547
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions crates/script/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub async fn check_tx_status(
return Ok(receipt.into());
}

let mut retries = 0;

loop {
match PendingTransactionBuilder::new(provider.clone(), hash)
.with_timeout(Some(Duration::from_secs(timeout)))
Expand All @@ -47,20 +49,23 @@ pub async fn check_tx_status(
{
Ok(receipt) => return Ok(receipt.into()),
// do nothing on timeout, we will check whether tx is dropped below
Err(PendingTransactionError::TxWatcher(WatchTxError::Timeout)) => {}
// treat other errors as fatal
Err(e) => return Err(e.into()),
}

if provider.get_transaction_by_hash(hash).await?.is_some() {
trace!("tx is still known to the node, waiting for receipt");
} else {
trace!("eth_getTransactionByHash returned null, assuming dropped");
break
Err(PendingTransactionError::TxWatcher(WatchTxError::Timeout)) => {
if provider.get_transaction_by_hash(hash).await?.is_some() {
trace!("tx is still known to the node, waiting for receipt");
} else {
trace!("eth_getTransactionByHash returned null, assuming dropped");
return Ok(TxStatus::Dropped)
}
}
// treat other errors as fatal, with retries
Err(e) => {
if retries == 3 {
return Err(e.into())
}
retries += 1;
}
}
}

Ok(TxStatus::Dropped)
}
.await;

Expand Down

0 comments on commit 8fd0547

Please sign in to comment.