Bitcoin Core  0.20.99
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>
9 #include <consensus/validation.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 
Definition: block.h:62
const std::vector< uint8_t > block413567
Definition: data.cpp:11
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:17
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:202
void write(const char *pch, size_t nSize)
Definition: streams.h:435
static const std::string MAIN
Chain name strings.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:31
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
bool Rewind(size_type n)
Definition: streams.h:376
Bench & unit(char const *unit)
Sets the operation unit.
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
BENCHMARK(DeserializeBlockTest)
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:583
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.