Skip to content

Commit cb14071

Browse files
committed
[refactor/bench] make mempool_stress bench reusable and parameterizable
1 parent 35a31d5 commit cb14071

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/bench/mempool_stress.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@ struct Available {
2626
Available(CTransactionRef& ref, size_t tx_count) : ref(ref), tx_count(tx_count){}
2727
};
2828

29-
static void ComplexMemPool(benchmark::Bench& bench)
29+
static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_rand, int childTxs, int min_ancestors)
3030
{
31-
int childTxs = 800;
32-
if (bench.complexityN() > 1) {
33-
childTxs = static_cast<int>(bench.complexityN());
34-
}
35-
36-
FastRandomContext det_rand{true};
3731
std::vector<Available> available_coins;
3832
std::vector<CTransactionRef> ordered_coins;
3933
// Create some base transactions
@@ -58,8 +52,10 @@ static void ComplexMemPool(benchmark::Bench& bench)
5852
size_t idx = det_rand.randrange(available_coins.size());
5953
Available coin = available_coins[idx];
6054
uint256 hash = coin.ref->GetHash();
61-
// biased towards taking just one ancestor, but maybe more
62-
size_t n_to_take = det_rand.randrange(2) == 0 ? 1 : 1+det_rand.randrange(coin.ref->vout.size() - coin.vin_left);
55+
// biased towards taking min_ancestors parents, but maybe more
56+
size_t n_to_take = det_rand.randrange(2) == 0 ?
57+
min_ancestors :
58+
min_ancestors + det_rand.randrange(coin.ref->vout.size() - coin.vin_left);
6359
for (size_t i = 0; i < n_to_take; ++i) {
6460
tx.vin.emplace_back();
6561
tx.vin.back().prevout = COutPoint(hash, coin.vin_left++);
@@ -79,6 +75,17 @@ static void ComplexMemPool(benchmark::Bench& bench)
7975
ordered_coins.emplace_back(MakeTransactionRef(tx));
8076
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
8177
}
78+
return ordered_coins;
79+
}
80+
81+
static void ComplexMemPool(benchmark::Bench& bench)
82+
{
83+
FastRandomContext det_rand{true};
84+
int childTxs = 800;
85+
if (bench.complexityN() > 1) {
86+
childTxs = static_cast<int>(bench.complexityN());
87+
}
88+
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 1);
8289
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
8390
CTxMemPool pool;
8491
LOCK2(cs_main, pool.cs);

0 commit comments

Comments
 (0)