Skip to content

Commit 16be133

Browse files
committed
Fix rescanblockchain rpc to property report progress
CWallet::ScanForWalletTransactions did not previously take into account pindexStop when calculating progress. Renamed progress vars to progress_*. rescanblockchain is the only rpc that uses this parameter.
1 parent 7eb7076 commit 16be133

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/wallet/wallet.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,23 +1745,27 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
17451745
fAbortRescan = false;
17461746
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
17471747
CBlockIndex* tip = nullptr;
1748-
double dProgressStart;
1749-
double dProgressTip;
1748+
double progress_begin;
1749+
double progress_end;
17501750
{
17511751
LOCK(cs_main);
1752-
tip = chainActive.Tip();
1753-
dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
1754-
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip);
1752+
progress_begin = GuessVerificationProgress(chainParams.TxData(), pindex);
1753+
if (pindexStop == nullptr) {
1754+
tip = chainActive.Tip();
1755+
progress_end = GuessVerificationProgress(chainParams.TxData(), tip);
1756+
} else {
1757+
progress_end = GuessVerificationProgress(chainParams.TxData(), pindexStop);
1758+
}
17551759
}
1756-
double gvp = dProgressStart;
1760+
double progress_current = progress_begin;
17571761
while (pindex && !fAbortRescan && !ShutdownRequested())
17581762
{
1759-
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) {
1760-
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((gvp - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
1763+
if (pindex->nHeight % 100 == 0 && progress_end - progress_begin > 0.0) {
1764+
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
17611765
}
17621766
if (GetTime() >= nNow + 60) {
17631767
nNow = GetTime();
1764-
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, gvp);
1768+
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, progress_current);
17651769
}
17661770

17671771
CBlock block;
@@ -1785,18 +1789,18 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
17851789
{
17861790
LOCK(cs_main);
17871791
pindex = chainActive.Next(pindex);
1788-
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
1789-
if (tip != chainActive.Tip()) {
1792+
progress_current = GuessVerificationProgress(chainParams.TxData(), pindex);
1793+
if (pindexStop == nullptr && tip != chainActive.Tip()) {
17901794
tip = chainActive.Tip();
17911795
// in case the tip has changed, update progress max
1792-
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip);
1796+
progress_end = GuessVerificationProgress(chainParams.TxData(), tip);
17931797
}
17941798
}
17951799
}
17961800
if (pindex && fAbortRescan) {
1797-
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, gvp);
1801+
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, progress_current);
17981802
} else if (pindex && ShutdownRequested()) {
1799-
LogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", pindex->nHeight, gvp);
1803+
LogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", pindex->nHeight, progress_current);
18001804
}
18011805
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
18021806
}

0 commit comments

Comments
 (0)