Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
rpc_mempool.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-present 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 <
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
>
17
18
#include <memory>
19
#include <vector>
20
21
22
static
void
AddTx
(
const
CTransactionRef
& tx,
const
CAmount
&
fee
,
CTxMemPool
& pool)
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
, pool.cs)
23
{
24
LockPoints
lp
;
25
TryAddToMempool
(pool,
CTxMemPoolEntry
(tx,
fee
,
/*time=*/
0,
/*entry_height=*/
1,
/*entry_sequence=*/
0,
/*spends_coinbase=*/
false
,
/*sigops_cost=*/
4,
lp
));
26
}
27
28
static
void
RpcMempool
(
benchmark::Bench
& bench)
29
{
30
const
auto
testing_setup =
MakeNoLogFileContext<const ChainTestingSetup>
(
ChainType::MAIN
);
31
CTxMemPool
& pool = *
Assert
(testing_setup->m_node.mempool);
32
LOCK2
(
cs_main
, pool.
cs
);
33
34
for
(
int
i = 0; i < 1000; ++i) {
35
CMutableTransaction
tx =
CMutableTransaction
();
36
tx.
vin
.resize(1);
37
tx.
vin
[0].scriptSig =
CScript
() <<
OP_1
;
38
tx.
vin
[0].scriptWitness.stack.push_back({1});
39
tx.
vout
.resize(1);
40
tx.
vout
[0].scriptPubKey =
CScript
() <<
OP_1
<<
OP_EQUAL
;
41
tx.
vout
[0].nValue = i;
42
const
CTransactionRef
tx_r{
MakeTransactionRef
(tx)};
43
AddTx
(tx_r,
/*fee=*/
i, pool);
44
}
45
46
bench.
run
([&] {
47
(void)
MempoolToJSON
(pool,
/*verbose=*/
true
);
48
});
49
}
50
51
BENCHMARK
(
RpcMempool
);
amount.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative).
Definition
amount.h:12
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
ChainType::MAIN
@ MAIN
Definition
chaintype.h:12
check.h
Assert
#define Assert(val)
Identity function.
Definition
check.h:113
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:405
CTxMemPoolEntry
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition
mempool_entry.h:66
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition
txmempool.h:187
CTxMemPool::cs
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition
txmempool.h:258
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition
cs_main.cpp:8
cs_main.h
fee
uint64_t fee
Definition
mempool_ephemeral_spends.cpp:30
lp
LockPoints lp
Definition
mempool_ephemeral_spends.cpp:31
transaction.h
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition
transaction.h:404
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition
transaction.h:403
MempoolToJSON
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition
mempool.cpp:571
mempool.h
RpcMempool
static void RpcMempool(benchmark::Bench &bench)
Definition
rpc_mempool.cpp:28
AddTx
static void AddTx(const CTransactionRef &tx, const CAmount &fee, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
TryAddToMempool
TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, 0, 1, 0, false, 4, lp))
script.h
OP_EQUAL
@ OP_EQUAL
Definition
script.h:146
OP_1
@ OP_1
Definition
script.h:83
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:250
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:358
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition
transaction.h:360
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:359
LockPoints
Definition
mempool_entry.h:26
sync.h
LOCK2
#define LOCK2(cs1, cs2)
Definition
sync.h:259
txmempool.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:51
txmempool.h
univalue.h
Generated on
for Bitcoin Core by
1.17.0