Skip to content

Commit f773203

Browse files
jonasschnellirandom-zebra
authored andcommitted
Reduce cs_main lock in ReadBlockFromDisk, only read GetBlockPos under
the lock
1 parent 3e01665 commit f773203

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/validation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,10 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
820820

821821
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
822822
{
823-
if (!ReadBlockFromDisk(block, pindex->GetBlockPos()))
823+
CDiskBlockPos blockPos = WITH_LOCK(cs_main, return pindex->GetBlockPos(); );
824+
if (!ReadBlockFromDisk(block, blockPos)) {
824825
return false;
826+
}
825827
if (block.GetHash() != pindex->GetBlockHash()) {
826828
LogPrintf("%s : block=%s index=%s\n", __func__, block.GetHash().GetHex(), pindex->GetBlockHash().GetHex());
827829
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*) : GetHash() doesn't match index");

src/wallet/wallet.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,8 +1905,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
19051905
}
19061906

19071907
CBlock block;
1908-
bool readRet = WITH_LOCK(cs_main, return ReadBlockFromDisk(block, pindex); );
1909-
if (readRet) {
1908+
if (ReadBlockFromDisk(block, pindex)) {
19101909
LOCK2(cs_main, cs_wallet);
19111910
if (pindex && !chainActive.Contains(pindex)) {
19121911
// Abort scan if current block is no longer active, to prevent

0 commit comments

Comments
 (0)