aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 06b77bb9b9..f9e8a97ae6 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1605,7 +1605,7 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
bool fReachedTarget = false;
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
{
- for (unsigned int i = 0; i < vValue.size(); i++)
+ for (unsigned int i = 0; i < vValue.size() && !fReachedTarget; i++)
{
//The solver here uses a randomized algorithm,
//the randomness serves no real security purpose but is just
@@ -1620,31 +1620,26 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
if (nTotal >= nTargetValue)
{
fReachedTarget = true;
-
- for (unsigned int i = 0; i < vValue.size(); i++)
- {
- //The target has been reached, but the candidate set may contain extraneous inputs.
- //This iterates over all inputs and deducts any that are included, but smaller
- //than the amount nTargetValue is still exceeded by.
- if (vfIncluded[i] && (nTotal - vValue[i].first) >= nTargetValue )
- {
- vfIncluded[i] = false;
- nTotal -= vValue[i].first;
- }
- }
-
if (nTotal < nBest)
{
nBest = nTotal;
vfBest = vfIncluded;
}
- nTotal -= vValue[i].first;
- vfIncluded[i] = false;
}
}
}
}
}
+
+ //Reduces the approximate best subset by removing any inputs that are smaller than the surplus of nTotal beyond nTargetValue.
+ for (unsigned int i = 0; i < vValue.size(); i++)
+ {
+ if (vfBest[i] && (nBest - vValue[i].first) >= nTargetValue )
+ {
+ vfBest[i] = false;
+ nBest -= vValue[i].first;
+ }
+ }
}
bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,