From 7febe4f3c7f482390c4aa6fc528e2ee3fb34b142 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 5 Sep 2021 11:32:59 +0200 Subject: consensus: don't call GetBlockPos in ReadBlockFromDisk without lock Github-Pull: #22895 Rebased-From: 350e034e64d175f3db4c85ddca42e76e279912f6 --- src/node/blockstorage.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 0083b74b33..b64fc8d944 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; } -- cgit v1.2.3