mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
[refactor/bench] make mempool_stress bench reusable and parameterizable
This commit is contained in:
parent
35a31d5f7e
commit
cb1407196f
1 changed files with 16 additions and 9 deletions
|
@ -26,14 +26,8 @@ struct Available {
|
||||||
Available(CTransactionRef& ref, size_t tx_count) : ref(ref), tx_count(tx_count){}
|
Available(CTransactionRef& ref, size_t tx_count) : ref(ref), tx_count(tx_count){}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ComplexMemPool(benchmark::Bench& bench)
|
static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_rand, int childTxs, int min_ancestors)
|
||||||
{
|
{
|
||||||
int childTxs = 800;
|
|
||||||
if (bench.complexityN() > 1) {
|
|
||||||
childTxs = static_cast<int>(bench.complexityN());
|
|
||||||
}
|
|
||||||
|
|
||||||
FastRandomContext det_rand{true};
|
|
||||||
std::vector<Available> available_coins;
|
std::vector<Available> available_coins;
|
||||||
std::vector<CTransactionRef> ordered_coins;
|
std::vector<CTransactionRef> ordered_coins;
|
||||||
// Create some base transactions
|
// Create some base transactions
|
||||||
|
@ -58,8 +52,10 @@ static void ComplexMemPool(benchmark::Bench& bench)
|
||||||
size_t idx = det_rand.randrange(available_coins.size());
|
size_t idx = det_rand.randrange(available_coins.size());
|
||||||
Available coin = available_coins[idx];
|
Available coin = available_coins[idx];
|
||||||
uint256 hash = coin.ref->GetHash();
|
uint256 hash = coin.ref->GetHash();
|
||||||
// biased towards taking just one ancestor, but maybe more
|
// biased towards taking min_ancestors parents, 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);
|
size_t n_to_take = det_rand.randrange(2) == 0 ?
|
||||||
|
min_ancestors :
|
||||||
|
min_ancestors + det_rand.randrange(coin.ref->vout.size() - coin.vin_left);
|
||||||
for (size_t i = 0; i < n_to_take; ++i) {
|
for (size_t i = 0; i < n_to_take; ++i) {
|
||||||
tx.vin.emplace_back();
|
tx.vin.emplace_back();
|
||||||
tx.vin.back().prevout = COutPoint(hash, coin.vin_left++);
|
tx.vin.back().prevout = COutPoint(hash, coin.vin_left++);
|
||||||
|
@ -79,6 +75,17 @@ static void ComplexMemPool(benchmark::Bench& bench)
|
||||||
ordered_coins.emplace_back(MakeTransactionRef(tx));
|
ordered_coins.emplace_back(MakeTransactionRef(tx));
|
||||||
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
|
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
|
||||||
}
|
}
|
||||||
|
return ordered_coins;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ComplexMemPool(benchmark::Bench& bench)
|
||||||
|
{
|
||||||
|
FastRandomContext det_rand{true};
|
||||||
|
int childTxs = 800;
|
||||||
|
if (bench.complexityN() > 1) {
|
||||||
|
childTxs = static_cast<int>(bench.complexityN());
|
||||||
|
}
|
||||||
|
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 1);
|
||||||
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
|
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
|
||||||
CTxMemPool pool;
|
CTxMemPool pool;
|
||||||
LOCK2(cs_main, pool.cs);
|
LOCK2(cs_main, pool.cs);
|
||||||
|
|
Loading…
Add table
Reference in a new issue