Bitcoin ABC  0.24.7
P2P Digital Currency
checkblock.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016 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 <config.h>
10 #include <consensus/validation.h>
11 #include <streams.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 
21  char 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 
35  char a = '\0';
36  stream.write(&a, 1); // Prevent compaction
37 
38  const Config &config = GetConfig();
39  const Consensus::Params params = config.GetChainParams().GetConsensus();
40  BlockValidationOptions options(config);
41  bench.unit("block").run([&] {
42  // Note that CBlock caches its checked state, so we need to recreate it
43  // here.
44  CBlock block;
45  stream >> block;
46  bool rewound = stream.Rewind(benchmark::data::block413567.size());
47  assert(rewound);
48 
49  BlockValidationState validationState;
50  bool checked = CheckBlock(block, validationState, params, options);
51  assert(checked);
52  });
53 }
54 
BlockValidationState
Definition: validation.h:138
streams.h
validation.h
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:59
benchmark::data::block413567
const std::vector< uint8_t > block413567
Definition: data.cpp:11
chainparams.h
BlockValidationOptions
Definition: validation.h:180
DeserializeAndCheckBlockTest
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:32
DeserializeBlockTest
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition: checkblock.cpp:18
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:165
CDataStream::write
void write(const char *pch, size_t nSize)
Definition: streams.h:427
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:59
Config
Definition: config.h:17
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.
bench.h
CBlock
Definition: block.h:55
Config::GetChainParams
virtual const CChainParams & GetChainParams() const =0
data.h
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
config.h
BENCHMARK
BENCHMARK(DeserializeBlockTest)
CDataStream::Rewind
bool Rewind(size_type n)
Definition: streams.h:368
GetConfig
const Config & GetConfig()
Definition: config.cpp:34
Checkpoints::CheckBlock
bool CheckBlock(const CCheckpointData &data, int nHeight, const BlockHash &hash)
Returns true if block passes checkpoint checks.
Definition: checkpoints.cpp:17
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11