From acf14c6d734fc238dc1f44a4b5bab1f3f6411c9b Mon Sep 17 00:00:00 2001 From: Michael Mallan Date: Thu, 31 Oct 2024 13:29:25 +0000 Subject: [PATCH] gui: refresh cache more often while syncing Refresh the cache more often while the wallet has a syncing status of some kind in order to detect sooner that this has finished. This does not cover syncing scenarios that require the first poll to be detected since we don't currently store the required info (the last poll at startup). This should be covered in a follow-up. --- gui/src/app/mod.rs | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs index bf0c4bf7..a09a0a89 100644 --- a/gui/src/app/mod.rs +++ b/gui/src/app/mod.rs @@ -32,6 +32,7 @@ use state::{ CoinsPanel, CreateSpendPanel, Home, PsbtsPanel, ReceivePanel, RecoveryPanel, State, TransactionsPanel, }; +use wallet::{sync_status, SyncStatus}; use crate::{ app::{cache::Cache, error::Error, menu::Menu, wallet::Wallet}, @@ -227,19 +228,35 @@ impl App { pub fn subscription(&self) -> Subscription { Subscription::batch(vec![ time::every(Duration::from_secs( - // LianaLite has no rescan feature, the cache refresh loop is only - // to fetch the new block height tip, which for a synced wallet - // (height > 0) is only used to warn user about recovery availability. - if self.daemon.backend() == DaemonBackend::RemoteBackend - && self.cache.blockheight > 0 - { - 120 - // For the rescan feature, we set a higher frequency of cache refresh - // to give to user an up-to-date view of the rescan progress. - // For a remote backend, we refresh cache more often while height is 0 - // to detect sooner that syncing has finished. - } else { - 10 + // Note that for now we pass `None` for `last_poll_at_startup`, + // which means the `LatestWalletSync` status will not be returned + // unless the last poll is also `None`. + // TODO: Store last poll at startup and use it here. + match sync_status( + self.daemon.backend(), + self.cache.blockheight, + self.cache.sync_progress, + self.cache.last_poll_timestamp, + None, + ) { + SyncStatus::BlockchainSync(_) => 5, // Only applies to local backends + SyncStatus::WalletFullScan + if self.daemon.backend() == DaemonBackend::RemoteBackend => + { + 10 + } // If remote backend, don't ping too often + SyncStatus::WalletFullScan | SyncStatus::LatestWalletSync => 3, + SyncStatus::Synced => { + if self.daemon.backend() == DaemonBackend::RemoteBackend { + // Remote backend has no rescan feature. For a synced wallet, + // cache refresh is only used to warn user about recovery availability. + 120 + } else { + // For the rescan feature, we refresh more often in order + // to give user an up-to-date view of the rescan progress. + 10 + } + } }, )) .map(|_| Message::Tick),