35 for (
unsigned int i = 0; i < num_inputs; ++i) {
53 for (
unsigned int i{start_input}; i < start_input + num_inputs; ++i) {
55 tx.
vin.emplace_back(inputs.at(i % inputs.size()));
68 std::vector<CTransactionRef> tiny_txs;
69 tiny_txs.reserve(NUM_TINY_TRANSACTIONS);
70 for (
unsigned int i{0}; i < NUM_TINY_TRANSACTIONS; ++i) {
82 int64_t total_weight_to_add{0};
83 for (
unsigned int txindex{0}; txindex < NUM_TINY_TRANSACTIONS; ++txindex) {
84 const auto& tx{tiny_txs.at(txindex)};
87 if (total_weight_to_add > orphanage->MaxGlobalUsage())
break;
89 assert(orphanage->AddTx(tx, peer));
92 assert(txindex < NUM_TINY_TRANSACTIONS - 1);
97 assert(orphanage->TotalOrphanUsage() <= orphanage->MaxGlobalUsage());
98 assert(orphanage->TotalLatencyScore() <= orphanage->MaxGlobalLatencyScore());
103 const auto num_announcements_before_trim{orphanage->CountAnnouncements()};
104 assert(orphanage->AddTx(large_tx, peer));
107 const auto num_announcements_after_trim{orphanage->CountAnnouncements()};
108 const auto num_evicted{num_announcements_before_trim - num_announcements_after_trim};
118 static constexpr unsigned int NUM_PEERS{39};
124 static_assert(LARGE_TX_WEIGHT >=
TINY_TX_WEIGHT * 2,
"Tx is too small, increase NUM_PEERS");
130 std::vector<CTransactionRef> shared_txs;
131 shared_txs.reserve(NUM_UNIQUE_TXNS);
132 for (
unsigned int i{0}; i < NUM_UNIQUE_TXNS; ++i) {
135 std::vector<size_t> indexes;
136 indexes.resize(NUM_UNIQUE_TXNS);
137 std::iota(indexes.begin(), indexes.end(), 0);
143 static_assert(NUM_UNIQUE_TXNS <= NUM_PEERS * 2);
146 for (
unsigned int i{0}; i < NUM_UNIQUE_TXNS; ++i) {
147 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
149 CTransactionRef reserved_second_to_last_tx{peer < NUM_UNIQUE_TXNS - NUM_PEERS ? shared_txs.at(peer + NUM_PEERS) :
nullptr};
151 const auto& tx{shared_txs.at(indexes.at(i))};
152 if (tx == reserved_last_tx) {
154 }
else if (reserved_second_to_last_tx && tx == reserved_second_to_last_tx) {
157 orphanage->AddTx(tx, peer);
163 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
165 CTransactionRef reserved_second_to_last_tx{peer < NUM_UNIQUE_TXNS - NUM_PEERS ? shared_txs.at(peer + NUM_PEERS) :
nullptr};
167 if (reserved_second_to_last_tx) {
168 orphanage->AddTx(reserved_second_to_last_tx, peer);
170 orphanage->AddTx(reserved_last_tx, peer);
173 assert(orphanage->CountAnnouncements() == NUM_PEERS * NUM_UNIQUE_TXNS);
174 const auto total_usage{orphanage->TotalOrphanUsage()};
175 const auto max_usage{orphanage->MaxGlobalUsage()};
176 assert(max_usage - total_usage <= LARGE_TX_WEIGHT);
177 assert(orphanage->TotalLatencyScore() <= orphanage->MaxGlobalLatencyScore());
182 const auto num_announcements_before_trim{orphanage->CountAnnouncements()};
184 assert(orphanage->AddTx(last_tx, 0));
187 const auto num_evicted{num_announcements_before_trim - orphanage->CountAnnouncements() + 1};
190 assert(num_evicted >= (NUM_UNIQUE_TXNS - 2) * NUM_PEERS);
203 block.
vtx.push_back(block_tx);
206 constexpr unsigned int INPUTS_PER_TX{9};
207 constexpr unsigned int NUM_PEERS{125};
211 constexpr unsigned int INPUTS_PER_PEER = NUM_BLOCK_INPUTS / NUM_PEERS;
212 static_assert(INPUTS_PER_PEER > 0);
215 static_assert(7 * NUM_TXNS_PER_PEER + INPUTS_PER_TX - 1 >= INPUTS_PER_PEER);
217 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
221 const unsigned int start_input = peer * INPUTS_PER_PEER + txnum * 7;
228 assert(!orphanage->HaveTx(ptx->GetWitnessHash()));
229 assert(orphanage->AddTx(ptx, peer));
237 assert(orphanage->TotalLatencyScore() <= orphanage->MaxGlobalLatencyScore());
238 assert(orphanage->TotalOrphanUsage() <= orphanage->MaxGlobalUsage());
242 assert(orphanage->CountAnnouncements() == NUM_PEERS * NUM_TXNS_PER_PEER);
243 assert(orphanage->TotalLatencyScore() == orphanage->CountAnnouncements());
246 if (block_or_disconnect) {
249 orphanage->EraseForBlock(block);
250 assert(orphanage->CountAnnouncements() == 0);
253 for (
NodeId peer{0}; peer < NUM_PEERS; ++peer) {
254 orphanage->EraseForPeer(peer);
256 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)
BENCHMARK(OrphanageSinglePeerEviction)
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
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)