Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2023-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.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>10#include <primitives/transaction.h>11#include <serialize.h>12#include <streams.h>13#include <sync.h>14#include <test/util/setup_common.h>15#include <util/check.h>16#include <validation.h>18#include <memory>19#include <span>21static CBlock CreateTestBlock()22{23CBlock block;24SpanReader{benchmark::data::block413567} >> TX_WITH_WITNESS(block);25return block;26}28static void WriteBlockBench(benchmark::Bench& bench)29{30const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};31auto& blockman{testing_setup->m_node.chainman->m_blockman};32const CBlock block{CreateTestBlock()};33bench.run([&] {34LOCK(::cs_main);35const auto pos{blockman.WriteBlock(block, 413'567)};36assert(!pos.IsNull());37});38}40static void ReadBlockBench(benchmark::Bench& bench)41{42const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};43auto& blockman{testing_setup->m_node.chainman->m_blockman};44const auto& test_block{CreateTestBlock()};45const auto& expected_hash{test_block.GetHash()};46const auto& pos{WITH_LOCK(::cs_main, return blockman.WriteBlock(test_block, 413'567))};47bench.run([&] {48CBlock block;49const auto success{blockman.ReadBlock(block, pos, expected_hash)};50assert(success);51});52}54static void ReadRawBlockBench(benchmark::Bench& bench)55{56const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};57auto& blockman{testing_setup->m_node.chainman->m_blockman};58const auto pos{WITH_LOCK(::cs_main, return blockman.WriteBlock(CreateTestBlock(), 413'567))};59bench.run([&] {60const auto res{blockman.ReadRawBlock(pos)};61assert(res);62});63}65BENCHMARK(WriteBlockBench);66BENCHMARK(ReadBlockBench);67BENCHMARK(ReadRawBlockBench);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.