From 13c8df4d5a9eeca18a77644fada1816c0ec10308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 7 Apr 2026 21:52:24 +0300 Subject: [PATCH] refactor: replace `DataStream` with `SpanReader` in block deserialization tests These benchmark inputs are immutable fixture bytes, so `DataStream` adds an unnecessary owned buffer and the setup needed to recreate or preserve its state. Use `SpanReader` for block deserialization in `checkblock` instead. This keeps `DeserializeBlockTest` focused on deserialization work, while `CheckBlockTest` still uses untimed setup only to rebuild a fresh uncached `CBlock` for the timed `CheckBlock()` call. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> --- src/bench/checkblock.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index cbba543f2d8..9faf9ac137a 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -4,22 +4,14 @@ #include #include -#include -#include #include #include #include -#include -#include #include -#include #include #include #include -#include -#include -#include // These are the two major time-sinks which happen after we have fully received // a block off the wire, but before we can relay the block on to peers using @@ -27,27 +19,29 @@ static void DeserializeBlockTest(benchmark::Bench& bench) { - DataStream stream; - bench.unit("block").epochIterations(1) - .setup([&] { stream = DataStream{benchmark::data::block413567}; }) - .run([&] { CBlock block; stream >> TX_WITH_WITNESS(block); }); + const auto block_data{benchmark::data::block413567}; + bench.unit("block").run([&] { + CBlock block; + SpanReader{block_data} >> TX_WITH_WITNESS(block); + assert(block.vtx.size() == 1557); + }); } static void CheckBlockTest(benchmark::Bench& bench) { - ArgsManager bench_args; - const auto chainParams = CreateChainParams(bench_args, ChainType::MAIN); + const auto& chain_params{CChainParams::Main()}; + const auto block_data{benchmark::data::block413567}; CBlock block; bench.unit("block").epochIterations(1) .setup([&] { block = CBlock{}; - DataStream stream{benchmark::data::block413567}; - stream >> TX_WITH_WITNESS(block); + SpanReader{block_data} >> TX_WITH_WITNESS(block); + assert(block.vtx.size() == 1557); }) .run([&] { BlockValidationState validationState; - bool checked = CheckBlock(block, validationState, chainParams->GetConsensus()); + const bool checked{CheckBlock(block, validationState, chain_params->GetConsensus())}; assert(checked); }); }