refactor: replace `DataStream` with `SpanReader` in block deserialization tests
What changed, and why it matters
This is a small internal cleanup in Bitcoin Core's benchmark code. It swaps one helper class for another when reading a fixed test block, removes unused header includes, and simplifies how the benchmark obtains mainnet chain parameters. There is no change to how real network blocks are validated or to any user-facing behavior.
No security action needed. Treat as ordinary code-quality / benchmark refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors src/bench/checkblock.cpp only. It replaces DataStream with SpanReader for deserializing the immutable benchmark fixture block413567.raw, removes several now-unused includes (chainparams.h, common/args.h, serialize.h, span.h, util/chaintype.h, memory, optional, vector), and changes CheckBlockTest to use CChainParams::Main() instead of creating an ArgsManager and CreateChainParams. The benchmark still deserializes the same bytes and calls the same CheckBlock() consensus function; only the test harness and setup are simplified.
Changed components
src/bench/checkblock.cppInspect captured patch +11 / −17
diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp
index cbba543f..9faf9ac1 100644
--- a/src/bench/checkblock.cpp
+++ b/src/bench/checkblock.cpp
@@ -4,22 +4,14 @@
#include <bench/bench.h>
#include <bench/data/block413567.raw.h>
-#include <chainparams.h>
-#include <common/args.h>
#include <consensus/validation.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
-#include <serialize.h>
-#include <span.h>
#include <streams.h>
-#include <util/chaintype.h>
#include <validation.h>
#include <cassert>
#include <cstddef>
-#include <memory>
-#include <optional>
-#include <vector>
// 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);
});
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.