@@ -1036,7 +1036,7 @@ bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymize
10361036 CAmount nMaxAmount = nBalanceNeedsAnonymized;
10371037
10381038 // Try to match their denominations if possible, select exact number of denominations
1039- if (!pwalletMain->SelectCoinsByDenominations (dsq.nDenom , nMinAmount, nMaxAmount, vecTxDSInTmp, vCoinsTmp, nValueInTmp, 0 , privateSendClient.nPrivateSendRounds )) {
1039+ if (!pwalletMain->SelectCoinsByDenominations (dsq.nDenom , nMinAmount, nMaxAmount, vecTxDSInTmp, vCoinsTmp, nValueInTmp, 0 , privateSendClient.nPrivateSendRounds , true )) {
10401040 LogPrintf (" CPrivateSendClientSession::JoinExistingQueue -- Couldn't match %d denominations %d (%s)\n " , vecBits.front (), dsq.nDenom , CPrivateSend::GetDenominationsToString (dsq.nDenom ));
10411041 continue ;
10421042 }
@@ -1180,25 +1180,45 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
11801180 std::string strError;
11811181 std::vector<CTxDSIn> vecTxDSInRet;
11821182 std::vector<CTxOut> vecTxOutRet;
1183+ // lean towards "highest" branch but still mix via "lowest" one someties
1184+ bool fMixLowest = privateSendClient.nLiquidityProvider || (GetRandInt (4 ) == 0 );
1185+ // lean towards edges but still mix starting from the middle someties
1186+ // Note: liqudity providers always start from 0
1187+ bool fScanFromTheMiddle = (privateSendClient.nLiquidityProvider == 0 ) && (GetRandInt (4 ) == 0 );
1188+
1189+ int nRoundStart{0 };
1190+ if (fScanFromTheMiddle ) {
1191+ nRoundStart = privateSendClient.nPrivateSendRounds / 2 ;
1192+ } else if (!fMixLowest ) {
1193+ nRoundStart = privateSendClient.nPrivateSendRounds ;
1194+ }
11831195
11841196 // Submit transaction to the pool if we get here
1185- if (privateSendClient.nLiquidityProvider ) {
1186- // Try to use only inputs with the same number of rounds starting from the lowest number of rounds possible
1187- for (int i = 0 ; i< privateSendClient.nPrivateSendRounds ; i++) {
1188- if (PrepareDenominate (i, i + 1 , strError, vecTxDSInRet, vecTxOutRet)) {
1189- LogPrintf (" CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n " , i);
1190- return SendDenominate (vecTxDSInRet, vecTxOutRet, connman);
1197+ if (fMixLowest ) {
1198+ // Try to use only inputs with the same number of rounds, from low to high
1199+ while (true ) {
1200+ for (int i = nRoundStart; i < privateSendClient.nPrivateSendRounds ; i++) {
1201+ if (PrepareDenominate (i, i + 1 , strError, vecTxDSInRet, vecTxOutRet)) {
1202+ LogPrintf (" CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n " , i);
1203+ return SendDenominate (vecTxDSInRet, vecTxOutRet, connman);
1204+ }
1205+ LogPrint (" privatesend" , " CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n " , i, strError);
11911206 }
1192- LogPrint (" privatesend" , " CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n " , i, strError);
1207+ if (nRoundStart == 0 ) break ;
1208+ nRoundStart = 0 ;
11931209 }
11941210 } else {
1195- // Try to use only inputs with the same number of rounds starting from the highest number of rounds possible
1196- for (int i = privateSendClient.nPrivateSendRounds ; i > 0 ; i--) {
1197- if (PrepareDenominate (i - 1 , i, strError, vecTxDSInRet, vecTxOutRet)) {
1198- LogPrintf (" CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n " , i);
1199- return SendDenominate (vecTxDSInRet, vecTxOutRet, connman);
1211+ // Try to use only inputs with the same number of rounds, from high to low
1212+ while (true ) {
1213+ for (int i = nRoundStart; i > 0 ; i--) {
1214+ if (PrepareDenominate (i - 1 , i, strError, vecTxDSInRet, vecTxOutRet)) {
1215+ LogPrintf (" CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n " , i);
1216+ return SendDenominate (vecTxDSInRet, vecTxOutRet, connman);
1217+ }
1218+ LogPrint (" privatesend" , " CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n " , i, strError);
12001219 }
1201- LogPrint (" privatesend" , " CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, error: %s\n " , i, strError);
1220+ if (nRoundStart == privateSendClient.nPrivateSendRounds ) break ;
1221+ nRoundStart = privateSendClient.nPrivateSendRounds ;
12021222 }
12031223 }
12041224
@@ -1251,7 +1271,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
12511271 return false ;
12521272 }
12531273 std::vector<CAmount> vecStandardDenoms = CPrivateSend::GetStandardDenominations ();
1254- bool fSelected = pwalletMain->SelectCoinsByDenominations (nSessionDenom, vecStandardDenoms[vecBits.front ()], CPrivateSend::GetMaxPoolAmount (), vecTxDSIn, vCoins, nValueIn, nMinRounds, nMaxRounds);
1274+ bool fSelected = pwalletMain->SelectCoinsByDenominations (nSessionDenom, vecStandardDenoms[vecBits.front ()], CPrivateSend::GetMaxPoolAmount (), vecTxDSIn, vCoins, nValueIn, nMinRounds, nMaxRounds, true );
12551275 if (nMinRounds >= 0 && !fSelected ) {
12561276 strErrorRet = " Can't select current denominated inputs" ;
12571277 return false ;
0 commit comments