Bitcoin ABC 0.30.5
P2P Digital Currency
rpc_mempool.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2019 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 <chainparamsbase.h>
7#include <consensus/amount.h>
8#include <kernel/cs_main.h>
10#include <rpc/mempool.h>
11#include <test/util/setup_common.h>
12#include <txmempool.h>
13
14#include <univalue.h>
15
16static void AddTx(const CTransactionRef &tx, const Amount &fee,
19 pool.addUnchecked(CTxMemPoolEntryRef::make(tx, fee, /*time=*/0,
20 /*height=*/1,
21 /*_sigChecks=*/1, lp));
22}
23
24static void RpcMempool(benchmark::Bench &bench) {
25 const TestingSetup test_setup{
27 /* extra_args */
28 {
29 "-nodebuglogfile",
30 "-nodebug",
31 },
32 };
33 CTxMemPool &pool = *Assert(test_setup.m_node.mempool);
34 LOCK2(cs_main, pool.cs);
35
36 for (int i = 0; i < 1000; ++i) {
38 tx.vin.resize(1);
39 tx.vin[0].scriptSig = CScript() << OP_1;
40 tx.vout.resize(1);
41 tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
42 tx.vout[0].nValue = i * COIN;
43 const CTransactionRef tx_r{MakeTransactionRef(tx)};
44 AddTx(tx_r, /* fee */ i * COIN, pool);
45 }
46
47 bench.run([&] { (void)MempoolToJSON(pool, /*verbose*/ true); });
48}
49
static constexpr Amount COIN
Definition: amount.h:144
#define Assert(val)
Identity function.
Definition: check.h:84
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
A mutable version of CTransaction.
Definition: transaction.h:274
std::vector< CTxOut > vout
Definition: transaction.h:277
std::vector< CTxIn > vin
Definition: transaction.h:276
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:212
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:307
static RCUPtr make(Args &&...args)
Construct a new object that is owned by the pointer.
Definition: rcu.h:112
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
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition: mempool.cpp:395
LockPoints lp
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:316
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
static void AddTx(const CTransactionRef &tx, const Amount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
static void RpcMempool(benchmark::Bench &bench)
Definition: rpc_mempool.cpp:24
BENCHMARK(RpcMempool)
@ OP_EQUAL
Definition: script.h:119
@ OP_1
Definition: script.h:56
Definition: amount.h:19
#define LOCK2(cs1, cs2)
Definition: sync.h:309
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56