PIVX Core  5.6.99
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 "validation.h"
9 
10 // These are the two major time-sinks which happen after we have fully received
11 // a block off the wire, but before we can relay the block on to peers using
12 // compact block relay.
13 
14 static void DeserializeBlockTest(benchmark::State& state)
15 {
16  CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION);
17  char a = '\0';
18  stream.write(&a, 1); // Prevent compaction
19 
20  while (state.KeepRunning()) {
21  CBlock block;
22  stream >> block;
23  bool rewound = stream.Rewind(benchmark::data::block2680960.size());
24  assert(rewound);
25  }
26 }
27 
28 static void DeserializeAndCheckBlockTest(benchmark::State& state)
29 {
30  CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION);
31  char a = '\0';
32  stream.write(&a, 1); // Prevent compaction
33 
35  const static auto verify_handle = std::make_unique<ECCVerifyHandle>();
36 
37  while (state.KeepRunning()) {
38  CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
39  stream >> block;
40  bool rewound = stream.Rewind(benchmark::data::block2680960.size());
41  assert(rewound);
42 
43  CValidationState state;
44  assert(WITH_LOCK(cs_main, return CheckBlock(block, state); ));
45  }
46 }
47 
48 BENCHMARK(DeserializeBlockTest, 130);
49 BENCHMARK(DeserializeAndCheckBlockTest, 160);
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
BENCHMARK(DeserializeBlockTest, 130)
static const std::string MAIN
Chain name strings.
Definition: block.h:80
Capture information about block/transaction validation.
Definition: validation.h:24
bool KeepRunning()
Definition: bench.h:69
bool CheckBlock(int nHeight, const uint256 &hash, bool fMatchesCheckpoint)
Returns true if block passes checkpoint checks.
Definition: checkpoints.cpp:29
const std::vector< uint8_t > block2680960
Definition: data.cpp:11
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
@ SER_NETWORK
Definition: serialize.h:174
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:247