Bitcoin ABC 0.32.4
P2P Digital Currency
readwriteblock.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 <flatfile.h>
9#include <node/blockstorage.h>
10#include <primitives/block.h>
11#include <serialize.h>
12#include <span.h>
13#include <streams.h>
14#include <test/util/setup_common.h>
15#include <validation.h>
16
17#include <cassert>
18#include <cstdint>
19#include <memory>
20#include <vector>
21
24 CBlock block;
25 stream >> block;
26
27 return chainman.m_blockman.SaveBlockToDisk(block, 0);
28}
29
31 const auto testing_setup{
32 MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
33 ChainstateManager &chainman{*testing_setup->m_node.chainman};
34
35 CBlock block;
36 const auto pos{WriteBlockToDisk(chainman)};
37
38 bench.run([&] {
39 const auto success{chainman.m_blockman.ReadBlockFromDisk(block, pos)};
40 assert(success);
41 });
42}
43
45 const auto testing_setup{
46 MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
47 ChainstateManager &chainman{*testing_setup->m_node.chainman};
48
49 std::vector<uint8_t> block_data;
50 const auto pos{WriteBlockToDisk(chainman)};
51
52 bench.run([&] {
53 const auto success{
54 chainman.m_blockman.ReadRawBlockFromDisk(block_data, pos)};
55 assert(success);
56 });
57}
58
Definition: block.h:60
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1186
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1327
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:173
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
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:343
const std::vector< uint8_t > block413567
Definition: data.cpp:11
static void ReadRawBlockFromDiskBench(benchmark::Bench &bench)
BENCHMARK(ReadBlockFromDiskBench)
static void ReadBlockFromDiskBench(benchmark::Bench &bench)
static FlatFilePos WriteBlockToDisk(ChainstateManager &chainman)
assert(!tx.IsCoinBase())