Fix "Coordinator did not add enough value.."
Resolves
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -387,6 +387,12 @@ namespace WalletWasabi.Backend.Controllers
alice.State = AliceState.ConnectionConfirmed;
int takeBlindCount = round.EstimateBestMixingLevel(alice);
+
+ var prevBlindCount = alice.BlindedOutputScripts.Length;
+ for (int i = 0; i < prevBlindCount - takeBlindCount; i++)
+ {
+ alice.NetworkFeeToPay -= round.FeePerOutputs;
+ }
alice.BlindedOutputScripts = alice.BlindedOutputScripts.Take(takeBlindCount).ToArray();
alice.BlindedOutputSignatures = alice.BlindedOutputSignatures.Take(takeBlindCount).ToArray();
resp.BlindedOutputSignatures = alice.BlindedOutputSignatures; // Don't give back more mixing levels than we'll use.

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -2950,8 +2950,6 @@ namespace WalletWasabi.Tests
await rpc.GenerateAsync(1);
- // ToDo: For now it doesn't test fees.
-
try
{
// 2. Start mixing.

MODIFY
WalletWasabi/Models/ChaumianCoinJoin/Alice.cs
WalletWasabi/Models/ChaumianCoinJoin/Alice.cs
@@ -15,7 +15,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
public Money InputSum { get; }
- public Money NetworkFeeToPay { get; }
+ public Money NetworkFeeToPay { get; set; }
public IEnumerable<Coin> Inputs { get; }

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -331,7 +331,8 @@ namespace WalletWasabi.Services
// Make sure change is counted.
Money minAmountBack = ongoingRound.CoinsRegistered.Sum(x => x.Amount); // Start with input sum.
- minAmountBack -= ongoingRound.State.FeePerOutputs * myOutputs.Length + ongoingRound.State.FeePerInputs * ongoingRound.Registration.CoinsRegistered.Count(); // Minus miner fee.
+ // Do outputs.lenght + 1 in case the server estimated the network fees wrongly due to insufficient data in an edge case.
+ minAmountBack -= ongoingRound.State.FeePerOutputs * (myOutputs.Length + 1) + ongoingRound.State.FeePerInputs * ongoingRound.Registration.CoinsRegistered.Count(); // Minus miner fee.
IOrderedEnumerable<(Money value, int count)> indistinguishableOutputs = unsignedCoinJoin.GetIndistinguishableOutputs(includeSingle: false).OrderByDescending(x => x.count);
foreach ((Money value, int count) denomPair in indistinguishableOutputs)
@@ -357,7 +358,7 @@ namespace WalletWasabi.Services
minAmountBack -= minimumChangeAmount; // Minus coordinator protections (so it won't create bad coinjoins.)
}
- if (amountBack < minAmountBack && !amountBack.Almost(minAmountBack, Money.Satoshis(10000))) // I catched an issue here, probably rounding. 1000 dust should be enough to catch it, but let's do 10000, why not.
+ if (amountBack < minAmountBack && !amountBack.Almost(minAmountBack, Money.Satoshis(10000))) // Just in case.
{
throw new NotSupportedException($"Coordinator did not add enough value to our outputs in the coinjoin. Missing: {(minAmountBack - amountBack).Satoshi} satoshis.");
}

Fix "Coordinator did not add enough value.."
Resolves https://github.com/zkSNACKs/WalletWasabi/issues/1136