Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
mempool_ephemeral_spends.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 <
consensus/validation.h
>
8
#include <
kernel/cs_main.h
>
9
#include <
policy/ephemeral_policy.h
>
10
#include <
policy/feerate.h
>
11
#include <
primitives/transaction.h
>
12
#include <
script/script.h
>
13
#include <
sync.h
>
14
#include <
test/util/setup_common.h
>
15
#include <
test/util/txmempool.h
>
16
#include <
txmempool.h
>
17
#include <
util/check.h
>
18
19
#include <cstddef>
20
#include <cstdint>
21
#include <memory>
22
#include <vector>
23
24
25
static
void
AddTx
(
const
CTransactionRef
& tx,
CTxMemPool
& pool)
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
, pool.cs)
26
{
27
int64_t nTime{0};
28
unsigned
int
nHeight
{1};
29
uint64_t
sequence
{0};
30
bool
spendsCoinbase
{
false
};
31
unsigned
int
sigOpCost
{4};
32
uint64_t
fee
{0};
33
LockPoints
lp
;
34
TryAddToMempool
(pool,
CTxMemPoolEntry
(
35
tx,
fee
, nTime,
nHeight
,
sequence
,
36
spendsCoinbase
,
sigOpCost
,
lp
));
37
}
38
39
static
void
MempoolCheckEphemeralSpends
(
benchmark::Bench
& bench)
40
{
41
const
auto
testing_setup =
MakeNoLogFileContext<const TestingSetup>
();
42
43
int
number_outputs{1000};
44
if
(bench.
complexityN
() > 1) {
45
number_outputs =
static_cast<
int
>
(bench.
complexityN
());
46
}
47
48
// Tx with many outputs
49
CMutableTransaction
tx1;
50
tx1.
vin
.resize(1);
51
tx1.
vout
.resize(number_outputs);
52
for
(
size_t
i = 0; i < tx1.
vout
.size(); i++) {
53
// Each output progressively larger
54
tx1.
vout
[i] =
CTxOut
{
CAmount
(i) *
CENT
,
CScript
()};
55
}
56
57
const
auto
& parent_txid = tx1.
GetHash
();
58
59
// Spends all outputs of tx1, other details don't matter
60
CMutableTransaction
tx2;
61
tx2.
vin
.resize(tx1.
vout
.size());
62
for
(uint32_t i{0}; i < tx2.
vin
.size(); ++i) {
63
tx2.
vin
[i].prevout =
COutPoint
{parent_txid, i};
64
}
65
tx2.
vout
.resize(1);
66
67
CTxMemPool
& pool = *
Assert
(testing_setup->m_node.mempool);
68
LOCK2
(
cs_main
, pool.cs);
69
// Create transaction references outside the "hot loop"
70
const
CTransactionRef
tx1_r{MakeTransactionRef(tx1)};
71
const
CTransactionRef
tx2_r{MakeTransactionRef(tx2)};
72
73
AddTx
(tx1_r, pool);
74
assert
(tx2_r->vin.back().prevout ==
COutPoint
(parent_txid, tx1_r->vout.size() - 1));
75
76
uint32_t iteration{0};
77
78
TxValidationState
dummy_state;
79
Wtxid
dummy_wtxid;
80
81
bench.
run
([&]()
NO_THREAD_SAFETY_ANALYSIS
{
82
83
CheckEphemeralSpends
({tx2_r},
/*dust_relay_rate=*/
CFeeRate
(iteration *
COIN
/ 10), pool, dummy_state, dummy_wtxid);
84
iteration++;
85
});
86
}
87
88
BENCHMARK
(
MempoolCheckEphemeralSpends
);
amount.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative).
Definition
amount.h:12
COIN
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition
amount.h:15
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
TryAddToMempool
TryAddToMempool(pool, CTxMemPoolEntry(tx, fee, 0, 1, 0, false, 4, lp))
check.h
Assert
#define Assert(val)
Identity function.
Definition
check.h:116
CFeeRate::CFeeRate
CFeeRate()=default
Fee rate of 0 satoshis per 0 vB.
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition
transaction.h:30
CScript::CScript
CScript()=default
CTxMemPoolEntry::CTxMemPoolEntry
CTxMemPoolEntry(const CTxMemPoolEntry &)=delete
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition
txmempool.h:187
CTxOut
An output of a transaction.
Definition
transaction.h:141
TxValidationState
Definition
validation.h:132
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1308
ankerl::nanobench::Bench::complexityN
Bench & complexityN(T n) noexcept
Definition
nanobench.h:1339
validation.h
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
CheckEphemeralSpends
bool CheckEphemeralSpends(const Package &package, CFeeRate dust_relay_rate, const CTxMemPool &tx_pool, TxValidationState &out_child_state, Wtxid &out_child_wtxid)
Called for each transaction(package) if any dust is in the package.
Definition
ephemeral_policy.cpp:33
ephemeral_policy.h
feerate.h
AddTx
static void AddTx(const CTransactionRef &tx, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
nHeight
unsigned int nHeight
Definition
mempool_ephemeral_spends.cpp:28
MempoolCheckEphemeralSpends
static void MempoolCheckEphemeralSpends(benchmark::Bench &bench)
Definition
mempool_ephemeral_spends.cpp:39
fee
uint64_t fee
Definition
mempool_ephemeral_spends.cpp:32
spendsCoinbase
bool spendsCoinbase
Definition
mempool_ephemeral_spends.cpp:30
sigOpCost
unsigned int sigOpCost
Definition
mempool_ephemeral_spends.cpp:31
sequence
uint64_t sequence
Definition
mempool_ephemeral_spends.cpp:29
lp
LockPoints lp
Definition
mempool_ephemeral_spends.cpp:33
transaction.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition
transaction.h:417
script.h
setup_common.h
CENT
constexpr CAmount CENT
Definition
setup_common.h:41
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:241
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:372
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition
transaction.h:374
CMutableTransaction::GetHash
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Definition
transaction.cpp:69
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:373
LockPoints
Definition
mempool_entry.h:26
sync.h
LOCK2
#define LOCK2(cs1, cs2)
Definition
sync.h:269
txmempool.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:49
NO_THREAD_SAFETY_ANALYSIS
#define NO_THREAD_SAFETY_ANALYSIS
Definition
threadsafety.h:51
Wtxid
transaction_identifier< true > Wtxid
Wtxid commits to all transaction fields including the witness.
Definition
transaction_identifier.h:62
txmempool.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0