Skip to content

Commit 9552dfb

Browse files
committed
Merge #12694: Actually disable BnB when there are preset inputs
081bf54 Test that BnB is not used when there are preset inputs (Andrew Chow) 6ef9982 Actually disable BnB when there are preset inputs (Andrew Chow) Pull request description: We don't want to use BnB when there are preset inputs because there is some weirdness with making that work with using the KnapsackSolver as the fallback. Currently we say that we haven't used bnb when there are preset inputs, but we don't actually disable BnB. This fixes that. I thought this was done originally. I guess it got lost in a rebase somewhere. Tree-SHA512: 9792c0cdd0736866bddbed20f10b8050104955dc589fba49a0bd61a582ba491c921af2cdcc2269678b7b69275dad5fcf89c71b75c28733c7bacbe52e55891b9c
2 parents f686002 + 081bf54 commit 9552dfb

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "wallet/wallet.h"
66
#include "wallet/coinselection.h"
7+
#include "wallet/coincontrol.h"
78
#include "amount.h"
89
#include "primitives/transaction.h"
910
#include "random.h"
@@ -27,7 +28,7 @@ std::vector<std::unique_ptr<CWalletTx>> wtxn;
2728
typedef std::set<CInputCoin> CoinSet;
2829

2930
static std::vector<COutput> vCoins;
30-
static const CWallet testWallet("dummy", CWalletDBWrapper::CreateDummy());
31+
static CWallet testWallet("dummy", CWalletDBWrapper::CreateDummy());
3132
static CAmount balance = 0;
3233

3334
CoinEligibilityFilter filter_standard(1, 6, 0);
@@ -72,6 +73,7 @@ static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = fa
7273
}
7374
COutput output(wtx.get(), nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
7475
vCoins.push_back(output);
76+
testWallet.AddToWallet(*wtx.get());
7577
wtxn.emplace_back(std::move(wtx));
7678
}
7779

@@ -222,6 +224,18 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
222224
add_coin(1);
223225
vCoins.at(0).nInputBytes = 40; // Make sure that it has a negative effective value. The next check should assert if this somehow got through. Otherwise it will fail
224226
BOOST_CHECK(!testWallet.SelectCoinsMinConf( 1 * CENT, filter_standard, vCoins, setCoinsRet, nValueRet, coin_selection_params_bnb, bnb_used));
227+
228+
// Make sure that we aren't using BnB when there are preset inputs
229+
empty_wallet();
230+
add_coin(5 * CENT);
231+
add_coin(3 * CENT);
232+
add_coin(2 * CENT);
233+
CCoinControl coin_control;
234+
coin_control.fAllowOtherInputs = true;
235+
coin_control.Select(COutPoint(vCoins.at(0).tx->GetHash(), vCoins.at(0).i));
236+
BOOST_CHECK(testWallet.SelectCoins(vCoins, 10 * CENT, setCoinsRet, nValueRet, coin_control, coin_selection_params_bnb, bnb_used));
237+
BOOST_CHECK(!bnb_used);
238+
BOOST_CHECK(!coin_selection_params_bnb.use_bnb);
225239
}
226240

227241
BOOST_AUTO_TEST_CASE(knapsack_solver_test)

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
24912491
}
24922492
}
24932493

2494-
bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl& coin_control, const CoinSelectionParams& coin_selection_params, bool& bnb_used) const
2494+
bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const
24952495
{
24962496
std::vector<COutput> vCoins(vAvailableCoins);
24972497

@@ -2521,6 +2521,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
25212521
{
25222522
// For now, don't use BnB if preset inputs are selected. TODO: Enable this later
25232523
bnb_used = false;
2524+
coin_selection_params.use_bnb = false;
25242525

25252526
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.hash);
25262527
if (it != mapWallet.end())

src/wallet/wallet.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,6 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
665665
std::mutex mutexScanning;
666666
friend class WalletRescanReserver;
667667

668-
669-
/**
670-
* Select a set of coins such that nValueRet >= nTargetValue and at least
671-
* all coins from coinControl are selected; Never select unconfirmed coins
672-
* if they are not ours
673-
*/
674-
bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
675-
const CCoinControl& coin_control, const CoinSelectionParams& coin_selection_params, bool& bnb_used) const;
676-
677668
CWalletDB *pwalletdbEncryption;
678669

679670
//! the current wallet version: clients below this version are not able to load the wallet
@@ -766,6 +757,14 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
766757
return *dbw;
767758
}
768759

760+
/**
761+
* Select a set of coins such that nValueRet >= nTargetValue and at least
762+
* all coins from coinControl are selected; Never select unconfirmed coins
763+
* if they are not ours
764+
*/
765+
bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
766+
const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const;
767+
769768
/** Get a name for this wallet for logging/debugging purposes.
770769
*/
771770
const std::string& GetName() const { return m_name; }

0 commit comments

Comments
 (0)