Bitcoin Core  21.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>
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 
BlockValidationState
Definition: validation.h:140
streams.h
validation.h
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
benchmark::data::block413567
const std::vector< uint8_t > block413567
Definition: data.cpp:11
chainparams.h
DeserializeAndCheckBlockTest
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:31
DeserializeBlockTest
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:17
CDataStream::write
void write(const char *pch, size_t nSize)
Definition: streams.h:402
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
CDataStream::Rewind
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition: streams.h:338
bench.h
CBaseChainParams::MAIN
static const std::string MAIN
Chain name strings.
Definition: chainparamsbase.h:22
CheckBlock
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
Definition: validation.cpp:3192
CBlock
Definition: block.h:62
ArgsManager
Definition: system.h:162
data.h
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:204
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:166
BENCHMARK
BENCHMARK(DeserializeBlockTest)
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
CreateChainParams
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.
Definition: chainparams.cpp:543
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12