Skip to content

Commit 9aacb38

Browse files
furszyFuzzbawls
authored andcommitted
Prevent multiple calls to CWallet::AvailableCoins
Coming from btc@bb16c8894becfba8764b13d448ba6e7e7f1608c2 Github-Pull: #1717 Rebased-From: 49f4124
1 parent c0e9b13 commit 9aacb38

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/wallet/wallet.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,18 +2311,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
23112311
return true;
23122312
}
23132313

2314-
bool CWallet::SelectCoinsToSpend(const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl, AvailableCoinsType coin_type, bool useIX, bool fIncludeColdStaking, bool fIncludeDelegated) const
2314+
bool CWallet::SelectCoinsToSpend(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl) const
23152315
{
23162316
// Note: this function should never be used for "always free" tx types like dstx
2317-
std::vector<COutput> vCoins;
2318-
AvailableCoins(&vCoins,
2319-
coinControl,
2320-
fIncludeDelegated,
2321-
fIncludeColdStaking,
2322-
coin_type,
2323-
true, // fOnlyConfirmed
2324-
false, // fIncludeZeroValue
2325-
useIX);
2317+
std::vector<COutput> vCoins(vAvailableCoins);
23262318

23272319
// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
23282320
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs) {
@@ -2507,6 +2499,16 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
25072499
{
25082500
LOCK2(cs_main, cs_wallet);
25092501
{
2502+
std::vector<COutput> vAvailableCoins;
2503+
AvailableCoins(&vAvailableCoins,
2504+
coinControl,
2505+
fIncludeDelegated,
2506+
false, // fIncludeColdStaking
2507+
coin_type,
2508+
true, // fOnlyConfirmed
2509+
false, // fIncludeZeroValue
2510+
useIX);
2511+
25102512
nFeeRet = 0;
25112513
if (nFeePay > 0) nFeeRet = nFeePay;
25122514
while (true) {
@@ -2552,7 +2554,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
25522554
std::set<std::pair<const CWalletTx*, unsigned int> > setCoins;
25532555
CAmount nValueIn = 0;
25542556

2555-
if (!SelectCoinsToSpend(nTotalValue, setCoins, nValueIn, coinControl, coin_type, useIX, false, fIncludeDelegated)) {
2557+
if (!SelectCoinsToSpend(vAvailableCoins, nTotalValue, setCoins, nValueIn, coinControl)) {
25562558
if (coin_type == ALL_COINS) {
25572559
strFailReason = _("Insufficient funds.");
25582560
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
355355
int nWatchonlyConfig = 1
356356
) const;
357357
//! >> Available coins (spending)
358-
bool SelectCoinsToSpend(const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl = nullptr, AvailableCoinsType coin_type = ALL_COINS, bool useIX = true, bool fIncludeColdStaking = false, bool fIncludeDelegated = true) const;
358+
bool SelectCoinsToSpend(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl = nullptr) const;
359359
bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
360360
//! >> Available coins (staking)
361361
bool StakeableCoins(std::vector<COutput>* pCoins = nullptr);

src/wallet/wallet_zerocoin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,14 @@ bool CWallet::CreateZerocoinMintTransaction(const CAmount nValue,
302302
// calculate fee
303303
CAmount nTotalValue = nValue + Params().GetConsensus().ZC_MinMintFee * txNew.vout.size();
304304

305+
// Get the available coins
306+
std::vector<COutput> vAvailableCoins;
307+
AvailableCoins(&vAvailableCoins, coinControl);
308+
305309
CAmount nValueIn = 0;
306310
std::set<std::pair<const CWalletTx*, unsigned int> > setCoins;
307311
// select UTXO's to use
308-
if (!SelectCoinsToSpend(nTotalValue, setCoins, nValueIn, coinControl)) {
312+
if (!SelectCoinsToSpend(vAvailableCoins, nTotalValue, setCoins, nValueIn, coinControl)) {
309313
strFailReason = _("Insufficient or insufficient confirmed funds, you might need to wait a few minutes and try again.");
310314
return false;
311315
}

0 commit comments

Comments
 (0)