diff options
author | AlSzacrel <alszacrel@web.de> | 2014-09-13 02:09:18 +0200 |
---|---|---|
committer | Murch <alszacrel@web.de> | 2015-12-06 23:26:45 +0100 |
commit | 5c03483e26ab414d22ef192691b2336c1bb3cb02 (patch) | |
tree | 9973d4590bb5a20b4c016918cc284a48ea675882 | |
parent | 075faaebf2e534265ff8aca015eaf03a8a156f32 (diff) |
Coinselection prunes extraneous inputs from ApproximateBestSubset
A further pass over the available inputs has been added to ApproximateBestSubset after a candidate set has been found. It will prune any extraneous inputs in the selected subset, in order to decrease the number of input and the resulting change.
-rw-r--r-- | src/wallet/wallet.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d23d54e678..06b77bb9b9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1620,6 +1620,19 @@ 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; |