Bitcoin Core
24.1.0
P2P Digital Currency
src
bench
rpc_mempool.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-2021 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 <
rpc/mempool.h
>
8
#include <
test/util/setup_common.h
>
9
#include <
txmempool.h
>
10
11
#include <
univalue.h
>
12
13
14
static
void
AddTx
(
const
CTransactionRef
& tx,
const
CAmount
& fee,
CTxMemPool
& pool)
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
, pool.cs)
15
{
16
LockPoints
lp
;
17
pool.addUnchecked(
CTxMemPoolEntry
(tx, fee,
/*time=*/
0,
/*entry_height=*/
1,
/*spends_coinbase=*/
false
,
/*sigops_cost=*/
4,
lp
));
18
}
19
20
static
void
RpcMempool
(
benchmark::Bench
& bench)
21
{
22
const
auto
testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(
CBaseChainParams::MAIN
);
23
CTxMemPool
& pool = *
Assert
(testing_setup->m_node.mempool);
24
LOCK2
(
cs_main
, pool.cs);
25
26
for
(
int
i = 0; i < 1000; ++i) {
27
CMutableTransaction
tx =
CMutableTransaction
();
28
tx.
vin
.resize(1);
29
tx.
vin
[0].scriptSig =
CScript
() <<
OP_1
;
30
tx.
vin
[0].scriptWitness.stack.push_back({1});
31
tx.
vout
.resize(1);
32
tx.
vout
[0].scriptPubKey =
CScript
() <<
OP_1
<<
OP_EQUAL
;
33
tx.
vout
[0].nValue = i;
34
const
CTransactionRef
tx_r{
MakeTransactionRef
(tx)};
35
AddTx
(tx_r,
/*fee=*/
i, pool);
36
}
37
38
bench.
run
([&] {
39
(void)
MempoolToJSON
(pool,
/*verbose=*/
true
);
40
});
41
}
42
43
BENCHMARK
(
RpcMempool
);
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition:
transaction.h:414
LockPoints
Definition:
txmempool.h:44
AddTx
static void AddTx(const CTransactionRef &tx, const CAmount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition:
transaction.h:374
OP_EQUAL
Definition:
script.h:142
CTxMemPoolEntry
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition:
txmempool.h:88
CBaseChainParams::MAIN
static const std::string MAIN
Chain name strings.
Definition:
chainparamsbase.h:22
OP_1
Definition:
script.h:79
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition:
amount.h:12
LOCK2
#define LOCK2(cs1, cs2)
Definition:
sync.h:262
txmempool.h
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition:
nanobench.h:1183
univalue.h
setup_common.h
RpcMempool
static void RpcMempool(benchmark::Bench &bench)
Definition:
rpc_mempool.cpp:20
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition:
transaction.h:375
BENCHMARK
BENCHMARK(RpcMempool)
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition:
transaction.h:415
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition:
threadsafety.h:49
bench.h
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition:
txmempool.h:431
CScript
Serialized script, used inside transaction inputs and outputs.
Definition:
script.h:410
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition:
validation.cpp:121
MempoolToJSON
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition:
mempool.cpp:322
CMutableTransaction
A mutable version of CTransaction.
Definition:
transaction.h:372
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition:
nanobench.h:616
chainparamsbase.h
mempool.h
Assert
#define Assert(val)
Identity function.
Definition:
check.h:74
lp
LockPoints lp
Definition:
mempool_eviction.cpp:17
Generated on Tue May 16 2023 12:00:00 for Bitcoin Core by
1.8.14