Fix bug in getrescaninfo

There was a small bug in getrescaninfo where when a rescan first starts, it
shows rescanning=true but progress=100% because rescanHeight was not initialized
correctly.

Also update our rescanHeight while we are fast-forwarding thru blocks which are
before the current wallet birthday.
This commit is contained in:
Duke Leto
2022-10-28 17:06:58 -04:00
parent 29ec7b5fb6
commit c36464ee1b

View File

@@ -2763,13 +2763,16 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
pwalletMain->fRescanning = true;
CBlockIndex* pindex = pindexStart;
pwalletMain->rescanStartHeight = pindex->GetHeight();
pwalletMain->rescanHeight = pwalletMain->rescanStartHeight;
{
LOCK2(cs_main, cs_wallet);
// no need to read and scan block, if block was created before
// our wallet birthday (as adjusted for block time variability)
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200)))
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200))) {
pindex = chainActive.Next(pindex);
pwalletMain->rescanHeight = pindex->GetHeight();
}
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);
@@ -2777,7 +2780,6 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
while (pindex)
{
pwalletMain->rescanHeight = pindex->GetHeight();
if (pindex->GetHeight() % 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))));
@@ -2821,6 +2823,8 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
nNow = GetTime();
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->GetHeight(), Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
}
// update rescan height before we scan the next block
pwalletMain->rescanHeight = pindex->GetHeight();
pindex = chainActive.Next(pindex);
}