Skip to content

Commit

Permalink
consensus: don't call GetBlockPos in ReadBlockFromDisk without lock
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#22895
Rebased-From: 350e034
  • Loading branch information
jonatack authored and fanquake committed Feb 14, 2022
1 parent aadb682 commit 60c48fb
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,14 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P

bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
{
FlatFilePos blockPos;
{
LOCK(cs_main);
blockPos = pindex->GetBlockPos();
}
const FlatFilePos block_pos{WITH_LOCK(cs_main, return pindex->GetBlockPos())};

if (!ReadBlockFromDisk(block, blockPos, consensusParams)) {
if (!ReadBlockFromDisk(block, block_pos, consensusParams)) {
return false;
}
if (block.GetHash() != pindex->GetBlockHash()) {
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
pindex->ToString(), pindex->GetBlockPos().ToString());
pindex->ToString(), block_pos.ToString());
}
return true;
}
Expand Down

0 comments on commit 60c48fb

Please sign in to comment.