|
| 1 | +// Copyright (c) 2020 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 | + |
| 7 | +#include <amount.h> |
| 8 | +#include <net.h> |
| 9 | +#include <net_processing.h> |
| 10 | +#include <primitives/transaction.h> |
| 11 | +#include <random.h> |
| 12 | +#include <script/script.h> |
| 13 | +#include <sync.h> |
| 14 | + |
| 15 | +#include <vector> |
| 16 | + |
| 17 | +static constexpr CAmount CENT{1000000}; |
| 18 | +extern bool AddOrphanTx(const CTransactionRef& tx, NodeId peer); |
| 19 | +extern unsigned int EvictOrphanTxs(unsigned int nMaxOrphans); |
| 20 | + |
| 21 | +static void OrphanTxPool(benchmark::State& state) |
| 22 | +{ |
| 23 | + FastRandomContext rand; |
| 24 | + std::vector<CTransactionRef> txs; |
| 25 | + for (unsigned int i = 0; i < DEFAULT_MAX_ORPHAN_TRANSACTIONS; ++i) { |
| 26 | + CMutableTransaction tx; |
| 27 | + tx.vin.resize(1); |
| 28 | + tx.vin[0].prevout.n = 0; |
| 29 | + tx.vin[0].prevout.hash = rand.rand256(); |
| 30 | + tx.vin[0].scriptSig << OP_1; |
| 31 | + tx.vout.resize(1); |
| 32 | + tx.vout[0].nValue = 1 * CENT; |
| 33 | + tx.vout[0].scriptPubKey << OP_1; |
| 34 | + txs.emplace_back(MakeTransactionRef(tx)); |
| 35 | + } |
| 36 | + |
| 37 | + LOCK(g_cs_orphans); |
| 38 | + while (state.KeepRunning()) { |
| 39 | + for (const auto& tx : txs) { |
| 40 | + AddOrphanTx(tx, 0); |
| 41 | + } |
| 42 | + EvictOrphanTxs(0); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +BENCHMARK(OrphanTxPool, 10000); |
0 commit comments