Raven Core  3.0.0
P2P Digital Currency
checkblock.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "bench.h"
7 
8 #include "chainparams.h"
9 #include "validation.h"
10 #include "streams.h"
11 #include "consensus/validation.h"
12 
13 namespace block_bench {
14 #include "bench/data/block566553.raw.h"
15 
16 } // namespace block_bench
17 
18 // These are the two major time-sinks which happen after we have fully received
19 // a block off the wire, but before we can relay the block on to peers using
20 // compact block relay.
21 
22 static void DeserializeBlockTest(benchmark::State& state)
23 {
24  CDataStream stream((const char*)block_bench::block566553,
25  (const char*)&block_bench::block566553[sizeof(block_bench::block566553)],
26  SER_NETWORK, PROTOCOL_VERSION);
27  char a = '\0';
28  stream.write(&a, 1); // Prevent compaction
29 
30  while (state.KeepRunning()) {
31  CBlock block;
32  stream >> block;
33  assert(stream.Rewind(sizeof(block_bench::block566553)));
34  }
35 }
36 
37 static void DeserializeAndCheckBlockTest(benchmark::State& state)
38 {
39  CDataStream stream((const char*)block_bench::block566553,
40  (const char*)&block_bench::block566553[sizeof(block_bench::block566553)],
41  SER_NETWORK, PROTOCOL_VERSION);
42  char a = '\0';
43  stream.write(&a, 1); // Prevent compaction
44 
45  const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
46 
47  while (state.KeepRunning()) {
48  CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
49  stream >> block;
50  assert(stream.Rewind(sizeof(block_bench::block566553)));
51 
52  CValidationState validationState;
53  assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
54  }
55 }
56 
57 BENCHMARK(DeserializeBlockTest);
58 BENCHMARK(DeserializeAndCheckBlockTest);
Definition: block.h:73
bool KeepRunning()
Definition: bench.cpp:44
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
void write(const char *pch, size_t nSize)
Definition: streams.h:382
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:321
RVN END.
Definition: validation.h:30
BENCHMARK(DeserializeBlockTest)