10 #include <txmempool.h>
12 #include <validation.h>
36 std::vector<Available> available_coins;
37 std::vector<CTransactionRef> ordered_coins;
39 size_t tx_counter = 1;
40 for (
auto x = 0; x < 100; ++x) {
44 tx.
vin[0].scriptWitness.stack.push_back(
CScriptNum(x).getvch());
51 available_coins.emplace_back(ordered_coins.back(), tx_counter++);
53 for (
auto x = 0; x < childTxs && !available_coins.empty(); ++x) {
55 size_t n_ancestors = det_rand.
randrange(10)+1;
56 for (
size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
57 size_t idx = det_rand.
randrange(available_coins.size());
59 Txid hash = coin.
ref->GetHash();
61 size_t n_to_take = det_rand.
randrange(2) == 0 ?
64 for (
size_t i = 0; i < n_to_take; ++i) {
65 tx.
vin.emplace_back();
71 coin = available_coins.back();
72 available_coins.pop_back();
81 available_coins.emplace_back(ordered_coins.back(), tx_counter++);
93 std::vector<CTransactionRef> ordered_coins =
CreateOrderedCoins(det_rand, childTxs, 1);
94 const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
ChainType::MAIN);
98 for (
auto& tx : ordered_coins) {
109 auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(
ChainType::REGTEST, {
"-checkmempool=1"});
112 testing_setup->PopulateMempool(det_rand, 400,
true);
113 const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
117 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 ...
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.
CTransactionRef get(const uint256 &hash) const
size_t DynamicMemoryUsage() const
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
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
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
static void AddTx(const CTransactionRef &tx, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
static void MempoolCheck(benchmark::Bench &bench)
BENCHMARK(ComplexMemPool, benchmark::PriorityLevel::HIGH)
static std::vector< CTransactionRef > CreateOrderedCoins(FastRandomContext &det_rand, int childTxs, int min_ancestors)
static void ComplexMemPool(benchmark::Bench &bench)
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
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