aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMurch <alszacrel@web.de>2015-12-06 22:20:41 +0100
committerMurch <alszacrel@web.de>2015-12-07 17:36:47 +0100
commitaf9510e0374443b093d633a91c4f1f8bf5071292 (patch)
treed964d4ee866a6adfee8d85584ad43bd731238a03 /src
parent5c03483e26ab414d22ef192691b2336c1bb3cb02 (diff)
downloadbitcoin-af9510e0374443b093d633a91c4f1f8bf5071292.tar.xz
Moved set reduction to the end of ApproximateBestSubset to reduce performance impact
Diffstat (limited to 'src')
-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,