Skip to content

Commit abc26fa

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22856: test: Fix bug in transaction generation in ComplexMempool benchmark
29e9833 Fixes Bug in Transaction generation in ComplexMempool benchmark (Shorya) Pull request description: This fixes issues with `ComplexMempool` benchmark introduced in [#17292](bitcoin/bitcoin#17292) , this stress test benchmarks performance of ancestor and descendant tracking of mempool graph algorithms on a complex Mempool. This Benchmark first creates 100 base transactions and stores them in `available_coins` vector. `available_coins` is used for selecting ancestor transactions while creating 800 new transactions. For this a random transaction is picked from `available_coins` and some of its outputs are mapped to the inputs of the new transaction being created. Now in case we exhaust all the outputs of an entry in `available_coins` then we need to remove it from `available_coins` before the next iteration of choosing a potential ancestor , it is now implemented with this patch. As the index of the entry is randomly chosen from `available_coins` , In order to remove it from the vector , if index of the selected entry is not at the end of `available_coins` vector , it is swapped with the entry at the back of the vector , then the entry at the end of `available_coins` is popped out. Earlier the code responsible for constructing outputs of the newly created transaction was inside the loop used for assigning ancestors to the transaction , which does some unnecessary work as it creates outputs of the transaction again and again , now it is moved out of the loop so outputs of the transaction are created just once before adding it to the final list of the transactions created. This one is a minor change to save some computation. These changes have changed the `ComplexMempool` benchmark results on `bitcoin:master` as follows : **Before** > | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 232,881,625.00 | 4.29 | 0.7% | 2.55 | `ComplexMemPool` **After** > | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 497,275,135.00 | 2.01 | 0.5% | 5.49 | `ComplexMemPool` Top commit has no ACKs. Tree-SHA512: d6946d7e65c55f54c84cc49d7abee52e59ffc8b7668b3c80b4ce15a57690ab00a600c6241cc71a2a075def9c30792a311256fed325ef162f37aeacd2cce93624
2 parents e457513 + 29e9833 commit abc26fa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/bench/mempool_stress.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_ra
5151
size_t n_ancestors = det_rand.randrange(10)+1;
5252
for (size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
5353
size_t idx = det_rand.randrange(available_coins.size());
54-
Available coin = available_coins[idx];
54+
Available& coin = available_coins[idx];
5555
uint256 hash = coin.ref->GetHash();
5656
// biased towards taking min_ancestors parents, but maybe more
5757
size_t n_to_take = det_rand.randrange(2) == 0 ?
@@ -63,15 +63,17 @@ static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_ra
6363
tx.vin.back().scriptSig = CScript() << coin.tx_count;
6464
tx.vin.back().scriptWitness.stack.push_back(CScriptNum(coin.tx_count).getvch());
6565
}
66-
if (coin.vin_left == coin.ref->vin.size()) {
67-
coin = available_coins.back();
66+
if (coin.vin_left == coin.ref->vout.size()) {
67+
if(available_coins.size()-1!=idx){ // if idx is not the last index swap it with the end index
68+
std::swap(available_coins[idx], available_coins.back());
69+
}
6870
available_coins.pop_back();
6971
}
70-
tx.vout.resize(det_rand.randrange(10)+2);
71-
for (auto& out : tx.vout) {
72-
out.scriptPubKey = CScript() << CScriptNum(tx_counter) << OP_EQUAL;
73-
out.nValue = 10 * COIN;
74-
}
72+
}
73+
tx.vout.resize(det_rand.randrange(10)+2);
74+
for (auto& out : tx.vout) {
75+
out.scriptPubKey = CScript() << CScriptNum(tx_counter) << OP_EQUAL;
76+
out.nValue = 10 * COIN;
7577
}
7678
ordered_coins.emplace_back(MakeTransactionRef(tx));
7779
available_coins.emplace_back(ordered_coins.back(), tx_counter++);

0 commit comments

Comments
 (0)