/ src / bench / checkblock.cpp
checkblock.cpp
 1  // Copyright (c) 2016-present 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/block413567.raw.h>
 7  #include <consensus/validation.h>
 8  #include <primitives/block.h>
 9  #include <primitives/transaction.h>
10  #include <streams.h>
11  #include <validation.h>
12  
13  #include <cassert>
14  #include <cstddef>
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::Bench& bench)
21  {
22      const auto block_data{benchmark::data::block413567};
23      bench.unit("block").run([&] {
24          CBlock block;
25          SpanReader{block_data} >> TX_WITH_WITNESS(block);
26          assert(block.vtx.size() == 1557);
27      });
28  }
29  
30  static void CheckBlockTest(benchmark::Bench& bench)
31  {
32      const auto& chain_params{CChainParams::Main()};
33      const auto block_data{benchmark::data::block413567};
34  
35      CBlock block;
36      bench.unit("block")
37          .setup([&] {
38              block = CBlock{};
39              SpanReader{block_data} >> TX_WITH_WITNESS(block);
40              assert(block.vtx.size() == 1557);
41          })
42          .run([&] {
43              BlockValidationState validationState;
44              const bool checked{CheckBlock(block, validationState, chain_params->GetConsensus())};
45              assert(checked);
46          });
47  }
48  
49  BENCHMARK(DeserializeBlockTest);
50  BENCHMARK(CheckBlockTest);