Skip to content

Commit bf3353d

Browse files
committed
Merge #12287: Optimise lock behaviour for GuessVerificationProgress()
90ba2df Fix missing cs_main lock for GuessVerificationProgress() (Jonas Schnelli) Pull request description: `GuessVerificationProgress()` needs `cs_main` due to accessing the `pindex->nChainTx`. This adds a `AssertLockHeld` in `GuessVerificationProgress()` and adds the missing locks in... * `LoadChainTip()` * `ScanForWalletTransactions()` (got missed in #11281) * GUI, `ClientModel::getVerificationProgress()` <--- **this may have GUI performance impacts**, but could be relaxed later with a cache or something more efficient. Tree-SHA512: 13302946571422375f32af8e396b9d2c1180f2693ea363aeba9e98c8266ddec64fe7862bfdcbb5a93a4b12165a61eec1e51e4e7d7a8515fa50879095dc163412
2 parents 07090c5 + 90ba2df commit bf3353d

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ size_t ClientModel::getMempoolDynamicUsage() const
138138
double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
139139
{
140140
CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn);
141+
LOCK(cs_main);
141142
if (!tip)
142143
{
143-
LOCK(cs_main);
144144
tip = chainActive.Tip();
145145
}
146146
return GuessVerificationProgress(Params().TxData(), tip);

src/validation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4658,6 +4658,7 @@ bool DumpMempool(void)
46584658
}
46594659

46604660
//! Guess how far we are in the verification process at the given block index
4661+
//! require cs_main if pindex has not been validated yet (because nChainTx might be unset)
46614662
double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pindex) {
46624663
if (pindex == nullptr)
46634664
return 0.0;

src/wallet/wallet.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,20 +1668,15 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
16681668
dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
16691669
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip);
16701670
}
1671+
double gvp = dProgressStart;
16711672
while (pindex && !fAbortRescan)
16721673
{
16731674
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) {
1674-
double gvp = 0;
1675-
{
1676-
LOCK(cs_main);
1677-
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
1678-
}
16791675
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((gvp - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
16801676
}
16811677
if (GetTime() >= nNow + 60) {
16821678
nNow = GetTime();
1683-
LOCK(cs_main);
1684-
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
1679+
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, gvp);
16851680
}
16861681

16871682
CBlock block;
@@ -1705,6 +1700,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
17051700
{
17061701
LOCK(cs_main);
17071702
pindex = chainActive.Next(pindex);
1703+
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
17081704
if (tip != chainActive.Tip()) {
17091705
tip = chainActive.Tip();
17101706
// in case the tip has changed, update progress max
@@ -1713,7 +1709,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
17131709
}
17141710
}
17151711
if (pindex && fAbortRescan) {
1716-
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
1712+
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, gvp);
17171713
}
17181714
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
17191715
}

0 commit comments

Comments
 (0)