Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timeout for tx confirmation #2098

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "6.5.4"
version = "6.5.5"
edition = "2021"

[dependencies]
Expand Down
32 changes: 27 additions & 5 deletions apps/fortuna/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use {
},
time::{
self,
timeout,
Duration,
},
},
Expand Down Expand Up @@ -421,6 +422,8 @@ pub async fn process_event_with_backoff(
}


const TX_CONFIRMATION_TIMEOUT_SECS: u64 = 30;

/// Process a callback on a chain. It estimates the gas for the reveal with callback and
/// submits the transaction if the gas estimate is below the gas limit.
/// It will return a permanent or transient error depending on the error type and whether
Expand Down Expand Up @@ -501,8 +504,28 @@ pub async fn process_event(
))
})?;

let receipt = pending_tx
.await
let reset_nonce = || {
let nonce_manager = contract.client_ref().inner().inner();
nonce_manager.reset();
};

let pending_receipt = timeout(
Duration::from_secs(TX_CONFIRMATION_TIMEOUT_SECS),
pending_tx,
)
.await
.map_err(|_| {
// Tx can get stuck in mempool without any progress if the nonce is too high
// in this case ethers internal polling will not reduce the number of retries
// and keep retrying indefinitely. So we set a manual timeout here and reset the nonce.
reset_nonce();
backoff::Error::transient(anyhow!(
"Tx stuck in mempool. Resetting nonce. Tx:{:?}",
transaction
))
})?;

let receipt = pending_receipt
.map_err(|e| {
backoff::Error::transient(anyhow!(
"Error waiting for transaction receipt. Tx:{:?} Error:{:?}",
Expand All @@ -513,10 +536,9 @@ pub async fn process_event(
.ok_or_else(|| {
// RPC may not return an error on tx submission if the nonce is too high.
// But we will never get a receipt. So we reset the nonce manager to get the correct nonce.
let nonce_manager = contract.client_ref().inner().inner();
nonce_manager.reset();
reset_nonce();
backoff::Error::transient(anyhow!(
"Can't verify the reveal, probably dropped from mempool Tx:{:?}",
"Can't verify the reveal, probably dropped from mempool. Resetting nonce. Tx:{:?}",
transaction
))
})?;
Expand Down
Loading