Skip to content

Commit cf3f9ae

Browse files
committed
fix logic of last seen challenge id
1 parent ef3c1fa commit cf3f9ae

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/main.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,32 +494,47 @@ fn run_app(cli: Cli) -> Result<(), String> {
494494
println!("Donation Target: {}", cli.donate_to.as_ref().unwrap());
495495
}
496496

497+
let mut last_seen_challenge_id = String::new();
498+
497499
// Outer Polling loop (robustly checks for challenge changes)
498500
loop {
499501
backoff_challenge.reset();
500502

501-
let old_challenge_id = current_challenge_id.clone();
503+
let old_challenge_id = last_seen_challenge_id.clone();
502504

503505
// In this mode, we never want to wait for a new challenge,
504506
// which is exactly the point of increasing the wallet derivation path index.
505507
current_challenge_id.clear();
506508

507509
// Get challenge parameters (fixed or dynamic)
508510
let challenge_params = match get_challenge_params(&client, &api_url, cli_challenge_ref, &mut current_challenge_id) {
509-
Ok(Some(params)) => params,
510-
Ok(None) => continue, // Continue polling after sleep/wait
511+
Ok(Some(params)) => {
512+
backoff_challenge.reset();
513+
514+
// Reset index only if we saw a new challenge
515+
if cli_challenge_ref.is_none() && params.challenge_id != old_challenge_id {
516+
wallet_deriv_index = 0;
517+
}
518+
519+
// Update last seen only on success
520+
last_seen_challenge_id = params.challenge_id.clone();
521+
522+
params
523+
},
524+
Ok(None) => {
525+
// Nothing new; count as success for backoff purposes
526+
backoff_challenge.reset();
527+
528+
// Continue polling after sleep/wait
529+
continue;
530+
},
511531
Err(e) => {
512532
eprintln!("⚠️ Critical API Error during challenge polling: {}. Retrying with exponential backoff...", e);
513533
backoff_challenge.sleep();
514534
continue;
515535
}
516536
};
517537

518-
// Reset index only if a *new* challenge ID is detected from the API poll (not in fixed mode)
519-
if cli_challenge_ref.is_none() && challenge_params.challenge_id != old_challenge_id {
520-
wallet_deriv_index = 0;
521-
}
522-
523538
// 1. Generate New Key Pair using Mnemonic and Index
524539
let key_pair = cardano::derive_key_pair_from_mnemonic(&mnemonic_phrase, cli.mnemonic_account, wallet_deriv_index);
525540
let mining_address = key_pair.2.to_bech32().unwrap();

0 commit comments

Comments
 (0)