mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
partial Merge #14822: bench: Destroy wallet txs instead of leaking their memory
fa5cef0f78 bench: Destroy wallet txs instead of leaking their memory (MarcoFalke) Pull request description: This should destroy the wallet txs when the benchmark ends to avoid having to hold them when the following benchmarks run. Tree-SHA512: e2510946e6a47fad3ec5fb28d298df8ddc2e017455fcff777fa7bbc12d801c08739db6a7a7289509aaa881ccdc59dfff9bcb6772b48db2c457d3787081a46c06
This commit is contained in:
parent
2833db6e0b
commit
500dfdb31a
@ -3,25 +3,19 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <bench/bench.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <wallet/coinselection.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<OutputGroup>& groups)
|
||||
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
|
||||
{
|
||||
int nInput = 0;
|
||||
|
||||
static int nextLockTime = 0;
|
||||
CMutableTransaction tx;
|
||||
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
|
||||
tx.vout.resize(nInput + 1);
|
||||
tx.vout[nInput].nValue = nValue;
|
||||
CWalletTx* wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx)));
|
||||
|
||||
int nAge = 6 * 24;
|
||||
COutput output(wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
|
||||
groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0);
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].nValue = nValue;
|
||||
wtxs.push_back(MakeUnique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))));
|
||||
}
|
||||
|
||||
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
|
||||
@ -34,14 +28,21 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<Ou
|
||||
static void CoinSelection(benchmark::Bench& bench)
|
||||
{
|
||||
const CWallet wallet(WalletLocation(), WalletDatabase::CreateDummy());
|
||||
std::vector<std::unique_ptr<CWalletTx>> wtxs;
|
||||
LOCK(wallet.cs_wallet);
|
||||
|
||||
// Add coins.
|
||||
std::vector<OutputGroup> groups;
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
addCoin(1000 * COIN, wallet, groups);
|
||||
addCoin(1000 * COIN, wallet, wtxs);
|
||||
}
|
||||
addCoin(3 * COIN, wallet, wtxs);
|
||||
|
||||
// Create groups
|
||||
std::vector<OutputGroup> groups;
|
||||
for (const auto& wtx : wtxs) {
|
||||
COutput output(wtx.get(), 0 /* iIn */, 6 * 24 /* nDepthIn */, true /* spendable */, true /* solvable */, true /* safe */);
|
||||
groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0);
|
||||
}
|
||||
addCoin(3 * COIN, wallet, groups);
|
||||
const CoinEligibilityFilter filter_standard(1, 6, 0);
|
||||
const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0);
|
||||
bench.run([&] {
|
||||
|
Loading…
Reference in New Issue
Block a user