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);
119 pool.TrimToSize(0,
nullptr);
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);
159 pool.removeForBlock(tx_remove_for_block, 100);
160 for (
auto& tx: tx_remove_for_block) {
161 AddTx(tx, pool, det_rand);
163 pool.UpdateTransactionsFromBlock(hashes_remove_for_block);
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);
190 pool.CalculateDescendants({first_tx}, dummy);
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);
std::shared_ptr< const CTransaction > CTransactionRef
#define NO_THREAD_SAFETY_ANALYSIS
static void MemPoolAddTransactions(benchmark::Bench &bench)
static std::vector< CTransactionRef > CreateCoinCluster(FastRandomContext &det_rand, int childTxs, int min_ancestors)
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Bench & complexityN(T n) noexcept
std::set< txiter, CompareIteratorByHash > setEntries
CTransactionRef get(const Txid &hash) const
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Available(CTransactionRef &ref, size_t tx_count)
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
std::vector< unsigned char > getvch() const
static void MempoolCheck(benchmark::Bench &bench)
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
BENCHMARK(MemPoolAncestorsDescendants)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Serialized script, used inside transaction inputs and outputs.
static transaction_identifier FromUint256(const uint256 &id)
static void ComplexMemPool(benchmark::Bench &bench)
uint256 GetRandHash() noexcept
Generate a random uint256.
TryAddToMempool(pool, CTxMemPoolEntry(tx, det_rand.randrange(10000)+1000, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
static void AddTx(const CTransactionRef &tx, CTxMemPool &pool, FastRandomContext &det_rand) EXCLUSIVE_LOCKS_REQUIRED(cs_main
static void MemPoolAncestorsDescendants(benchmark::Bench &bench)
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
A mutable version of CTransaction.
Main entry point to nanobench's benchmarking facility.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
static constexpr CAmount COIN
The amount of satoshis in one BTC.