Merge #13079: Fix rescanblockchain rpc to properly report progress

16be13345 Fix rescanblockchain rpc to property report progress (Ben Woosley)

Pull request description:

  Previously it assumed tip in all cases. This also extracts a RescanVerificationProgress helper object whose role is to manage reporting, in order to simplify ScanForWalletTransactions - more lines in total, but much simpler to follow the core logic.

Tree-SHA512: 5ebed0c56fae4ccfe613ff1d7082cb6da5a86635a8993ed3af70b500a4ea43074121aea9219b2f0321fbfeb7efcb964bdc2199297a64ca0fa85d9d07aa637d40
This commit is contained in:
Jonas Schnelli 2018-05-07 15:03:28 +02:00
commit 5778d44aa8
No known key found for this signature in database
GPG key ID: 1EB776BB03C7922D

View file

@ -1745,23 +1745,27 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
fAbortRescan = false; fAbortRescan = false;
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
CBlockIndex* tip = nullptr; CBlockIndex* tip = nullptr;
double dProgressStart; double progress_begin;
double dProgressTip; double progress_end;
{ {
LOCK(cs_main); LOCK(cs_main);
tip = chainActive.Tip(); progress_begin = GuessVerificationProgress(chainParams.TxData(), pindex);
dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex); if (pindexStop == nullptr) {
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip); tip = chainActive.Tip();
progress_end = GuessVerificationProgress(chainParams.TxData(), tip);
} else {
progress_end = GuessVerificationProgress(chainParams.TxData(), pindexStop);
}
} }
double gvp = dProgressStart; double progress_current = progress_begin;
while (pindex && !fAbortRescan && !ShutdownRequested()) while (pindex && !fAbortRescan && !ShutdownRequested())
{ {
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) { if (pindex->nHeight % 100 == 0 && progress_end - progress_begin > 0.0) {
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((gvp - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
} }
if (GetTime() >= nNow + 60) { if (GetTime() >= nNow + 60) {
nNow = GetTime(); nNow = GetTime();
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, gvp); LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, progress_current);
} }
CBlock block; CBlock block;
@ -1785,18 +1789,18 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
{ {
LOCK(cs_main); LOCK(cs_main);
pindex = chainActive.Next(pindex); pindex = chainActive.Next(pindex);
gvp = GuessVerificationProgress(chainParams.TxData(), pindex); progress_current = GuessVerificationProgress(chainParams.TxData(), pindex);
if (tip != chainActive.Tip()) { if (pindexStop == nullptr && tip != chainActive.Tip()) {
tip = chainActive.Tip(); tip = chainActive.Tip();
// in case the tip has changed, update progress max // in case the tip has changed, update progress max
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip); progress_end = GuessVerificationProgress(chainParams.TxData(), tip);
} }
} }
} }
if (pindex && fAbortRescan) { if (pindex && fAbortRescan) {
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, gvp); LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, progress_current);
} else if (pindex && ShutdownRequested()) { } else if (pindex && ShutdownRequested()) {
LogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", pindex->nHeight, gvp); LogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", pindex->nHeight, progress_current);
} }
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
} }