bench: Destroy wallet txs instead of leaking their memory

This commit is contained in:
MarcoFalke 2018-11-27 16:53:49 -05:00
parent 600b85bb41
commit fa5cef0f78
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 15 additions and 18 deletions

View file

@ -4,25 +4,19 @@
#include <bench/bench.h> #include <bench/bench.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <wallet/wallet.h>
#include <wallet/coinselection.h> #include <wallet/coinselection.h>
#include <wallet/wallet.h>
#include <set> #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; static int nextLockTime = 0;
CMutableTransaction tx; CMutableTransaction tx;
tx.nLockTime = nextLockTime++; // so all transactions get different hashes tx.nLockTime = nextLockTime++; // so all transactions get different hashes
tx.vout.resize(nInput + 1); tx.vout.resize(1);
tx.vout[nInput].nValue = nValue; tx.vout[0].nValue = nValue;
CWalletTx* wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx))); wtxs.push_back(MakeUnique<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);
} }
// Simple benchmark for wallet coin selection. Note that it maybe be necessary // Simple benchmark for wallet coin selection. Note that it maybe be necessary
@ -36,14 +30,21 @@ static void CoinSelection(benchmark::State& state)
{ {
auto chain = interfaces::MakeChain(); auto chain = interfaces::MakeChain();
const CWallet wallet(*chain, WalletLocation(), WalletDatabase::CreateDummy()); const CWallet wallet(*chain, WalletLocation(), WalletDatabase::CreateDummy());
std::vector<std::unique_ptr<CWalletTx>> wtxs;
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
// Add coins. // Add coins.
std::vector<OutputGroup> groups;
for (int i = 0; i < 1000; ++i) { 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 CoinEligibilityFilter filter_standard(1, 6, 0);
const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0); const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0);

View file

@ -1,7 +1,3 @@
# Suppress warnings about addCoin(...) leak in the CoinSelection benchmark
leak:addCoin
leak:bench_bitcoin
# Suppress warnings triggered in dependencies # Suppress warnings triggered in dependencies
leak:libcrypto leak:libcrypto
leak:libqminimal leak:libqminimal