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(client): perform re-attempts to clear pending transactions #1533

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Changes from 1 commit
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
23 changes: 18 additions & 5 deletions sn_client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought but I get the feeling we could be extracting important values like this into constants. Then we could move them out and label them so we are more aware of their importance.

https://doc.rust-lang.org/rust-by-example/custom_types/constants.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. Also, this functionality is used a couple of times. Will just extract it out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! 👍

// 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();
Expand Down
Loading