test/bench: verify hash in ComputeFilter reads

Switch to the index-aware `ReadBlock()` overload in `ComputeFilter` so that filter creation will abort if the stored block header hash doesn't match the expected one.

In the `readwriteblock` benchmark, pass the expected hash to `ReadBlock()` to match the new signature without affecting benchmark performance.
This commit is contained in:
Lőrinc
2025-05-28 14:11:32 +02:00
parent 5d235d50d6
commit 2371b9f4ee
2 changed files with 6 additions and 4 deletions

View File

@@ -42,10 +42,12 @@ static void ReadBlockBench(benchmark::Bench& bench)
{
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
auto& blockman{testing_setup->m_node.chainman->m_blockman};
const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)};
CBlock block;
const auto& test_block{CreateTestBlock()};
const auto& expected_hash{test_block.GetHash()};
const auto& pos{blockman.WriteBlock(test_block, 413'567)};
bench.run([&] {
const auto success{blockman.ReadBlock(block, pos)};
CBlock block;
const auto success{blockman.ReadBlock(block, pos, expected_hash)};
assert(success);
});
}

View File

@@ -17,7 +17,7 @@ bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex& block_index,
LOCK(::cs_main);
CBlock block;
if (!blockman.ReadBlock(block, block_index.GetBlockPos())) {
if (!blockman.ReadBlock(block, block_index)) {
return false;
}