15#include <validation.h>
45 std::vector<Available> available_coins;
46 std::vector<CTransactionRef> ordered_coins;
48 size_t tx_counter = 1;
49 for (
auto x = 0; x < 10; ++x) {
54 tx.
vin[0].scriptWitness.stack.push_back(
CScriptNum(x).getvch());
61 available_coins.emplace_back(ordered_coins.back(), tx_counter++);
63 for (
auto x = 0; x < childTxs && !available_coins.empty(); ++x) {
65 size_t n_ancestors = det_rand.
randrange(10)+1;
66 for (
size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
67 size_t idx = det_rand.
randrange(available_coins.size());
69 Txid hash = coin.
ref->GetHash();
71 size_t n_to_take = det_rand.
randrange(2) == 0 ?
74 for (
size_t i = 0; i < n_to_take; ++i) {
75 tx.
vin.emplace_back();
81 coin = available_coins.back();
82 available_coins.pop_back();
91 available_coins.emplace_back(ordered_coins.back(), tx_counter++);
103 const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
ChainType::MAIN);
106 std::vector<CTransactionRef> transactions;
108 for (
int i=0; i<100; i++) {
110 transactions.insert(transactions.end(), new_txs.begin(), new_txs.end());
116 for (
auto& tx : transactions) {
117 AddTx(tx, pool, det_rand);
130 const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
ChainType::MAIN);
133 std::vector<CTransactionRef> tx_remove_for_block;
134 std::vector<Txid> hashes_remove_for_block;
138 for (
int i=0; i<1000; i++) {
139 std::vector<CTransactionRef> transactions =
CreateCoinCluster(det_rand, childTxs, 1);
145 for (
auto& tx : transactions) {
147 tx_remove_for_block.push_back(tx);
149 hashes_remove_for_block.emplace_back(tx->GetHash());
151 AddTx(tx, pool, det_rand);
160 for (
auto& tx: tx_remove_for_block) {
161 AddTx(tx, pool, det_rand);
174 const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
ChainType::MAIN);
179 std::vector<CTransactionRef> transactions =
CreateCoinCluster(det_rand, childTxs, 1);
180 for (
auto& tx : transactions) {
181 AddTx(tx, pool, det_rand);
199 auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(
ChainType::REGTEST, {.extra_args = {
"-checkmempool=1"}});
202 testing_setup->PopulateMempool(det_rand, 400,
true);
203 const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
207 pool.check(coins_tip, 300);
static constexpr CAmount COIN
The amount of satoshis in one BTC.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
std::vector< unsigned char > getvch() const
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::optional< txiter > GetIter(const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
void UpdateTransactionsFromBlock(const std::vector< Txid > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
UpdateTransactionsFromBlock is called when adding transactions from a disconnected block back to the ...
CTransactionRef get(const Txid &hash) const
std::set< txiter, CompareIteratorByHash > setEntries
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of given transaction.
setEntries CalculateMemPoolAncestors(const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Calculate all in-mempool ancestors of entry (not including the tx itself)
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
Main entry point to nanobench's benchmarking facility.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Bench & complexityN(T n) noexcept
static transaction_identifier FromUint256(const uint256 &id)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
static void MempoolCheck(benchmark::Bench &bench)
static std::vector< CTransactionRef > CreateCoinCluster(FastRandomContext &det_rand, int childTxs, int min_ancestors)
static void MemPoolAncestorsDescendants(benchmark::Bench &bench)
TryAddToMempool(pool, CTxMemPoolEntry(TxGraph::Ref(), tx, det_rand.randrange(10000)+1000, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
BENCHMARK(MemPoolAncestorsDescendants, benchmark::PriorityLevel::HIGH)
static void MemPoolAddTransactions(benchmark::Bench &bench)
static void AddTx(const CTransactionRef &tx, CTxMemPool &pool, FastRandomContext &det_rand) EXCLUSIVE_LOCKS_REQUIRED(cs_main
static void ComplexMemPool(benchmark::Bench &bench)
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
uint256 GetRandHash() noexcept
Generate a random uint256.
Available(CTransactionRef &ref, size_t tx_count)
A mutable version of CTransaction.
std::vector< CTxOut > vout
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define NO_THREAD_SAFETY_ANALYSIS