diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 9405f68c6cf..0e4c13debbc 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -411,7 +411,7 @@ public: void UnlinkPrunedFiles(const std::set& setFilesToPrune) const; /** Functions for disk access for blocks */ - bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional& expected_hash = {}) const; + bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional& expected_hash) const; bool ReadBlock(CBlock& block, const CBlockIndex& index) const; bool ReadRawBlock(std::vector& block, const FlatFilePos& pos) const; diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp index d1c64e786dc..d3b58143719 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -190,12 +190,12 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) BOOST_CHECK_EQUAL(read_block.nVersion, 0); { ASSERT_DEBUG_LOG("Errors in block header"); - BOOST_CHECK(!blockman.ReadBlock(read_block, pos1)); + BOOST_CHECK(!blockman.ReadBlock(read_block, pos1, {})); BOOST_CHECK_EQUAL(read_block.nVersion, 1); } { ASSERT_DEBUG_LOG("Errors in block header"); - BOOST_CHECK(!blockman.ReadBlock(read_block, pos2)); + BOOST_CHECK(!blockman.ReadBlock(read_block, pos2, {})); BOOST_CHECK_EQUAL(read_block.nVersion, 2); } @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) BOOST_CHECK_EQUAL(blockman.CalculateCurrentUsage(), (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2); // Block 2 was not overwritten: - blockman.ReadBlock(read_block, pos2); + BOOST_CHECK(!blockman.ReadBlock(read_block, pos2, {})); BOOST_CHECK_EQUAL(read_block.nVersion, 2); } diff --git a/src/validation.cpp b/src/validation.cpp index 18c775a9db9..35f66271c45 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5168,14 +5168,14 @@ void ChainstateManager::LoadExternalBlockFile( while (range.first != range.second) { std::multimap::iterator it = range.first; std::shared_ptr pblockrecursive = std::make_shared(); - if (m_blockman.ReadBlock(*pblockrecursive, it->second)) { - LogDebug(BCLog::REINDEX, "%s: Processing out of order child %s of %s\n", __func__, pblockrecursive->GetHash().ToString(), - head.ToString()); + if (m_blockman.ReadBlock(*pblockrecursive, it->second, {})) { + const auto& block_hash{pblockrecursive->GetHash()}; + LogDebug(BCLog::REINDEX, "%s: Processing out of order child %s of %s", __func__, block_hash.ToString(), head.ToString()); LOCK(cs_main); BlockValidationState dummy; if (AcceptBlock(pblockrecursive, dummy, nullptr, true, &it->second, nullptr, true)) { nLoaded++; - queue.push_back(pblockrecursive->GetHash()); + queue.push_back(block_hash); } } range.first++;