Avoid rounding down small fee amounts
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -256,8 +256,9 @@ namespace WalletWasabi.Backend.Controllers
var acceptedBlindedOutputScripts = new List<uint256>();
// Check if inputs have enough coins.
+ int inputCount = inputs.Count();
Money inputSum = inputs.Sum(x => x.Amount);
- Money networkFeeToPay = (inputs.Count() * round.FeePerInputs) + (2 * round.FeePerOutputs);
+ Money networkFeeToPay = (inputCount * round.FeePerInputs) + (2 * round.FeePerOutputs);
Money changeAmount = inputSum - (round.MixingLevels.GetBaseDenomination() + networkFeeToPay);
if (changeAmount < Money.Zero)
{
@@ -274,7 +275,8 @@ namespace WalletWasabi.Backend.Controllers
break;
}
- changeAmount -= (denomination + round.FeePerOutputs + (denomination.Percentange(round.CoordinatorFeePercent) * round.AnonymitySet)); // It should be the number of bobs, but we must make sure they'd have money to pay all.
+ Money outputCoordinatorFee = denomination.Percentange(round.CoordinatorFeePercent * round.AnonymitySet); // It should be the number of bobs, but we must make sure they'd have money to pay all.
+ changeAmount -= (denomination + round.FeePerOutputs + outputCoordinatorFee);
if (changeAmount < Money.Zero)
{

MODIFY
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
@@ -293,7 +293,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
IEnumerable<Bob> bobsOnThisLevel = Bobs.Where(x => x.Level == level);
if (bobsOnThisLevel.Count() <= 1) break;
- coordinatorFee += level.Denomination.Percentange(CoordinatorFeePercent) * bobsOnThisLevel.Count() * bobsOnThisLevel.Count();
+ coordinatorFee += level.Denomination.Percentange(CoordinatorFeePercent * bobsOnThisLevel.Count() * bobsOnThisLevel.Count());
}
}
@@ -317,7 +317,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
IEnumerable<Bob> bobsOnThisLevel = Bobs.Where(x => x.Level == level);
if (bobsOnThisLevel.Count() <= 1) break;
- changeAmount -= (level.Denomination + FeePerOutputs + (level.Denomination.Percentange(CoordinatorFeePercent) * bobsOnThisLevel.Count()));
+ changeAmount -= (level.Denomination + FeePerOutputs + (level.Denomination.Percentange(CoordinatorFeePercent * bobsOnThisLevel.Count())));
}
}
@@ -568,7 +568,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
break;
}
- changeAmount -= (level.Denomination + FeePerOutputs + (level.Denomination.Percentange(CoordinatorFeePercent) * bobsOnThisLevel));
+ changeAmount -= (level.Denomination + FeePerOutputs + (level.Denomination.Percentange(CoordinatorFeePercent * bobsOnThisLevel)));
if (changeAmount < Money.Zero)
{
@@ -606,7 +606,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
break;
}
- changeAmount -= (level.Denomination + FeePerOutputs + (level.Denomination.Percentange(CoordinatorFeePercent) * potentialAlicesOnThisLevel));
+ changeAmount -= (level.Denomination + FeePerOutputs + (level.Denomination.Percentange(CoordinatorFeePercent * potentialAlicesOnThisLevel)));
if (changeAmount < Money.Zero)
{

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -327,7 +327,7 @@ namespace WalletWasabi.Services
if (myOutputs.Select(x => x.Value).Contains(denomPair.value))
{
Money denomination = denomPair.value;
- Money expectedCoordinatorFee = denomination.Percentange(ongoingRound.State.CoordinatorFeePercent) * denomPair.count;
+ Money expectedCoordinatorFee = denomination.Percentange(ongoingRound.State.CoordinatorFeePercent * denomPair.count);
minAmountBack -= expectedCoordinatorFee; // Minus expected coordinator fee.
}
}

Avoid rounding down small fee amounts