From 2371b9f4ee0b108ebbb8afedc47d73ce0f97d272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Wed, 28 May 2025 14:11:32 +0200 Subject: [PATCH] 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. --- src/bench/readwriteblock.cpp | 8 +++++--- src/test/util/blockfilter.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bench/readwriteblock.cpp b/src/bench/readwriteblock.cpp index 10434b15d20..c0537b1fa69 100644 --- a/src/bench/readwriteblock.cpp +++ b/src/bench/readwriteblock.cpp @@ -42,10 +42,12 @@ static void ReadBlockBench(benchmark::Bench& bench) { const auto testing_setup{MakeNoLogFileContext(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); }); } diff --git a/src/test/util/blockfilter.cpp b/src/test/util/blockfilter.cpp index 8a17f7f4f51..8716af9fdaa 100644 --- a/src/test/util/blockfilter.cpp +++ b/src/test/util/blockfilter.cpp @@ -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; }