[wallet] Add support for aborting wallet transaction rescans.
This commit is contained in:
parent
b7365f0545
commit
75a08e7d17
2 changed files with 19 additions and 1 deletions
|
@ -1527,6 +1527,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
|
||||||
CBlockIndex* pindex = pindexStart;
|
CBlockIndex* pindex = pindexStart;
|
||||||
{
|
{
|
||||||
LOCK2(cs_main, cs_wallet);
|
LOCK2(cs_main, cs_wallet);
|
||||||
|
fAbortRescan = false;
|
||||||
|
fScanningWallet = true;
|
||||||
|
|
||||||
// no need to read and scan block, if block was created before
|
// no need to read and scan block, if block was created before
|
||||||
// our wallet birthday (as adjusted for block time variability)
|
// our wallet birthday (as adjusted for block time variability)
|
||||||
|
@ -1536,7 +1538,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
|
||||||
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
|
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
|
||||||
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
|
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
|
||||||
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
|
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
|
||||||
while (pindex)
|
while (pindex && !fAbortRescan)
|
||||||
{
|
{
|
||||||
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||||
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), pindex) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
|
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
|
||||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
|
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pindex && fAbortRescan) {
|
||||||
|
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
|
||||||
|
}
|
||||||
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
|
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
|
||||||
|
|
||||||
|
fScanningWallet = false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,6 +651,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::atomic<bool> fFlushScheduled;
|
static std::atomic<bool> fFlushScheduled;
|
||||||
|
std::atomic<bool> fAbortRescan;
|
||||||
|
std::atomic<bool> fScanningWallet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
||||||
|
@ -775,6 +777,8 @@ public:
|
||||||
nTimeFirstKey = 0;
|
nTimeFirstKey = 0;
|
||||||
fBroadcastTransactions = false;
|
fBroadcastTransactions = false;
|
||||||
nRelockTime = 0;
|
nRelockTime = 0;
|
||||||
|
fAbortRescan = false;
|
||||||
|
fScanningWallet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<uint256, CWalletTx> mapWallet;
|
std::map<uint256, CWalletTx> mapWallet;
|
||||||
|
@ -819,6 +823,13 @@ public:
|
||||||
void UnlockAllCoins();
|
void UnlockAllCoins();
|
||||||
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
|
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rescan abort properties
|
||||||
|
*/
|
||||||
|
void AbortRescan() { fAbortRescan = true; }
|
||||||
|
bool IsAbortingRescan() { return fAbortRescan; }
|
||||||
|
bool IsScanning() { return fScanningWallet; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* keystore implementation
|
* keystore implementation
|
||||||
* Generate a new key
|
* Generate a new key
|
||||||
|
|
Loading…
Reference in a new issue