Fabcoin Core  0.16.2
P2P Digital Currency
checkblock.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2017 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 namespace block_bench {
14 } // namespace block_bench
15 
16 // These are the two major time-sinks which happen after we have fully received
17 // a block off the wire, but before we can relay the block on to peers using
18 // compact block relay.
19 
20 static void DeserializeBlockTest(benchmark::State& state)
21 {
22  CDataStream stream((const char*)block_bench::block413567,
23  (const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
24  SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_BLOCK_LEGACY);
25  char a = '\0';
26  stream.write(&a, 1); // Prevent compaction
27 
28  while (state.KeepRunning()) {
29  CBlock block;
30  stream >> block;
31  assert(stream.Rewind(sizeof(block_bench::block413567)));
32  }
33 }
34 
35 static void DeserializeAndCheckBlockTest(benchmark::State& state)
36 {
37  CDataStream stream((const char*)block_bench::block413567,
38  (const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
39  SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_BLOCK_LEGACY );
40  char a = '\0';
41  stream.write(&a, 1); // Prevent compaction
42 
43  const auto chainParams = CreateChainParams(CBaseChainParams::UNITTEST);
44 
45  while (state.KeepRunning()) {
46  CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
47  stream >> block;
48  assert(stream.Rewind(sizeof(block_bench::block413567)));
49 
50  CValidationState validationState;
51  assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
52  }
53 }
54 
55 //BENCHMARK(DeserializeBlockTest);
56 //BENCHMARK(DeserializeAndCheckBlockTest);
Definition: block.h:155
static const std::string UNITTEST
bool KeepRunning()
Definition: bench.h:70
assert(len-trim+(2 *lenIndices)<=WIDTH)
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:146
void write(const char *pch, size_t nSize)
Definition: streams.h:381
#define a(i)
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:320
Capture information about block/transaction validation.
Definition: validation.h:27