From d247a1b6ad686887f9bb393c8fd678908838bc3f Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 23 Oct 2017 19:06:18 +0300 Subject: [PATCH 1/2] fix edge case for IS (skip inputs that are too large) --- src/wallet/wallet.cpp | 23 +++++++++++++++-------- src/wallet/wallet.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5d2f27e072d0..5ce4c0781a43 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2421,7 +2421,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const } static void ApproximateBestSubset(vector > >vValue, const CAmount& nTotalLower, const CAmount& nTargetValue, - vector& vfBest, CAmount& nBest, int iterations = 1000) + vector& vfBest, CAmount& nBest, int iterations = 1000, bool fUseInstantSend = false) { vector vfIncluded; @@ -2451,6 +2451,11 @@ static void ApproximateBestSubset(vector= nTargetValue) { + if (fUseInstantSend && nTotal > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)) { + nTotal -= vValue[i].first; + vfIncluded[i] = false; + continue; + } fReachedTarget = true; if (nTotal < nBest) { @@ -2493,14 +2498,16 @@ bool less_then_denom (const COutput& out1, const COutput& out2) } bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins, - set >& setCoinsRet, CAmount& nValueRet) const + set >& setCoinsRet, CAmount& nValueRet, bool fUseInstantSend) const { setCoinsRet.clear(); nValueRet = 0; // List of values less than target pair > coinLowestLarger; - coinLowestLarger.first = std::numeric_limits::max(); + coinLowestLarger.first = fUseInstantSend + ? sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE) + : std::numeric_limits::max(); coinLowestLarger.second.first = NULL; vector > > vValue; CAmount nTotalLower = 0; @@ -2586,9 +2593,9 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int vector vfBest; CAmount nBest; - ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest); + ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, fUseInstantSend); if (nBest != nTargetValue && nTotalLower >= nTargetValue + MIN_CHANGE) - ApproximateBestSubset(vValue, nTotalLower, nTargetValue + MIN_CHANGE, vfBest, nBest); + ApproximateBestSubset(vValue, nTotalLower, nTargetValue + MIN_CHANGE, vfBest, nBest, fUseInstantSend); // If we have a bigger coin and (either the stochastic approximation didn't find a good solution, // or the next bigger coin is closer), return the bigger coin @@ -2697,9 +2704,9 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; + bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet, bool fUseInstantSend = false) const; bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector& vecTxInRet, std::vector& vCoinsRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax); bool GetCollateralTxIn(CTxIn& txinRet, CAmount& nValueRet) const; From 57da68c8dbf3c6a68e2290ae4d1e6b13571f8644 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 24 Oct 2017 03:48:06 +0300 Subject: [PATCH 2/2] fix --- src/wallet/wallet.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5ce4c0781a43..9fc76ac6c6b1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2439,6 +2439,9 @@ static void ApproximateBestSubset(vector sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)) { + continue; + } //The solver here uses a randomized algorithm, //the randomness serves no real security purpose but is just //needed to prevent degenerate behavior and it is important @@ -2451,11 +2454,6 @@ static void ApproximateBestSubset(vector= nTargetValue) { - if (fUseInstantSend && nTotal > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)) { - nTotal -= vValue[i].first; - vfIncluded[i] = false; - continue; - } fReachedTarget = true; if (nTotal < nBest) {