Moved set reduction to the end of ApproximateBestSubset to reduce performance impact
This commit is contained in:
parent
5c03483e26
commit
af9510e037
1 changed files with 11 additions and 16 deletions
|
@ -1605,7 +1605,7 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
|
||||||
bool fReachedTarget = false;
|
bool fReachedTarget = false;
|
||||||
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
|
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 solver here uses a randomized algorithm,
|
||||||
//the randomness serves no real security purpose but is just
|
//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)
|
if (nTotal >= nTargetValue)
|
||||||
{
|
{
|
||||||
fReachedTarget = true;
|
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)
|
if (nTotal < nBest)
|
||||||
{
|
{
|
||||||
nBest = nTotal;
|
nBest = nTotal;
|
||||||
vfBest = vfIncluded;
|
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,
|
bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
|
||||||
|
|
Loading…
Reference in a new issue