From 96e8d120336cf4312cd5f42ba2f9aff17d4ad414 Mon Sep 17 00:00:00 2001 From: AlSzacrel Date: Sat, 13 Sep 2014 02:09:18 +0200 Subject: [PATCH] Coinselection prunes extraneous inputs from ApproximateBestSubset This is a combination of 3 commits. - 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. - Moved set reduction to the end of ApproximateBestSubset to reduce performance impact - Added a test for the pruning of extraneous inputs after ApproximateBestSet Github-Pull: #4906 Rebased-From: 5c03483e26ab414d22ef192691b2336c1bb3cb02 af9510e0374443b093d633a91c4f1f8bf5071292 fc0f52d78085b6ef97d6821fc7592326c2d9b495 --- src/wallet/test/wallet_tests.cpp | 18 ++++++++++++++++++ src/wallet/wallet.cpp | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 8b9292bd14d..5e8ccd90ab1 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -328,4 +328,22 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) empty_wallet(); } +BOOST_AUTO_TEST_CASE(pruning_in_ApproximateBestSet) +{ + CoinSet setCoinsRet; + CAmount nValueRet; + + LOCK(wallet.cs_wallet); + + empty_wallet(); + for (int i = 0; i < 12; i++) + { + add_coin(10*CENT); + } + add_coin(100*CENT); + add_coin(100*CENT); + BOOST_CHECK(wallet.SelectCoinsMinConf(221*CENT, 1, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK_EQUAL(nValueRet, 230*CENT); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d23d54e6787..a262769c4d7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1632,6 +1632,16 @@ static void ApproximateBestSubset(vector= nTargetValue ) + { + vfBest[i] = false; + nBest -= vValue[i].first; + } + } } bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins,