Bitcoin ABC  0.22.13
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 <rpc/blockchain.h>
7 #include <txmempool.h>
8 
9 #include <univalue.h>
10 
11 static void AddTx(const CTransactionRef &tx, const Amount &fee,
13  LockPoints lp;
14  pool.addUnchecked(CTxMemPoolEntry(tx, fee, /* time */ 0,
15  /* height */ 1,
16  /* spendsCoinbase */ false,
17  /* sigOpCount */ 1, lp));
18 }
19 
20 static void RpcMempool(benchmark::State &state) {
21  CTxMemPool pool;
22  LOCK2(cs_main, pool.cs);
23 
24  for (int i = 0; i < 1000; ++i) {
26  tx.vin.resize(1);
27  tx.vin[0].scriptSig = CScript() << OP_1;
28  tx.vout.resize(1);
29  tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
30  tx.vout[0].nValue = i * COIN;
31  const CTransactionRef tx_r{MakeTransactionRef(tx)};
32  AddTx(tx_r, /* fee */ i * COIN, pool);
33  }
34 
35  while (state.KeepRunning()) {
36  (void)MempoolToJSON(pool, /*verbose*/ true);
37  }
38 }
39 
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:338
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:339
Definition: amount.h:17
static void AddTx(const CTransactionRef &tx, const Amount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
bool KeepRunning()
Definition: bench.h:71
std::vector< CTxOut > vout
Definition: transaction.h:300
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:65
std::vector< CTxIn > vin
Definition: transaction.h:299
#define LOCK2(cs1, cs2)
Definition: sync.h:233
static constexpr Amount COIN
Definition: amount.h:153
static void RpcMempool(benchmark::State &state)
Definition: rpc_mempool.cpp:20
Definition: script.h:55
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:95
BENCHMARK(RpcMempool, 40)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:468
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
A mutable version of CTransaction.
Definition: transaction.h:297
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose)
Mempool to JSON.
Definition: blockchain.cpp:581
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:545
LockPoints lp