0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-09 15:37:00 -04:00

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: 5c03483e26 af9510e037 fc0f52d780
This commit is contained in:
AlSzacrel 2014-09-13 02:09:18 +02:00 committed by Wladimir J. van der Laan
parent b2d7ada372
commit 96e8d12033
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 28 additions and 0 deletions

View file

@ -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()

View file

@ -1632,6 +1632,16 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
}
}
}
//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,