Skip to content

Commit 75a08e7

Browse files
committed
[wallet] Add support for aborting wallet transaction rescans.
1 parent b7365f0 commit 75a08e7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
15271527
CBlockIndex* pindex = pindexStart;
15281528
{
15291529
LOCK2(cs_main, cs_wallet);
1530+
fAbortRescan = false;
1531+
fScanningWallet = true;
15301532

15311533
// no need to read and scan block, if block was created before
15321534
// our wallet birthday (as adjusted for block time variability)
@@ -1536,7 +1538,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
15361538
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
15371539
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
15381540
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
1539-
while (pindex)
1541+
while (pindex && !fAbortRescan)
15401542
{
15411543
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
15421544
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), pindex) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
@@ -1558,7 +1560,12 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
15581560
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
15591561
}
15601562
}
1563+
if (pindex && fAbortRescan) {
1564+
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
1565+
}
15611566
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
1567+
1568+
fScanningWallet = false;
15621569
}
15631570
return ret;
15641571
}

src/wallet/wallet.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
651651
{
652652
private:
653653
static std::atomic<bool> fFlushScheduled;
654+
std::atomic<bool> fAbortRescan;
655+
std::atomic<bool> fScanningWallet;
654656

655657
/**
656658
* Select a set of coins such that nValueRet >= nTargetValue and at least
@@ -775,6 +777,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
775777
nTimeFirstKey = 0;
776778
fBroadcastTransactions = false;
777779
nRelockTime = 0;
780+
fAbortRescan = false;
781+
fScanningWallet = false;
778782
}
779783

780784
std::map<uint256, CWalletTx> mapWallet;
@@ -819,6 +823,13 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
819823
void UnlockAllCoins();
820824
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
821825

826+
/*
827+
* Rescan abort properties
828+
*/
829+
void AbortRescan() { fAbortRescan = true; }
830+
bool IsAbortingRescan() { return fAbortRescan; }
831+
bool IsScanning() { return fScanningWallet; }
832+
822833
/**
823834
* keystore implementation
824835
* Generate a new key

0 commit comments

Comments
 (0)