Skip to content

Commit b330f3f

Browse files
author
MarcoFalke
committed
Merge #13563: bench: Simplify CoinSelection
c2e4fc8 bench: Simplify CoinSelection (João Barbosa) Pull request description: Closes #13549. As pointed by @MarcoFalke: - `SelectCoinsMinConf` should always succeed as there are enough coins in the wallet. - Removed creating the coins in the wallet. Tree-SHA512: 965c363bcaf0ca7a1dec35b5cf4866abcf190c53eb7012dc4aeb4d29830f13a7465644bfb5a47f6ea3eaa86e4d4a57fe41e7b2593bf5094b76a551c4c71625bb
2 parents c93c360 + c2e4fc8 commit b330f3f

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/bench/coin_selection.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,25 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<CO
3434
static void CoinSelection(benchmark::State& state)
3535
{
3636
const CWallet wallet("dummy", WalletDatabase::CreateDummy());
37-
std::vector<COutput> vCoins;
3837
LOCK(wallet.cs_wallet);
3938

40-
while (state.KeepRunning()) {
41-
// Add coins.
42-
for (int i = 0; i < 1000; i++)
43-
addCoin(1000 * COIN, wallet, vCoins);
44-
addCoin(3 * COIN, wallet, vCoins);
39+
// Add coins.
40+
std::vector<COutput> vCoins;
41+
for (int i = 0; i < 1000; ++i) {
42+
addCoin(1000 * COIN, wallet, vCoins);
43+
}
44+
addCoin(3 * COIN, wallet, vCoins);
4545

46+
const CoinEligibilityFilter filter_standard(1, 6, 0);
47+
const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0);
48+
while (state.KeepRunning()) {
4649
std::set<CInputCoin> setCoinsRet;
4750
CAmount nValueRet;
4851
bool bnb_used;
49-
CoinEligibilityFilter filter_standard(1, 6, 0);
50-
CoinSelectionParams coin_selection_params(false, 34, 148, CFeeRate(0), 0);
51-
bool success = wallet.SelectCoinsMinConf(1003 * COIN, filter_standard, vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used)
52-
|| wallet.SelectCoinsMinConf(1003 * COIN, filter_standard, vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used);
52+
bool success = wallet.SelectCoinsMinConf(1003 * COIN, filter_standard, vCoins, setCoinsRet, nValueRet, coin_selection_params, bnb_used);
5353
assert(success);
5454
assert(nValueRet == 1003 * COIN);
5555
assert(setCoinsRet.size() == 2);
56-
57-
// Empty wallet.
58-
for (COutput& output : vCoins) {
59-
delete output.tx;
60-
}
61-
vCoins.clear();
6256
}
6357
}
6458

0 commit comments

Comments
 (0)