wallet: delay for sync attempt

This commit is contained in:
ardocrat 2024-04-25 15:18:48 +03:00
parent fc60d907d2
commit 5cf283696e

View file

@ -790,6 +790,9 @@ impl Wallet {
/// Delay in seconds to sync [`WalletData`] (60 seconds as average block time). /// Delay in seconds to sync [`WalletData`] (60 seconds as average block time).
const SYNC_DELAY: Duration = Duration::from_millis(60 * 1000); const SYNC_DELAY: Duration = Duration::from_millis(60 * 1000);
/// Delay in seconds for sync thread to wait before start of new attempt.
const ATTEMPT_DELAY: Duration = Duration::from_millis(3 * 1000);
/// Number of attempts to sync [`WalletData`] before setting an error. /// Number of attempts to sync [`WalletData`] before setting an error.
const SYNC_ATTEMPTS: u8 = 10; const SYNC_ATTEMPTS: u8 = 10;
@ -836,7 +839,7 @@ fn start_sync(mut wallet: Wallet) -> Thread {
// Skip cycle when node sync is not finished. // Skip cycle when node sync is not finished.
if !Node::is_running() || Node::get_sync_status() != Some(SyncStatus::NoSync) { if !Node::is_running() || Node::get_sync_status() != Some(SyncStatus::NoSync) {
println!("integrated node wait"); println!("integrated node wait");
thread::park_timeout(Duration::from_millis(1000)); thread::park_timeout(ATTEMPT_DELAY);
continue; continue;
} }
} }
@ -878,10 +881,10 @@ fn start_sync(mut wallet: Wallet) -> Thread {
return; return;
} }
// Repeat after default delay or after 1 second if sync was not success. // Repeat after default or attempt delay if synchronization was not successful.
let delay = if wallet.sync_error() let delay = if wallet.sync_error()
|| wallet.get_sync_attempts() != 0 { || wallet.get_sync_attempts() != 0 {
Duration::from_millis(1000) ATTEMPT_DELAY
} else { } else {
SYNC_DELAY SYNC_DELAY
}; };