Skip to content

Commit 350e034

Browse files
committed
consensus: don't call GetBlockPos in ReadBlockFromDisk without lock
1 parent f4e12fd commit 350e034

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/node/blockstorage.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,14 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P
394394

395395
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
396396
{
397-
FlatFilePos blockPos;
398-
{
399-
LOCK(cs_main);
400-
blockPos = pindex->GetBlockPos();
401-
}
397+
const FlatFilePos block_pos{WITH_LOCK(cs_main, return pindex->GetBlockPos())};
402398

403-
if (!ReadBlockFromDisk(block, blockPos, consensusParams)) {
399+
if (!ReadBlockFromDisk(block, block_pos, consensusParams)) {
404400
return false;
405401
}
406402
if (block.GetHash() != pindex->GetBlockHash()) {
407403
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
408-
pindex->ToString(), pindex->GetBlockPos().ToString());
404+
pindex->ToString(), block_pos.ToString());
409405
}
410406
return true;
411407
}

0 commit comments

Comments
 (0)