Handle when there's only one coin
MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -467,6 +467,12 @@ public class CoinJoinClient
// We can potentially add a lot more groups to improve results.
var sw1 = Stopwatch.StartNew();
foreach (var coin in largestAmounts)
+ {
+ if (inputCount == 1)
+ {
+ TryAddGroup(parameters, groups, new[] { coin });
+ }
+ else
{
var sw2 = Stopwatch.StartNew();
foreach (var group in filteredCoins
@@ -474,13 +480,7 @@ public class CoinJoinClient
.CombinationsWithoutRepetition(inputCount - 1)
.Select(x => x.Concat(new[] { coin })))
{
- var inSum = group.Sum(x => x.EffectiveValue(parameters.MiningFeeRate, parameters.CoordinationFeeRate));
- var outFee = parameters.MiningFeeRate.GetFee(Constants.P2wpkhOutputVirtualSize);
- if (inSum >= outFee + parameters.AllowedOutputAmounts.Min)
- {
- var k = HashCode.Combine(group.OrderBy(x => x.TransactionId).ThenBy(x => x.Index));
- groups.TryAdd(k, group);
- }
+ TryAddGroup(parameters, groups, group);
if (sw2.Elapsed > TimeSpan.FromSeconds(1))
{
@@ -495,6 +495,7 @@ public class CoinJoinClient
break;
}
}
+ }
if (!groups.Any())
{
@@ -516,6 +517,19 @@ public class CoinJoinClient
return finalCandidate?.ToShuffled()?.ToImmutableList() ?? ImmutableList<SmartCoin>.Empty;
}
+ 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));
+ var outFee = parameters.MiningFeeRate.GetFee(Constants.P2wpkhOutputVirtualSize);
+ if (inSum >= outFee + parameters.AllowedOutputAmounts.Min)
+ {
+ var k = HashCode.Combine(group.OrderBy(x => x.TransactionId).ThenBy(x => x.Index));
+ return groups.TryAdd(k, group);
+ }
+
+ return false;
+ }
+
private static int GetReps(IEnumerable<SmartCoin> group)
=> group.GroupBy(x => x.TransactionId).Sum(coinsInTxGroup => coinsInTxGroup.Count() - 1);

Handle when there's only one coin