Skip to content

Commit ae857fb

Browse files
committed
Fixes for PS and UTXO sorting
1 parent 84b39d9 commit ae857fb

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/privatesend-client.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -971,10 +971,10 @@ bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool
971971
return false;
972972
}
973973

974-
int nDnCount = dnodeman.CountDynodes();
974+
int nDnCountEnabled = dnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION);
975975

976976
// If we've used 90% of the Dynode list then drop the oldest first ~30%
977-
int nThreshold_high = nDnCount * 0.9;
977+
int nThreshold_high = nDnCountEnabled * 0.9;
978978
int nThreshold_low = nThreshold_high * 0.7;
979979
LogPrint("privatesend", "Checking vecDynodesUsed: size: %d, threshold: %d\n", (int)vecDynodesUsed.size(), nThreshold_high);
980980

@@ -1371,6 +1371,11 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(CConnman& connman)
13711371
return false;
13721372
}
13731373

1374+
// Start from smallest balances first to consume tiny amounts and cleanup UTXO a bit
1375+
std::sort(vecTally.begin(), vecTally.end(), [](const CompactTallyItem& a, const CompactTallyItem& b) {
1376+
return a.nAmount < b.nAmount;
1377+
});
1378+
13741379
// First try to use only non-denominated funds
13751380
for (const auto& item : vecTally) {
13761381
if (!MakeCollateralAmounts(item, false, connman))
@@ -1483,6 +1488,11 @@ bool CPrivateSendClientSession::CreateDenominated(CConnman& connman)
14831488
return false;
14841489
}
14851490

1491+
// Start from largest balances first to speed things up by creating txes with larger/largest denoms included
1492+
std::sort(vecTally.begin(), vecTally.end(), [](const CompactTallyItem& a, const CompactTallyItem& b) {
1493+
return a.nAmount > b.nAmount;
1494+
});
1495+
14861496
bool fCreateMixingCollaterals = !pwalletMain->HasCollateralInputs();
14871497

14881498
for (const auto& item : vecTally) {

src/wallet/wallet.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -2991,14 +2991,6 @@ bool CWallet::SelectPSInOutPairsByDenominations(int nDenom, CAmount nValueMin, C
29912991
return nValueTotal >= nValueMin && nDenom == nDenomResult;
29922992
}
29932993

2994-
struct CompareByAmount {
2995-
bool operator()(const CompactTallyItem& t1,
2996-
const CompactTallyItem& t2) const
2997-
{
2998-
return t1.nAmount > t2.nAmount;
2999-
}
3000-
};
3001-
30022994
bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated, bool fAnonymizable, bool fSkipUnconfirmed, int nMaxOupointsPerAddress) const
30032995
{
30042996
LOCK2(cs_main, cs_wallet);
@@ -3084,16 +3076,14 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
30843076
}
30853077

30863078
// construct resulting vector
3079+
// NOTE: vecTallyRet is "sorted" by txdest (i.e. address), just like mapTally
30873080
vecTallyRet.clear();
30883081
for (const auto& item : mapTally) {
30893082
if (fAnonymizable && item.second.nAmount < nSmallestDenom)
30903083
continue;
30913084
vecTallyRet.push_back(item.second);
30923085
}
30933086

3094-
// order by amounts per address, from smallest to largest
3095-
sort(vecTallyRet.rbegin(), vecTallyRet.rend(), CompareByAmount());
3096-
30973087
// cache already confirmed anonymizable entries for later use, no cache should be saved when the limit is specified
30983088
if(nMaxOupointsPerAddress != -1 && fAnonymizable && fSkipUnconfirmed) {
30993089
if (fSkipDenominated) {

0 commit comments

Comments
 (0)