Bitcoin Core  24.99.0
P2P Digital Currency
checkblock.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2022 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>
9 #include <consensus/validation.h>
10 #include <streams.h>
11 #include <util/system.h>
12 #include <validation.h>
13 
14 // These are the two major time-sinks which happen after we have fully received
15 // a block off the wire, but before we can relay the block on to peers using
16 // compact block relay.
17 
19 {
21  std::byte a{0};
22  stream.write({&a, 1}); // Prevent compaction
23 
24  bench.unit("block").run([&] {
25  CBlock block;
26  stream >> block;
27  bool rewound = stream.Rewind(benchmark::data::block413567.size());
28  assert(rewound);
29  });
30 }
31 
33 {
35  std::byte a{0};
36  stream.write({&a, 1}); // Prevent compaction
37 
38  ArgsManager bench_args;
39  const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN);
40 
41  bench.unit("block").run([&] {
42  CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
43  stream >> block;
44  bool rewound = stream.Rewind(benchmark::data::block413567.size());
45  assert(rewound);
46 
47  BlockValidationState validationState;
48  bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
49  assert(checked);
50  });
51 }
52 
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, benchmark::PriorityLevel::HIGH)
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:32
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:18
static const std::string MAIN
Chain name strings.
Definition: block.h:69
void write(Span< const value_type > src)
Definition: streams.h:290
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition: streams.h:236
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
@ HIGH
Definition: bench.h:47
@ SER_NETWORK
Definition: serialize.h:131
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