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  while (state.KeepRunning()) {
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  const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
38 
39  while (state.KeepRunning()) {
40  CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
41  stream >> block;
42  bool rewound = stream.Rewind(benchmark::data::block413567.size());
43  assert(rewound);
44 
45  BlockValidationState validationState;
46  bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
47  assert(checked);
48  }
49 }
50 
std::unique_ptr< const CChainParams > CreateChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
static void DeserializeAndCheckBlockTest(benchmark::State &state)
Definition: checkblock.cpp:31
Definition: block.h:62
static void DeserializeBlockTest(benchmark::State &state)
Definition: checkblock.cpp:17
const std::vector< uint8_t > block413567
Definition: data.cpp:11
bool KeepRunning()
Definition: bench.h:69
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:201
void write(const char *pch, size_t nSize)
Definition: streams.h:434
static const std::string MAIN
Chain name strings.
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:375
BENCHMARK(DeserializeBlockTest, 130)
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12