mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
consensus: don't call GetBlockPos in ReadBlockFromDisk without lock
This commit is contained in:
parent
f4e12fd50c
commit
350e034e64
1 changed files with 3 additions and 7 deletions
|
@ -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)
|
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
|
||||||
{
|
{
|
||||||
FlatFilePos blockPos;
|
const FlatFilePos block_pos{WITH_LOCK(cs_main, return pindex->GetBlockPos())};
|
||||||
{
|
|
||||||
LOCK(cs_main);
|
|
||||||
blockPos = pindex->GetBlockPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ReadBlockFromDisk(block, blockPos, consensusParams)) {
|
if (!ReadBlockFromDisk(block, block_pos, consensusParams)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (block.GetHash() != pindex->GetBlockHash()) {
|
if (block.GetHash() != pindex->GetBlockHash()) {
|
||||||
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue