fix(rescan): probe the node's block range off the UI thread

Finding the lowest block a node still has (Settings > Rescan, and the
automatic reconcile after a bootstrap) ran a binary search of about 42
synchronous getblockhash/getblock calls on the UI thread, each waiting
for the RPC connection behind any wallet scan (10-20 s on a big wallet)
and each with a 30 s timeout. The window froze for that long.

It now runs as one task on the wallet RPC worker, bounded to 90 s, and
the answer comes back on the UI thread; meanwhile the dialog shows
"Checking which blocks..." with Rescan disabled. An answer from an
earlier connection counts as "could not tell", and one for an earlier
opening of the dialog is dropped. The search probes block 1 first, so a
full-history node answers in one probe, and it answers "could not tell"
at once while a runtime rescan holds the lane.

Fixed along the way: any probe error (timeout, busy node) read as "block
missing", so a busy node could get a bogus "bootstrapped, rescan from
the tip"; and a non-string getblockhash reply never called back, leaving
the dialog on "Checking..." for good. Only the daemon's "can't read
block" error now counts as missing; anything else means "could not
tell".

User-visible:
- after a bootstrap, a probe that cannot tell is tried up to 6 times,
  30 s apart and only while the node is not busy, then a toast points
  to Settings > Rescan, instead of falling back to the -rescan
  restart, which fails on a bootstrapped node;
- the Settings Rescan dialog warns when the probe could not tell.

Two new strings, translated into all eight languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 21:09:48 -05:00
co-authored by Claude Opus 5.5
parent ad0f60a747
commit 2618744e59
16 changed files with 275 additions and 32 deletions
+25 -6
View File
@@ -1456,17 +1456,36 @@ void App::update()
// is rejected. The -rescan restart can't do it (the snapshot lacks pre-snapshot blocks), so we
// detect the lowest available block height and run a runtime rescanblockchain from there. Wait
// until the daemon is connected and out of warmup so the probe and rescan can actually run.
if (post_bootstrap_rescan_pending_ && rpcConnected && state_.connected &&
if (post_bootstrap_rescan_pending_ && !post_bootstrap_probe_in_flight_ &&
std::chrono::steady_clock::now() >= post_bootstrap_probe_retry_at_ &&
rpcConnected && state_.connected && !rpcBusy &&
!state_.warming_up && !state_.isLocked() && !state_.sync.rescanning &&
!runtime_rescan_active_ && !bootstrap_downloading_ &&
state_.sync.blocks > 1) { // wait until the tip is known so the probe has a real range
post_bootstrap_rescan_pending_ = false;
ui::Notifications::instance().info(TR("appx_bootstrap_complete_reconciling"));
if (post_bootstrap_probe_attempts_ == 0)
ui::Notifications::instance().info(TR("appx_bootstrap_complete_reconciling"));
++post_bootstrap_probe_attempts_;
post_bootstrap_probe_in_flight_ = true;
// Asynchronous (worker_): the callback runs on the UI thread a few frames later.
detectLowestAvailableBlockHeight([this](bool ok, int lowest, bool fullHistory) {
if (ok && !fullHistory) {
runtimeRescan(lowest); // bootstrapped/pruned: rescan from the snapshot base
post_bootstrap_probe_in_flight_ = false;
if (shutting_down_ || !post_bootstrap_rescan_pending_) return;
if (ok) {
post_bootstrap_rescan_pending_ = false;
post_bootstrap_probe_attempts_ = 0;
if (!fullHistory) {
runtimeRescan(lowest); // bootstrapped/pruned: rescan from the snapshot base
} else {
rescanBlockchain(); // full-history node: the -rescan restart works
}
} else if (post_bootstrap_probe_attempts_ < 6) {
// Could not tell (busy node, a timeout, a reconnect). NOT the -rescan restart: on a bootstrapped
// node it fails. Keep the reconcile armed and probe again in 30 s.
post_bootstrap_probe_retry_at_ = std::chrono::steady_clock::now() + std::chrono::seconds(30);
} else {
rescanBlockchain(); // full-history node (or probe failed): -rescan restart works
post_bootstrap_rescan_pending_ = false;
post_bootstrap_probe_attempts_ = 0;
ui::Notifications::instance().warning(TR("appx_bootstrap_reconcile_probe_failed"));
}
});
}