aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-09-05 11:32:59 +0200
committerJon Atack <jon@atack.com>2021-09-05 17:55:06 +0200
commit350e034e64d175f3db4c85ddca42e76e279912f6 (patch)
tree6f437b6ca8ddf51c01fd2a89cde652d9b7a675ba
parentf4e12fd50c23875f4b5f272c94449eb81de43d5d (diff)
consensus: don't call GetBlockPos in ReadBlockFromDisk without lock
-rw-r--r--src/node/blockstorage.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 90f7ba191d..5ddcf95c84 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -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;
}