mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-12 15:03:18 +02:00
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>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user