Skip to content

Commit

Permalink
Prevent multiple calls to CWallet::AvailableCoins
Browse files Browse the repository at this point in the history
Coming from btc@bb16c8894becfba8764b13d448ba6e7e7f1608c2

Github-Pull: #1717
Rebased-From: 49f4124
  • Loading branch information
furszy authored and Fuzzbawls committed Jul 22, 2020
1 parent c0e9b13 commit 9aacb38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,18 +2311,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
return true;
}

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
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
{
// Note: this function should never be used for "always free" tx types like dstx
std::vector<COutput> vCoins;
AvailableCoins(&vCoins,
coinControl,
fIncludeDelegated,
fIncludeColdStaking,
coin_type,
true, // fOnlyConfirmed
false, // fIncludeZeroValue
useIX);
std::vector<COutput> vCoins(vAvailableCoins);

// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs) {
Expand Down Expand Up @@ -2507,6 +2499,16 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
{
LOCK2(cs_main, cs_wallet);
{
std::vector<COutput> vAvailableCoins;
AvailableCoins(&vAvailableCoins,
coinControl,
fIncludeDelegated,
false, // fIncludeColdStaking
coin_type,
true, // fOnlyConfirmed
false, // fIncludeZeroValue
useIX);

nFeeRet = 0;
if (nFeePay > 0) nFeeRet = nFeePay;
while (true) {
Expand Down Expand Up @@ -2552,7 +2554,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
std::set<std::pair<const CWalletTx*, unsigned int> > setCoins;
CAmount nValueIn = 0;

if (!SelectCoinsToSpend(nTotalValue, setCoins, nValueIn, coinControl, coin_type, useIX, false, fIncludeDelegated)) {
if (!SelectCoinsToSpend(vAvailableCoins, nTotalValue, setCoins, nValueIn, coinControl)) {
if (coin_type == ALL_COINS) {
strFailReason = _("Insufficient funds.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
int nWatchonlyConfig = 1
) const;
//! >> Available coins (spending)
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;
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;
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;
//! >> Available coins (staking)
bool StakeableCoins(std::vector<COutput>* pCoins = nullptr);
Expand Down
6 changes: 5 additions & 1 deletion src/wallet/wallet_zerocoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,14 @@ bool CWallet::CreateZerocoinMintTransaction(const CAmount nValue,
// calculate fee
CAmount nTotalValue = nValue + Params().GetConsensus().ZC_MinMintFee * txNew.vout.size();

// Get the available coins
std::vector<COutput> vAvailableCoins;
AvailableCoins(&vAvailableCoins, coinControl);

CAmount nValueIn = 0;
std::set<std::pair<const CWalletTx*, unsigned int> > setCoins;
// select UTXO's to use
if (!SelectCoinsToSpend(nTotalValue, setCoins, nValueIn, coinControl)) {
if (!SelectCoinsToSpend(vAvailableCoins, nTotalValue, setCoins, nValueIn, coinControl)) {
strFailReason = _("Insufficient or insufficient confirmed funds, you might need to wait a few minutes and try again.");
return false;
}
Expand Down

0 comments on commit 9aacb38

Please sign in to comment.