aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShorya <shoryak@iitk.ac.in>2021-09-01 22:00:05 +0530
committerShorya <shoryak@iitk.ac.in>2021-09-04 18:17:43 +0530
commit29e983386b0aecf99cdb7d0e08ba6b450bed313e (patch)
tree3335c99d24695a2882068313dc3d221e82e0f892 /src
parent83daf47898f8a79cb20d20316c64becd564cf54c (diff)
Fixes Bug in Transaction generation in ComplexMempool benchmark
Available in line 59 is made a reference , so contents of the coin can be modified While generating transactions we select ancestors from available_coins ,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 by ,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. Code generating outputs for the transaction is moved out of the loop, as it needs to be done only once before adding the transaction to ordered_coins
Diffstat (limited to 'src')
-rw-r--r--src/bench/mempool_stress.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/bench/mempool_stress.cpp b/src/bench/mempool_stress.cpp
index f28768efc8..653a2630fc 100644
--- a/src/bench/mempool_stress.cpp
+++ b/src/bench/mempool_stress.cpp
@@ -56,7 +56,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
size_t n_ancestors = det_rand.randrange(10)+1;
for (size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
size_t idx = det_rand.randrange(available_coins.size());
- Available coin = available_coins[idx];
+ Available& coin = available_coins[idx];
uint256 hash = coin.ref->GetHash();
// biased towards taking just one ancestor, but maybe more
size_t n_to_take = det_rand.randrange(2) == 0 ? 1 : 1+det_rand.randrange(coin.ref->vout.size() - coin.vin_left);
@@ -66,15 +66,17 @@ static void ComplexMemPool(benchmark::Bench& bench)
tx.vin.back().scriptSig = CScript() << coin.tx_count;
tx.vin.back().scriptWitness.stack.push_back(CScriptNum(coin.tx_count).getvch());
}
- if (coin.vin_left == coin.ref->vin.size()) {
- coin = available_coins.back();
+ if (coin.vin_left == coin.ref->vout.size()) {
+ if(available_coins.size()-1!=idx){ // if idx is not the last index swap it with the end index
+ std::swap(available_coins[idx], available_coins.back());
+ }
available_coins.pop_back();
}
- tx.vout.resize(det_rand.randrange(10)+2);
- for (auto& out : tx.vout) {
- out.scriptPubKey = CScript() << CScriptNum(tx_counter) << OP_EQUAL;
- out.nValue = 10 * COIN;
- }
+ }
+ tx.vout.resize(det_rand.randrange(10)+2);
+ for (auto& out : tx.vout) {
+ out.scriptPubKey = CScript() << CScriptNum(tx_counter) << OP_EQUAL;
+ out.nValue = 10 * COIN;
}
ordered_coins.emplace_back(MakeTransactionRef(tx));
available_coins.emplace_back(ordered_coins.back(), tx_counter++);