Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
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;
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 BENCHMARK(n)
Definition bench.h:65
#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.
std::vector< CTxOut > vout
std::vector< CTxIn > vin
Serialized script, used inside transaction inputs and outputs.
Definition script.h:424
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
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()
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
static void AddTx(const CTransactionRef &tx, const Amount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
static void RpcMempool(benchmark::Bench &bench)
@ OP_EQUAL
Definition script.h:119
@ OP_1
Definition script.h:56
#define LOCK2(cs1, cs2)
Definition sync.h:309
#define EXCLUSIVE_LOCKS_REQUIRED(...)