15#include <validation.h>
17#include <test/util/mining.h>
18#include <test/util/setup_common.h>
39 std::vector<CTxIn>
utxos;
42 for (
size_t i = 0; i < n; ++i) {
63static std::vector<CTransactionRef>
68 std::vector<CTransactionRef> chain = {
firstTx};
71 const COutPoint parent(chain.back()->GetId(), 0);
91 txs += std::pow(2, i);
95 std::vector<CTransactionRef> chain;
98 std::queue<CTransactionRef> queue;
100 auto tx =
toTx(config, std::move(
txin));
102 chain.emplace_back(tx);
120 chain.push_back(
txref);
124 queue.emplace(
txref);
132 const std::vector<CTransactionRef>
chainedTxs) {
137 assert(mempool.size() == 0);
161 std::vector<std::vector<CTransactionRef>>
chains;
162 for (
auto &utxo :
utxos) {
177 assert(mempool.size() == 0);
182 for (
const auto &chain :
chains) {
185 for (
const auto &tx : chain) {
186 mempool.addUnchecked(entry.FromTx(tx));
189 assert(mempool.size() == chain.size());
191 assert(mempool.size() == 0);
232 assert(mempool.size() == 0);
239 const std::vector<std::vector<CTransactionRef>> &
chains) {
249 for (
const auto &chain :
chains) {
251 for (
const auto &tx : chain) {
252 mempool.addUnchecked(entry.FromTx(tx));
262 .CreateNewBlock(dummy);
271 const std::vector<std::vector<CTransactionRef>> &
chains,
273 std::list<CTxMemPool>
pools;
279 bench.epochs(2).epochIterations(1);
295 for (
const auto &chain :
chains) {
300 for (
const auto &tx : chain) {
314 auto it =
pools.begin();
320 while (
auto prevSize = pool.size()) {
321 pool.TrimToSize(pool.DynamicMemoryUsage() * 99 / 100);
349 const std::vector<CTransactionRef>
chainedTxs =
359 const std::vector<CTransactionRef>
chainedTxs =
405 {oneInOneOutChain(config, std::move(utxo), 50)});
414 {oneInOneOutChain(config, std::move(utxo), 500)});
423 std::vector<std::vector<CTransactionRef>>
chains;
426 for (
int i = 0; i <
NChains; ++i) {
438 std::vector<std::vector<CTransactionRef>>
chains;
441 for (
int i = 0; i <
NChains; ++i) {
static constexpr Amount SATOSHI
static constexpr Amount COIN
static void benchEviction(const Config &, benchmark::Bench &bench, const std::vector< std::vector< CTransactionRef > > &chains, bool revFee=true)
static void EvictChained50Tx(benchmark::Bench &bench)
Fill a mempool then evict 2000 x 50 1-input-1-output transactions, CTxMemPool version,...
static void Reorg10BlocksWith500TxChain(benchmark::Bench &bench)
Try to reorg a chain of depth 10 where each block has a 500 tx 1-input-1-output chain.
static void MempoolAcceptance50ChainedTxs(benchmark::Bench &bench)
Tests a chain of 50 1-input-1-output transactions.
static void MempoolAcceptance511TxTree(benchmark::Bench &bench)
Test a tree of 511 2-inputs-1-output transactions.
static void MempoolAcceptance63TxTree(benchmark::Bench &bench)
Test a tree of 63 2-inputs-1-output transactions.
static void EvictChained50TxRev(benchmark::Bench &bench)
Fill a mempool then evict 2000 x 50 1-input-1-output transactions, CTxMemPool version,...
static void Reorg10BlocksWith500TxChainSkipMempool(benchmark::Bench &bench)
Try to reorg a chain of depth 10 where each block has a 500 tx 1-input-1-output chain,...
static void MempoolAcceptance500ChainedTxs(benchmark::Bench &bench)
Tests a chain of 500 1-input-1-output transactions.
static void benchGenerateNewBlock(const Config &config, node::NodeContext &node, benchmark::Bench &bench, const std::vector< std::vector< CTransactionRef > > &chains)
static void GenerateBlock50ChainedTxs(benchmark::Bench &bench)
Generate a block with 50 1-input-1-output transactions.
static void Reorg10BlocksWith50TxChain(benchmark::Bench &bench)
Try to reorg a chain of depth 10 where each block has a 50 tx 1-input-1-output chain.
static void benchReorg(const Config &config, node::NodeContext &node, benchmark::Bench &bench, size_t reorgDepth, size_t chainSizePerBlock, bool includeMempoolTxRemoval)
Run benchmark that reorganizes blocks with one-input-one-output transaction chains in them.
static const CScript REDEEM_SCRIPT
This file contains benchmarks focusing on chained transactions in the mempool.
static std::vector< CTxIn > createUTXOs(const Config &config, size_t n, node::NodeContext &node)
Mine new utxos.
static void GenerateBlock500ChainedTxs(benchmark::Bench &bench)
Generate a block with 500 1-input-1-output transactions.
static std::vector< CTransactionRef > twoInOneOutTree(const Config &config, node::NodeContext &node, const size_t treeDepth)
Creates a tree of transactions with 2-inputs-1-output.
static std::vector< CTransactionRef > oneInOneOutChain(const Config &config, CTxIn utxo, const size_t chainLength)
Creates a chain of transactions with 1-input-1-output.
static const CScript SCRIPT_PUB_KEY
static void Reorg10BlocksWith50TxChainSkipMempool(benchmark::Bench &bench)
Try to reorg a chain of depth 10 where each block has a 50 tx 1-input-1-output chain,...
static CTransactionRef toTx(const Config &config, CTxIn txin)
Create a transaction spending a coinbase utxo.
static const CScript SCRIPT_SIG
static void benchATMP(node::NodeContext &node, benchmark::Bench &bench, const std::vector< CTransactionRef > chainedTxs)
Run benchmark on AcceptToMemoryPool.
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
A mutable version of CTransaction.
std::vector< CTxOut > vout
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
An input of a transaction.
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 check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(CTxMemPoolEntryRef entry) EXCLUSIVE_LOCKS_REQUIRED(cs
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
unsigned long size() const
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Main entry point to nanobench's benchmarking facility.
Generate a new block, without valid proof-of-work.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule).
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::vector< uint8_t > ToByteVector(const T &in)
Validation result for a transaction evaluated by MemPoolAccept (single or package).
const ResultType m_result_type
Result type.
@ VALID
Fully validated, valid.
Options struct containing options for constructing a CTxMemPool.
int check_ratio
The ratio used to determine how often sanity checks will run.
NodeContext struct containing references to chain state and connection state.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept, unsigned int heightOverride)
Try to add a transaction to the mempool.