From e6660b4677a933780134ed1f4d78b3232df25f47 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Thu, 28 Mar 2024 23:54:42 +0530 Subject: [PATCH] fix(client): perform re-attempts to clear pending transactions --- sn_client/src/wallet.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/sn_client/src/wallet.rs b/sn_client/src/wallet.rs index 7d4df079f9..e4443e8c58 100644 --- a/sn_client/src/wallet.rs +++ b/sn_client/src/wallet.rs @@ -704,14 +704,27 @@ impl WalletClient { ) -> WalletResult<(NanoTokens, NanoTokens)> { // Before wallet progress, there shall be no `unconfirmed_spend_requests` // Here, just re-upload again. The caller shall carry out a re-try later on. - if self.wallet.unconfirmed_spend_requests_exist() { - info!("Pre-Unconfirmed transactions exist. Resending in 1 second..."); + let mut did_error = false; + // Wallet shall be all clear to progress forward. + let mut attempts = 0; + while self.wallet.unconfirmed_spend_requests_exist() { + info!("Pre-Unconfirmed transactions exist, sending again after 1 second..."); sleep(Duration::from_secs(1)).await; self.resend_pending_transactions(verify_store).await; - return Err(WalletError::CouldNotSendMoney( - "Wallet has pre-unconfirmed transactions. Resend, and try again.".to_string(), - )); + if attempts > 10 { + // save the error state, but break out of the loop so we can save + did_error = true; + break; + } + + attempts += 1; + } + + if did_error { + error!("Wallet has pre-unconfirmed transactions, can't progress further."); + println!("Wallet has pre-unconfirmed transactions, can't progress further."); + return Err(WalletError::UnconfirmedTxAfterRetries); } let start = Instant::now();