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) 2011-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 <consensus/consensus.h>7#include <node/mining_types.h>8#include <primitives/transaction.h>9#include <random.h>10#include <script/script.h>11#include <sync.h>12#include <test/util/mining.h>13#include <test/util/script.h>14#include <test/util/setup_common.h>15#include <util/check.h>16#include <validation.h>18#include <array>19#include <cstddef>20#include <memory>21#include <vector>23using node::BlockCreateOptions;25static void AssembleBlock(benchmark::Bench& bench)26{27const auto test_setup = MakeNoLogFileContext<const TestingSetup>();29CScriptWitness witness;30witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE);31BlockCreateOptions options{32.coinbase_output_script = P2WSH_OP_TRUE,33};35// Collect some loose transactions that spend the coinbases of our mined blocks36constexpr size_t NUM_BLOCKS{200};37std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;38for (size_t b{0}; b < NUM_BLOCKS; ++b) {39CMutableTransaction tx;40tx.vin.emplace_back(MineBlock(test_setup->m_node, options));41tx.vin.back().scriptWitness = witness;42tx.vout.emplace_back(1337, P2WSH_OP_TRUE);43if (NUM_BLOCKS - b >= COINBASE_MATURITY)44txs.at(b) = MakeTransactionRef(tx);45}46{47LOCK(::cs_main);49for (const auto& txr : txs) {50const MempoolAcceptResult res = test_setup->m_node.chainman->ProcessTransaction(txr);51assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);52}53}55bench.run([&] {56PrepareBlock(test_setup->m_node, options);57});58}59static void BlockAssemblerAddPackageTxns(benchmark::Bench& bench)60{61FastRandomContext det_rand{true};62auto testing_setup{MakeNoLogFileContext<TestChain100Setup>()};63testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000, /*submit=*/true);65bench.run([&] {66PrepareBlock(testing_setup->m_node, {67.coinbase_output_script = P2WSH_OP_TRUE,68.test_block_validity = false69});70});71}73BENCHMARK(AssembleBlock);74BENCHMARK(BlockAssemblerAddPackageTxns);
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.