I think it should work "for now" because we should not be able to call abortrescan rpc if there's no rescan running.
But if some function calls wallet::abortrescan() we would have the problem of never starting the rescan in a future rescan call.
You can easily test this with the test added in this PR, which will fail, and the change:
$ git diff
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 8d50204928..cd16d0b5b6 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2008,6 +2008,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
if (fAbortRescan) {
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", block_height, progress_current);
result.status = ScanResult::USER_ABORT;
+ fAbortRescan = false;
} 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;
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 62fba7b4b7..db83269d44 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -1106,7 +1106,6 @@ public:
// 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;
I think the current approach of cleaning the value at the very beginning of a rescan is a cleaner approach and safer.