diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index bb79dd471e9..8d502049287 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1884,7 +1884,6 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc WalletLogPrintf("Rescan started from block %s... (%s)\n", start_block.ToString(), fast_rescan_filter ? "fast variant using block filters" : "slow variant inspecting all blocks"); - fAbortRescan = false; ShowProgress(strprintf("[%s] %s", DisplayName(), _("Rescanning…")), 0); // show rescan progress in GUI as dialog or on splashscreen, if rescan required on startup (e.g. due to corruption) uint256 tip_hash = WITH_LOCK(cs_wallet, return GetLastBlockHash()); uint256 end_hash = tip_hash; @@ -2006,10 +2005,10 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc WITH_LOCK(cs_wallet, chain().requestMempoolTransactions(*this)); } ShowProgress(strprintf("[%s] %s", DisplayName(), _("Rescanning…")), 100); // hide progress dialog in GUI - if (block_height && fAbortRescan) { + if (fAbortRescan) { WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", block_height, progress_current); result.status = ScanResult::USER_ABORT; - } else if (block_height && chain().shutdownRequested()) { + } else if (chain().shutdownRequested()) { WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", block_height, progress_current); result.status = ScanResult::USER_ABORT; } else { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 54bc60f5c40..62fba7b4b79 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1103,6 +1103,10 @@ public: if (m_wallet.fScanningWallet.exchange(true)) { return false; } + // Discard any abort request left over from previous reservation, so + // that an abort requested while the reservation is held always applies + // to abort this rescan, even if it arrives before the scan loop starts. + m_wallet.fAbortRescan = false; m_wallet.m_scanning_with_passphrase.exchange(with_passphrase); m_wallet.m_scanning_start = SteadyClock::now(); m_wallet.m_scanning_progress = 0;