mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-05 19:26:17 +00:00
This is an extraction of ArgsManager related functions from util/system into their own common file. Config file related functions are moved to common/config.cpp. The background of this commit is an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager. The ArgsManager belongs into the common library, since the kernel library should not depend on it. See doc/design/libraries.md for more information on this rationale.
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
// Copyright (c) 2016-2022 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <bench/bench.h>
|
|
#include <bench/data.h>
|
|
|
|
#include <chainparams.h>
|
|
#include <common/args.h>
|
|
#include <consensus/validation.h>
|
|
#include <streams.h>
|
|
#include <validation.h>
|
|
|
|
// 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
|
|
// compact block relay.
|
|
|
|
static void DeserializeBlockTest(benchmark::Bench& bench)
|
|
{
|
|
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
|
|
std::byte a{0};
|
|
stream.write({&a, 1}); // Prevent compaction
|
|
|
|
bench.unit("block").run([&] {
|
|
CBlock block;
|
|
stream >> block;
|
|
bool rewound = stream.Rewind(benchmark::data::block413567.size());
|
|
assert(rewound);
|
|
});
|
|
}
|
|
|
|
static void DeserializeAndCheckBlockTest(benchmark::Bench& bench)
|
|
{
|
|
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
|
|
std::byte a{0};
|
|
stream.write({&a, 1}); // Prevent compaction
|
|
|
|
ArgsManager bench_args;
|
|
const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN);
|
|
|
|
bench.unit("block").run([&] {
|
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
|
stream >> block;
|
|
bool rewound = stream.Rewind(benchmark::data::block413567.size());
|
|
assert(rewound);
|
|
|
|
BlockValidationState validationState;
|
|
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
|
|
assert(checked);
|
|
});
|
|
}
|
|
|
|
BENCHMARK(DeserializeBlockTest, benchmark::PriorityLevel::HIGH);
|
|
BENCHMARK(DeserializeAndCheckBlockTest, benchmark::PriorityLevel::HIGH);
|