feat(lite): add "Redownload blocks" (rescan from lite server) to Settings
Add a maintenance option for the lite wallet to re-download and re-scan every block from the lite server — useful when balances or history look wrong. - LiteWalletController::startRescan() runs the backend `rescan` command (which clears the wallet's synced block cache and re-syncs from its birthday) on a detached thread, reusing the existing sync progress/refresh machinery: it resets syncDone_ so refreshModel() shows progress again and refreshes data on completion. No-op if no wallet is open or a scan is already running. - scanInProgress() exposes the initial-sync-or-rescan state. - Settings (lite, open wallet) gains a "Redownload blocks" button behind a confirmation modal, disabled while a scan is running. i18n strings added. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -605,6 +605,38 @@ void LiteWalletController::startSync()
|
||||
});
|
||||
}
|
||||
|
||||
bool LiteWalletController::startRescan()
|
||||
{
|
||||
if (!walletOpen_.load()) return false;
|
||||
// Refuse if a sync/rescan is already running (would race two scans on the backend wallet lock).
|
||||
if (!syncDone_ || !syncDone_->load()) return false;
|
||||
|
||||
// Reset the done flag so refreshModel() re-enters its "scanning, publish progress only" path
|
||||
// and the UI shows progress again; clearing it BEFORE launching the thread avoids a window
|
||||
// where the worker would query balances mid-rescan.
|
||||
syncDone_->store(false);
|
||||
syncStarted_ = true;
|
||||
liteLog("Block re-download (rescan) started");
|
||||
|
||||
// The previous sync/rescan thread has finished (syncDone_ was true above); detach it before
|
||||
// reassigning syncThread_. Like startSync's thread it captures shared refs (bridge_ + syncDone_),
|
||||
// never `this`, so detaching is safe.
|
||||
if (syncThread_.joinable()) syncThread_.detach();
|
||||
|
||||
auto bridge = bridge_;
|
||||
auto done = syncDone_;
|
||||
syncThread_ = std::thread([bridge, done] {
|
||||
if (bridge) {
|
||||
// `rescan` clears the wallet's synced block cache and re-downloads/re-scans from the
|
||||
// birthday height — a blocking, uninterruptible full scan, same as `sync`.
|
||||
bridge->execute("rescan", "");
|
||||
bridge->execute("save", ""); // backend doesn't auto-save after a rescan
|
||||
}
|
||||
done->store(true);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<LiteWalletAppRefreshModel> LiteWalletController::refreshModel()
|
||||
{
|
||||
if (!walletOpen_.load()) return std::nullopt;
|
||||
|
||||
@@ -220,6 +220,15 @@ public:
|
||||
// op produces a ready wallet; safe to call once.
|
||||
void startSync();
|
||||
|
||||
// Re-download and re-scan every block from the lite server: runs the backend `rescan`
|
||||
// command (which clears the wallet's synced block cache and re-syncs from its birthday
|
||||
// height) on a detached thread, reusing the sync progress + refresh machinery. No-op if no
|
||||
// wallet is open or a scan is already running. True if a rescan was actually started.
|
||||
bool startRescan();
|
||||
|
||||
// True while the initial sync OR a rescan is actively scanning (not yet complete).
|
||||
bool scanInProgress() const { return syncStarted_ && !(syncDone_ && syncDone_->load()); }
|
||||
|
||||
// Generate a new address (shielded if true, else transparent) via the backend. Fast (local
|
||||
// key derivation), safe to call on the UI thread; the next refresh lists the new address.
|
||||
LiteNewAddressResult newAddress(bool shielded);
|
||||
|
||||
Reference in New Issue
Block a user