From c36464ee1b7de6e1873bbd63810005ea3f032c8a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 28 Oct 2022 17:06:58 -0400 Subject: [PATCH] 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. --- src/wallet/wallet.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9e8cd1aa4..bc2d75752 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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); }