Bitcoin Core 28.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/block413567.raw.h>
7#include <flatfile.h>
8#include <node/blockstorage.h>
9#include <primitives/block.h>
11#include <serialize.h>
12#include <span.h>
13#include <streams.h>
15#include <validation.h>
16
17#include <cassert>
18#include <cstdint>
19#include <memory>
20#include <vector>
21
23{
24 DataStream stream{benchmark::data::block413567};
25 CBlock block;
26 stream >> TX_WITH_WITNESS(block);
27
28 return chainman.m_blockman.SaveBlockToDisk(block, 0);
29}
30
32{
33 const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
34 ChainstateManager& chainman{*testing_setup->m_node.chainman};
35
36 CBlock block;
37 const auto pos{WriteBlockToDisk(chainman)};
38
39 bench.run([&] {
40 const auto success{chainman.m_blockman.ReadBlockFromDisk(block, pos)};
41 assert(success);
42 });
43}
44
46{
47 const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
48 ChainstateManager& chainman{*testing_setup->m_node.chainman};
49
50 std::vector<uint8_t> block_data;
51 const auto pos{WriteBlockToDisk(chainman)};
52
53 bench.run([&] {
54 const auto success{chainman.m_blockman.ReadRawBlockFromDisk(block_data, pos)};
55 assert(success);
56 });
57}
58
Definition: block.h:69
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:866
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1007
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)
Store block on disk and update block file statistics.
Definition: blockstorage.h:344
@ HIGH
Definition: bench.h:48
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:195
static void ReadRawBlockFromDiskTest(benchmark::Bench &bench)
Definition: readblock.cpp:45
static void ReadBlockFromDiskTest(benchmark::Bench &bench)
Definition: readblock.cpp:31
BENCHMARK(ReadBlockFromDiskTest, benchmark::PriorityLevel::HIGH)
static FlatFilePos WriteBlockToDisk(ChainstateManager &chainman)
Definition: readblock.cpp:22
assert(!tx.IsCoinBase())