Fix edge case: if somehow we would have two outputs in the same mixing level then check that instead of only checking one.
MODIFY
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
@@ -293,8 +293,8 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
// 4. Start building Coordinator fee.
var baseDenominationOutputCount = transaction.Outputs.Count(x => x.Value == newDenomination);
- Money coordinatorFeePerAlice = newDenomination.Percentage(CoordinatorFeePercent * baseDenominationOutputCount);
- Money coordinatorFee = baseDenominationOutputCount * coordinatorFeePerAlice;
+ Money coordinatorBaseFeePerAlice = newDenomination.Percentage(CoordinatorFeePercent * baseDenominationOutputCount);
+ Money coordinatorFee = baseDenominationOutputCount * coordinatorBaseFeePerAlice;
if (tinkerWithAdditionalMixingLevels)
{
@@ -303,7 +303,8 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
var denominationOutputCount = transaction.Outputs.Count(x => x.Value == level.Denomination);
if (denominationOutputCount <= 1) break;
- coordinatorFee += level.Denomination.Percentage(CoordinatorFeePercent * denominationOutputCount * denominationOutputCount);
+ Money coordinatorLevelFeePerAlice = level.Denomination.Percentage(CoordinatorFeePercent * denominationOutputCount);
+ coordinatorFee += coordinatorLevelFeePerAlice * denominationOutputCount;
}
}
@@ -317,7 +318,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
spentCoins.Add(input);
}
- Money changeAmount = alice.InputSum - alice.NetworkFeeToPay - newDenomination - coordinatorFeePerAlice;
+ Money changeAmount = alice.InputSum - alice.NetworkFeeToPay - newDenomination - coordinatorBaseFeePerAlice;
if (tinkerWithAdditionalMixingLevels)
{

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -336,11 +336,12 @@ namespace WalletWasabi.Services
IOrderedEnumerable<(Money value, int count)> indistinguishableOutputs = unsignedCoinJoin.GetIndistinguishableOutputs(includeSingle: false).OrderByDescending(x => x.count);
foreach ((Money value, int count) denomPair in indistinguishableOutputs)
{
- if (myOutputs.Select(x => x.Value)
- .Contains(denomPair.value))
- {
+ var mineCount = myOutputs.Count(x => x.Value == denomPair.value);
+
Money denomination = denomPair.value;
Money expectedCoordinatorFee = denomination.Percentage(ongoingRound.State.CoordinatorFeePercent * denomPair.count);
+ for (int i = 0; i < mineCount; i++)
+ {
minAmountBack -= expectedCoordinatorFee; // Minus expected coordinator fee.
}
}

Fix edge case: if somehow we would have two outputs in the same mixing level then check that instead of only checking one.