Bitcoin Core 22.99.0
P2P Digital Currency
checkblock.cpp
Go to the documentation of this file.
1// Copyright (c) 2016-2020 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
6#include <bench/data.h>
7
8#include <chainparams.h>
10#include <streams.h>
11#include <validation.h>
12
13// These are the two major time-sinks which happen after we have fully received
14// a block off the wire, but before we can relay the block on to peers using
15// compact block relay.
16
18{
20 char a = '\0';
21 stream.write(&a, 1); // Prevent compaction
22
23 bench.unit("block").run([&] {
24 CBlock block;
25 stream >> block;
26 bool rewound = stream.Rewind(benchmark::data::block413567.size());
27 assert(rewound);
28 });
29}
30
32{
34 char a = '\0';
35 stream.write(&a, 1); // Prevent compaction
36
37 ArgsManager bench_args;
38 const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN);
39
40 bench.unit("block").run([&] {
41 CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
42 stream >> block;
43 bool rewound = stream.Rewind(benchmark::data::block413567.size());
44 assert(rewound);
45
46 BlockValidationState validationState;
47 bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
48 assert(checked);
49 });
50}
51
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
BENCHMARK(DeserializeBlockTest)
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:31
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:17
static const std::string MAIN
Chain name strings.
Definition: block.h:63
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:205
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition: streams.h:338
void write(const char *pch, size_t nSize)
Definition: streams.h:402
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
Bench & unit(char const *unit)
Sets the operation unit.
const std::vector< uint8_t > block413567
Definition: data.cpp:11
@ SER_NETWORK
Definition: serialize.h:138
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
assert(!tx.IsCoinBase())
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12