-zapwallettxes erases every wallet transaction but leaves the best-block locator at the old tip.
The forced rescan that follows starts at genesis, and ScanForWalletTransactions only ever moves the
locator forward, so when that rescan was cut short -- killed, or a clean shutdown -- the next normal
start read the old locator, skipped the rescan, and the wallet came up without the erased
transactions: zero balance and no notes until someone ran -rescan. Plain -rescan had the same gap.
- Before a forced rescan that starts below the locator on disk, move the locator back to where the
scan starts (RewindWalletLocatorForRescan). An interrupted scan then checkpoints forward from
there, and a killed one restarts from there. With -zapwallettxes this is done right after the
zap, so a startup that fails in between (a config error, say) cannot reopen the gap.
- SetBestChainWith no longer stamps the chain tip while the startup rescan is running or was cut
short and init has not seeded the wallet tip yet. That stamp comes from FlushStateToDisk (its
hourly write, or the one in Shutdown) and would overwrite the scan's own locator the same way.
Regtest, dev vs this branch on the same fixture (141 blocks, 26 notes, 146 txs, 430.0496418 DRGX),
stopping the node under gdb as the zap rescan begins and then starting it normally: dev comes up
empty (0 balance, 0 notes, 0 txs) after both SIGKILL and SIGTERM; this branch resumes the rescan
from block 0 and restores exactly the baseline. New gtest
WalletShutdownSave.DoesNotStampTheChainTipOverAnIncompleteStartupRescan.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>