Skip to content

Commit ccd8ef6

Browse files
committed
Reduce cs_main lock in ReadBlockFromDisk, only read GetBlockPos under the lock
1 parent bc356b4 commit ccd8ef6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/validation.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,13 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
11211121

11221122
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
11231123
{
1124-
if (!ReadBlockFromDisk(block, pindex->GetBlockPos(), consensusParams))
1124+
CDiskBlockPos blockPos;
1125+
{
1126+
LOCK(cs_main);
1127+
blockPos = pindex->GetBlockPos();
1128+
}
1129+
1130+
if (!ReadBlockFromDisk(block, blockPos, consensusParams))
11251131
return false;
11261132
if (block.GetHash() != pindex->GetBlockHash())
11271133
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",

src/wallet/wallet.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,13 +1689,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
16891689
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
16901690
}
16911691

1692-
bool readRet = false;
16931692
CBlock block;
1694-
{
1695-
LOCK(cs_main);
1696-
readRet = ReadBlockFromDisk(block, pindex, Params().GetConsensus());
1697-
}
1698-
if (readRet) {
1693+
if (ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
16991694
LOCK2(cs_main, cs_wallet);
17001695
if (pindex && !chainActive.Contains(pindex)) {
17011696
// Abort scan if current block is no longer active, to prevent

0 commit comments

Comments
 (0)