30 for (
unsigned int i = 0; i < num_inputs; ++i) {
48 for (
unsigned int i{start_input}; i < start_input + num_inputs; ++i) {
50 tx.
vin.emplace_back(inputs.at(i % inputs.size()));
63 std::vector<CTransactionRef> tiny_txs;
64 tiny_txs.reserve(NUM_TINY_TRANSACTIONS);
65 for (
unsigned int i{0}; i < NUM_TINY_TRANSACTIONS; ++i) {
77 int64_t total_weight_to_add{0};
78 for (
unsigned int txindex{0}; txindex < NUM_TINY_TRANSACTIONS; ++txindex) {
79 const auto& tx{tiny_txs.at(txindex)};
82 if (total_weight_to_add > orphanage->MaxGlobalUsage())
break;
84 assert(orphanage->AddTx(tx, peer));
87 assert(txindex < NUM_TINY_TRANSACTIONS - 1);
92 assert(orphanage->TotalOrphanUsage() <= orphanage->MaxGlobalUsage());
93 assert(orphanage->TotalLatencyScore() <= orphanage->MaxGlobalLatencyScore());
98 const auto num_announcements_before_trim{orphanage->CountAnnouncements()};
99 assert(orphanage->AddTx(large_tx, peer));
102 const auto num_announcements_after_trim{orphanage->CountAnnouncements()};
103 const auto num_evicted{num_announcements_before_trim - num_announcements_after_trim};
113 static constexpr unsigned int NUM_PEERS{39};
119 static_assert(LARGE_TX_WEIGHT >=
TINY_TX_WEIGHT * 2,
"Tx is too small, increase NUM_PEERS");
125 std::vector<CTransactionRef> shared_txs;
126 shared_txs.reserve(NUM_UNIQUE_TXNS);
127 for (
unsigned int i{0}; i < NUM_UNIQUE_TXNS; ++i) {
130 std::vector<size_t> indexes;
131 indexes.resize(NUM_UNIQUE_TXNS);
132 std::iota(indexes.begin(), indexes.end(), 0);
138 static_assert(NUM_UNIQUE_TXNS <= NUM_PEERS * 2);
141 for (
unsigned int i{0}; i < NUM_UNIQUE_TXNS; ++i) {
142 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
144 CTransactionRef reserved_second_to_last_tx{peer < NUM_UNIQUE_TXNS - NUM_PEERS ? shared_txs.at(peer + NUM_PEERS) :
nullptr};
146 const auto& tx{shared_txs.at(indexes.at(i))};
147 if (tx == reserved_last_tx) {
149 }
else if (reserved_second_to_last_tx && tx == reserved_second_to_last_tx) {
152 orphanage->AddTx(tx, peer);
158 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
160 CTransactionRef reserved_second_to_last_tx{peer < NUM_UNIQUE_TXNS - NUM_PEERS ? shared_txs.at(peer + NUM_PEERS) :
nullptr};
162 if (reserved_second_to_last_tx) {
163 orphanage->AddTx(reserved_second_to_last_tx, peer);
165 orphanage->AddTx(reserved_last_tx, peer);
168 assert(orphanage->CountAnnouncements() == NUM_PEERS * NUM_UNIQUE_TXNS);
169 const auto total_usage{orphanage->TotalOrphanUsage()};
170 const auto max_usage{orphanage->MaxGlobalUsage()};
171 assert(max_usage - total_usage <= LARGE_TX_WEIGHT);
172 assert(orphanage->TotalLatencyScore() <= orphanage->MaxGlobalLatencyScore());
177 const auto num_announcements_before_trim{orphanage->CountAnnouncements()};
179 assert(orphanage->AddTx(last_tx, 0));
182 const auto num_evicted{num_announcements_before_trim - orphanage->CountAnnouncements() + 1};
185 assert(num_evicted >= (NUM_UNIQUE_TXNS - 2) * NUM_PEERS);
198 block.
vtx.push_back(block_tx);
201 constexpr unsigned int INPUTS_PER_TX{9};
202 constexpr unsigned int NUM_PEERS{125};
206 constexpr unsigned int INPUTS_PER_PEER = NUM_BLOCK_INPUTS / NUM_PEERS;
207 static_assert(INPUTS_PER_PEER > 0);
210 static_assert(7 * NUM_TXNS_PER_PEER + INPUTS_PER_TX - 1 >= INPUTS_PER_PEER);
212 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
216 const unsigned int start_input = peer * INPUTS_PER_PEER + txnum * 7;
223 assert(!orphanage->HaveTx(ptx->GetWitnessHash()));
224 assert(orphanage->AddTx(ptx, peer));
232 assert(orphanage->TotalLatencyScore() <= orphanage->MaxGlobalLatencyScore());
233 assert(orphanage->TotalOrphanUsage() <= orphanage->MaxGlobalUsage());
237 assert(orphanage->CountAnnouncements() == NUM_PEERS * NUM_TXNS_PER_PEER);
238 assert(orphanage->TotalLatencyScore() == orphanage->CountAnnouncements());
241 if (block_or_disconnect) {
244 orphanage->EraseForBlock(block);
245 assert(orphanage->CountAnnouncements() == 0);
248 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
249 orphanage->EraseForPeer(peer);
251 assert(orphanage->CountAnnouncements() == 0);
static CTransactionRef MakeTransactionSpendingUpTo(const std::vector< CTxIn > &inputs, unsigned int start_input, unsigned int num_inputs, int64_t weight_limit)
static void OrphanageEraseForPeer(benchmark::Bench &bench)
static void OrphanageEraseForBlock(benchmark::Bench &bench)
static CTransactionRef MakeTransactionBulkedTo(unsigned int num_inputs, int64_t target_weight, FastRandomContext &det_rand)
static void OrphanageEraseAll(benchmark::Bench &bench, bool block_or_disconnect)
static constexpr node::TxOrphanage::Usage TINY_TX_WEIGHT
BENCHMARK(OrphanageSinglePeerEviction, benchmark::PriorityLevel::LOW)
static constexpr int64_t APPROX_WEIGHT_PER_INPUT
static void OrphanageSinglePeerEviction(benchmark::Bench &bench)
static void OrphanageMultiPeerEviction(benchmark::Bench &bench)
std::vector< CTransactionRef > vtx
uint256 rand256() noexcept
generate a random uint256.
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 & epochs(size_t numEpochs) noexcept
Controls number of epochs, the number of measurements to perform.
Bench & epochIterations(uint64_t numIters) noexcept
Sets exactly the number of iterations for each epoch.
static transaction_identifier FromUint256(const uint256 &id)
static int32_t GetTransactionWeight(const CTransaction &tx)
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
std::unique_ptr< TxOrphanage > MakeTxOrphanage() noexcept
Create a new TxOrphanage instance.
static constexpr unsigned int DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE
Default value for TxOrphanage::m_max_global_latency_score.
static constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER
Default value for TxOrphanage::m_reserved_usage_per_peer.
static constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
A mutable version of CTransaction.
std::vector< CTxOut > vout
#define NO_THREAD_SAFETY_ANALYSIS
void BulkTransaction(CMutableTransaction &tx, int32_t target_weight)