Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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 
7 #include <chainparams.h>
8 #include <validation.h>
9 #include <streams.h>
10 #include <consensus/validation.h>
11 
12 #include <bench/data/block813851.raw.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 {
20  CDataStream stream((const char*)raw_bench::block813851,
21  (const char*)&raw_bench::block813851[sizeof(raw_bench::block813851)],
23  char a = '\0';
24  stream.write(&a, 1); // Prevent compaction
25 
26  while (state.KeepRunning()) {
27  CBlock block;
28  stream >> block;
29  assert(stream.Rewind(sizeof(raw_bench::block813851)));
30  }
31 }
32 
34 {
35  CDataStream stream((const char*)raw_bench::block813851,
36  (const char*)&raw_bench::block813851[sizeof(raw_bench::block813851)],
38  char a = '\0';
39  stream.write(&a, 1); // Prevent compaction
40 
41  const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
42 
43  while (state.KeepRunning()) {
44  CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
45  stream >> block;
46  assert(stream.Rewind(sizeof(raw_bench::block813851)));
47 
48  CValidationState validationState;
49  assert(CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime()));
50  }
51 }
52 
static void DeserializeAndCheckBlockTest(benchmark::State &state)
Definition: checkblock.cpp:33
Definition: block.h:72
static void DeserializeBlockTest(benchmark::State &state)
Definition: checkblock.cpp:18
bool KeepRunning()
Definition: bench.cpp:39
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
void write(const char *pch, size_t nSize)
Definition: streams.h:336
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
std::unique_ptr< CChainParams > CreateChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
bool CheckBlock(const CBlock &block, CValidationState &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:277
Capture information about block/transaction validation.
Definition: validation.h:22
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
BENCHMARK(DeserializeBlockTest)
Released under the MIT license