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/amount.h>7#include <kernel/cs_main.h>8#include <primitives/transaction.h>9#include <rpc/mempool.h>10#include <script/script.h>11#include <sync.h>12#include <test/util/setup_common.h>13#include <test/util/txmempool.h>14#include <txmempool.h>15#include <univalue.h>16#include <util/check.h>18#include <memory>19#include <vector>22static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)23{24LockPoints lp;25TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, /*time=*/0, /*entry_height=*/1, /*entry_sequence=*/0, /*spends_coinbase=*/false, /*sigops_cost=*/4, lp));26}28static void RpcMempool(benchmark::Bench& bench)29{30const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(ChainType::MAIN);31CTxMemPool& pool = *Assert(testing_setup->m_node.mempool);32LOCK2(cs_main, pool.cs);34for (int i = 0; i < 1000; ++i) {35CMutableTransaction tx = CMutableTransaction();36tx.vin.resize(1);37tx.vin[0].scriptSig = CScript() << OP_1;38tx.vin[0].scriptWitness.stack.push_back({1});39tx.vout.resize(1);40tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;41tx.vout[0].nValue = i;42const CTransactionRef tx_r{MakeTransactionRef(tx)};43AddTx(tx_r, /*fee=*/i, pool);44}46bench.run([&] {47(void)MempoolToJSON(pool, /*verbose=*/true);48});49}51BENCHMARK(RpcMempool);
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.