[wallet] Add support for aborting wallet transaction rescans.
This commit is contained in:
@@ -1758,6 +1758,8 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
CBlockIndex* pindex = pindexStart;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
fAbortRescan = false;
|
||||
fScanningWallet = true;
|
||||
|
||||
// no need to read and scan block, if block was created before
|
||||
// our wallet birthday (as adjusted for block time variability)
|
||||
@@ -1767,7 +1769,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
|
||||
double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false);
|
||||
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false);
|
||||
while (pindex)
|
||||
while (pindex && !fAbortRescan)
|
||||
{
|
||||
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
|
||||
@@ -1785,7 +1787,12 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
|
||||
}
|
||||
}
|
||||
if (pindex && fAbortRescan) {
|
||||
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
|
||||
}
|
||||
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
|
||||
|
||||
fScanningWallet = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ enum WalletFeature
|
||||
FEATURE_WALLETCRYPT = 40000, // wallet encryption
|
||||
FEATURE_COMPRPUBKEY = 60000, // compressed public keys
|
||||
|
||||
FEATURE_HD = 330000, // Hierarchical key derivation after BIP32 (HD Wallet)
|
||||
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
|
||||
FEATURE_HD = 330000, // Hierarchical key derivation after BIP32 (HD Wallet)
|
||||
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
|
||||
};
|
||||
|
||||
/** A key pool entry */
|
||||
@@ -550,6 +550,9 @@ private:
|
||||
class CWallet : public CCryptoKeyStore, public CValidationInterface
|
||||
{
|
||||
private:
|
||||
std::atomic<bool> fAbortRescan;
|
||||
std::atomic<bool> fScanningWallet;
|
||||
|
||||
/**
|
||||
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
||||
* all coins from coinControl are selected; Never select unconfirmed coins
|
||||
@@ -645,6 +648,9 @@ public:
|
||||
nTimeFirstKey = 0;
|
||||
fBroadcastTransactions = false;
|
||||
nConflictsReceived = 0;
|
||||
|
||||
fAbortRescan = false;
|
||||
fScanningWallet = false;
|
||||
}
|
||||
|
||||
std::map<uint256, CWalletTx> mapWallet;
|
||||
@@ -691,6 +697,13 @@ public:
|
||||
void UnlockAllCoins();
|
||||
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
|
||||
|
||||
/*
|
||||
* Rescan abort properties
|
||||
*/
|
||||
void AbortRescan() { fAbortRescan = true; }
|
||||
bool IsAbortingRescan() { return fAbortRescan; }
|
||||
bool IsScanning() { return fScanningWallet; }
|
||||
|
||||
/**
|
||||
* keystore implementation
|
||||
* Generate a new key
|
||||
|
||||
Reference in New Issue
Block a user