Skip to content

Commit 9341b53

Browse files
committed
blockstorage: make block read hash checks explicit
Dropped the default expected_hash parameter from `ReadBlock()`. In `blockmanager_flush_block_file` tests, we pass {} since the tests would already fail at PoW validation for corrupted blocks. In `ChainstateManager::LoadExternalBlockFile`, we pass {} when processing child blocks because their hashes aren't known beforehand.
1 parent 2371b9f commit 9341b53

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/node/blockstorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class BlockManager
411411
void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune) const;
412412

413413
/** Functions for disk access for blocks */
414-
bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional<uint256>& expected_hash = {}) const;
414+
bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional<uint256>& expected_hash) const;
415415
bool ReadBlock(CBlock& block, const CBlockIndex& index) const;
416416
bool ReadRawBlock(std::vector<uint8_t>& block, const FlatFilePos& pos) const;
417417

src/test/blockmanager_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
190190
BOOST_CHECK_EQUAL(read_block.nVersion, 0);
191191
{
192192
ASSERT_DEBUG_LOG("Errors in block header");
193-
BOOST_CHECK(!blockman.ReadBlock(read_block, pos1));
193+
BOOST_CHECK(!blockman.ReadBlock(read_block, pos1, {}));
194194
BOOST_CHECK_EQUAL(read_block.nVersion, 1);
195195
}
196196
{
197197
ASSERT_DEBUG_LOG("Errors in block header");
198-
BOOST_CHECK(!blockman.ReadBlock(read_block, pos2));
198+
BOOST_CHECK(!blockman.ReadBlock(read_block, pos2, {}));
199199
BOOST_CHECK_EQUAL(read_block.nVersion, 2);
200200
}
201201

@@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
212212
BOOST_CHECK_EQUAL(blockman.CalculateCurrentUsage(), (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2);
213213

214214
// Block 2 was not overwritten:
215-
blockman.ReadBlock(read_block, pos2);
215+
BOOST_CHECK(!blockman.ReadBlock(read_block, pos2, {}));
216216
BOOST_CHECK_EQUAL(read_block.nVersion, 2);
217217
}
218218

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5168,14 +5168,14 @@ void ChainstateManager::LoadExternalBlockFile(
51685168
while (range.first != range.second) {
51695169
std::multimap<uint256, FlatFilePos>::iterator it = range.first;
51705170
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
5171-
if (m_blockman.ReadBlock(*pblockrecursive, it->second)) {
5172-
LogDebug(BCLog::REINDEX, "%s: Processing out of order child %s of %s\n", __func__, pblockrecursive->GetHash().ToString(),
5173-
head.ToString());
5171+
if (m_blockman.ReadBlock(*pblockrecursive, it->second, {})) {
5172+
const auto& block_hash{pblockrecursive->GetHash()};
5173+
LogDebug(BCLog::REINDEX, "%s: Processing out of order child %s of %s", __func__, block_hash.ToString(), head.ToString());
51745174
LOCK(cs_main);
51755175
BlockValidationState dummy;
51765176
if (AcceptBlock(pblockrecursive, dummy, nullptr, true, &it->second, nullptr, true)) {
51775177
nLoaded++;
5178-
queue.push_back(pblockrecursive->GetHash());
5178+
queue.push_back(block_hash);
51795179
}
51805180
}
51815181
range.first++;

0 commit comments

Comments
 (0)