Bitcoin Core  27.99.0
P2P Digital Currency
readblock.cpp
Go to the documentation of this file.
1 // Copyright (c) 2023 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 <consensus/validation.h>
9 #include <node/blockstorage.h>
10 #include <streams.h>
11 #include <test/util/setup_common.h>
12 #include <util/chaintype.h>
13 #include <validation.h>
14 
16 {
18  CBlock block;
19  stream >> TX_WITH_WITNESS(block);
20 
21  return chainman.m_blockman.SaveBlockToDisk(block, 0, nullptr);
22 }
23 
25 {
26  const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
27  ChainstateManager& chainman{*testing_setup->m_node.chainman};
28 
29  CBlock block;
30  const auto pos{WriteBlockToDisk(chainman)};
31 
32  bench.run([&] {
33  const auto success{chainman.m_blockman.ReadBlockFromDisk(block, pos)};
34  assert(success);
35  });
36 }
37 
39 {
40  const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
41  ChainstateManager& chainman{*testing_setup->m_node.chainman};
42 
43  std::vector<uint8_t> block_data;
44  const auto pos{WriteBlockToDisk(chainman)};
45 
46  bench.run([&] {
47  const auto success{chainman.m_blockman.ReadRawBlockFromDisk(block_data, pos)};
48  assert(success);
49  });
50 }
51 
Definition: block.h:69
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:850
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:966
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
bool WriteUndoDataForBlock(const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex &block) EXCLUSIVE_LOCKS_REQUIRED(FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight, const FlatFilePos *dbp)
Store block on disk.
Definition: blockstorage.h:316
const std::vector< uint8_t > block413567
Definition: data.cpp:11
@ HIGH
Definition: bench.h:47
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:195
static void ReadRawBlockFromDiskTest(benchmark::Bench &bench)
Definition: readblock.cpp:38
static void ReadBlockFromDiskTest(benchmark::Bench &bench)
Definition: readblock.cpp:24
BENCHMARK(ReadBlockFromDiskTest, benchmark::PriorityLevel::HIGH)
static FlatFilePos WriteBlockToDisk(ChainstateManager &chainman)
Definition: readblock.cpp:15
assert(!tx.IsCoinBase())