diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5601,12 +5601,19 @@ } //! Guess how far we are in the verification process at the given block index +//! require cs_main if pindex has not been validated yet (because nChainTx might +//! be unset) double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex) { if (pindex == nullptr) { return 0.0; } + // This function assumes the lock on cs_main is already held (see the + // above comment). This is a temporary check until PR15997 is backported. + // https://github.com/bitcoin/bitcoin/pull/15997 + AssertLockHeld(cs_main); + int64_t nNow = time(nullptr); double fTxTotal; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1816,15 +1816,10 @@ GuessVerificationProgress(chainParams.TxData(), pindex); dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip); } + double gvp = dProgressStart; while (pindex && !fAbortRescan) { if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) { - double gvp = 0; - { - LOCK(cs_main); - gvp = - GuessVerificationProgress(chainParams.TxData(), pindex); - } ShowProgress( _("Rescanning..."), std::max( @@ -1834,11 +1829,8 @@ } if (GetTime() >= nNow + 60) { nNow = GetTime(); - LOCK(cs_main); - 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, gvp); } CBlock block; @@ -1865,6 +1857,7 @@ { LOCK(cs_main); pindex = chainActive.Next(pindex); + gvp = GuessVerificationProgress(chainParams.TxData(), pindex); if (tip != chainActive.Tip()) { tip = chainActive.Tip(); // in case the tip has changed, update progress max @@ -1876,8 +1869,7 @@ if (pindex && fAbortRescan) { LogPrintf("Rescan aborted at block %d. Progress=%f\n", - pindex->nHeight, - GuessVerificationProgress(chainParams.TxData(), pindex)); + pindex->nHeight, gvp); } // Hide progress dialog in GUI.