Limit private coin participation
MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -540,21 +540,13 @@ public class CoinJoinClient
privateCoins.Length + allowedNonPrivateCoins.Count,
consolidationMode ? MaxInputsRegistrableByWallet : GetInputTarget(allowedNonPrivateCoins.Count, privateCoins.Length, rnd));
- var allowedCoins = allowedNonPrivateCoins.Concat(privateCoins).ToArray();
+ // Let's allow only a inputCount - 1 private coins to play.
+ var allowedPrivateCoins = AnonScoreBiasedShuffle(privateCoins).Take(inputCount - 1);
- // Shuffle coins, while randomly biasing towards lower AS.
- var orderedAllowedCoins = new List<SmartCoin>();
- for (int i = 0; i < allowedCoins.Length; i++)
- {
- var remaining = allowedCoins.Except(orderedAllowedCoins).OrderBy(x => x.HdPubKey.AnonymitySet);
- var c = remaining.BiasedRandomElement(50);
- if (c is null)
- {
- throw new NotSupportedException("This is impossible.");
- }
+ var allowedCoins = allowedNonPrivateCoins.Concat(allowedPrivateCoins).ToArray();
- orderedAllowedCoins.Add(c);
- }
+ // Shuffle coins, while randomly biasing towards lower AS.
+ var orderedAllowedCoins = AnonScoreBiasedShuffle(allowedCoins).ToArray();
// Always use the largest amounts, so we do not participate with insignificant amounts and fragment wallet needlessly.
var largestAmounts = allowedNonPrivateCoins
@@ -628,6 +620,23 @@ public class CoinJoinClient
return finalCandidate?.ToShuffled()?.ToImmutableList() ?? ImmutableList<SmartCoin>.Empty;
}
+ private static IEnumerable<SmartCoin> AnonScoreBiasedShuffle(SmartCoin[] coins)
+ {
+ var orderedCoins = new List<SmartCoin>();
+ for (int i = 0; i < coins.Length; i++)
+ {
+ var remaining = coins.Except(orderedCoins).OrderBy(x => x.HdPubKey.AnonymitySet);
+ var c = remaining.BiasedRandomElement(50);
+ if (c is null)
+ {
+ throw new NotSupportedException("This is impossible.");
+ }
+
+ orderedCoins.Add(c);
+ yield return c;
+ }
+ }
+
private static bool TryAddGroup(RoundParameters parameters, Dictionary<int, IEnumerable<SmartCoin>> groups, IEnumerable<SmartCoin> group)
{
var inSum = group.Sum(x => x.EffectiveValue(parameters.MiningFeeRate, parameters.CoordinationFeeRate));

Limit private coin participation