Skip to content

Commit 60b20c8

Browse files
author
MarcoFalke
committed
Merge #14822: bench: Destroy wallet txs instead of leaking their memory
fa5cef0 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
2 parents 0a452d0 + fa5cef0 commit 60b20c8

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/bench/coin_selection.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44

55
#include <bench/bench.h>
66
#include <interfaces/chain.h>
7-
#include <wallet/wallet.h>
87
#include <wallet/coinselection.h>
8+
#include <wallet/wallet.h>
99

1010
#include <set>
1111

12-
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<OutputGroup>& groups)
12+
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
1313
{
14-
int nInput = 0;
15-
1614
static int nextLockTime = 0;
1715
CMutableTransaction tx;
1816
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
19-
tx.vout.resize(nInput + 1);
20-
tx.vout[nInput].nValue = nValue;
21-
CWalletTx* wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx)));
22-
23-
int nAge = 6 * 24;
24-
COutput output(wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
25-
groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0);
17+
tx.vout.resize(1);
18+
tx.vout[0].nValue = nValue;
19+
wtxs.push_back(MakeUnique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))));
2620
}
2721

2822
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
@@ -36,14 +30,21 @@ static void CoinSelection(benchmark::State& state)
3630
{
3731
auto chain = interfaces::MakeChain();
3832
const CWallet wallet(*chain, WalletLocation(), WalletDatabase::CreateDummy());
33+
std::vector<std::unique_ptr<CWalletTx>> wtxs;
3934
LOCK(wallet.cs_wallet);
4035

4136
// Add coins.
42-
std::vector<OutputGroup> groups;
4337
for (int i = 0; i < 1000; ++i) {
44-
addCoin(1000 * COIN, wallet, groups);
38+
addCoin(1000 * COIN, wallet, wtxs);
39+
}
40+
addCoin(3 * COIN, wallet, wtxs);
41+
42+
// Create groups
43+
std::vector<OutputGroup> groups;
44+
for (const auto& wtx : wtxs) {
45+
COutput output(wtx.get(), 0 /* iIn */, 6 * 24 /* nDepthIn */, true /* spendable */, true /* solvable */, true /* safe */);
46+
groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0);
4547
}
46-
addCoin(3 * COIN, wallet, groups);
4748

4849
const CoinEligibilityFilter filter_standard(1, 6, 0);
4950
const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0);

test/sanitizer_suppressions/lsan

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Suppress warnings about addCoin(...) leak in the CoinSelection benchmark
2-
leak:addCoin
3-
leak:bench_bitcoin
4-
51
# Suppress warnings triggered in dependencies
62
leak:libcrypto
73
leak:libqminimal

0 commit comments

Comments
 (0)