Skip to content

Commit 3773cad

Browse files
jonasschnelliPastaPastaPasta
authored andcommitted
Merge bitcoin#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 bitcoin#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
1 parent e10ab64 commit 3773cad

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/qt/clientmodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ size_t ClientModel::getInstantSentLockCount() const
174174
double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
175175
{
176176
CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn);
177+
LOCK(cs_main);
177178
if (!tip)
178179
{
179-
LOCK(cs_main);
180180
tip = chainActive.Tip();
181181
}
182182
return GuessVerificationProgress(Params().TxData(), tip);

src/validation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4989,6 +4989,7 @@ bool DumpMempool(void)
49894989
}
49904990

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

src/wallet/wallet.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -2065,20 +2065,15 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
20652065
dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
20662066
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip);
20672067
}
2068+
double gvp = dProgressStart;
20682069
while (pindex && !fAbortRescan)
20692070
{
20702071
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) {
2071-
double gvp = 0;
2072-
{
2073-
LOCK(cs_main);
2074-
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
2075-
}
20762072
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((gvp - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
20772073
}
20782074
if (GetTime() >= nNow + 60) {
20792075
nNow = GetTime();
2080-
LOCK(cs_main);
2081-
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
2076+
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, gvp);
20822077
}
20832078

20842079
CBlock block;
@@ -2102,6 +2097,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
21022097
{
21032098
LOCK(cs_main);
21042099
pindex = chainActive.Next(pindex);
2100+
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
21052101
if (tip != chainActive.Tip()) {
21062102
tip = chainActive.Tip();
21072103
// in case the tip has changed, update progress max
@@ -2110,7 +2106,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
21102106
}
21112107
}
21122108
if (pindex && fAbortRescan) {
2113-
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
2109+
LogPrintf("Rescan aborted at block %d. Progress=%f\n", pindex->nHeight, gvp);
21142110
}
21152111
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
21162112
}

0 commit comments

Comments
 (0)