mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 14:12:49 +02:00
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.
This commit is contained in:
@@ -411,7 +411,7 @@ public:
|
||||
void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune) const;
|
||||
|
||||
/** Functions for disk access for blocks */
|
||||
bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional<uint256>& expected_hash = {}) const;
|
||||
bool ReadBlock(CBlock& block, const FlatFilePos& pos, const std::optional<uint256>& expected_hash) const;
|
||||
bool ReadBlock(CBlock& block, const CBlockIndex& index) const;
|
||||
bool ReadRawBlock(std::vector<uint8_t>& block, const FlatFilePos& pos) const;
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -5168,14 +5168,14 @@ void ChainstateManager::LoadExternalBlockFile(
|
||||
while (range.first != range.second) {
|
||||
std::multimap<uint256, FlatFilePos>::iterator it = range.first;
|
||||
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
|
||||
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++;
|
||||
|
Reference in New Issue
Block a user