Make sure the MixLock is properly used
MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -84,6 +84,9 @@ namespace WalletWasabi.Services
while (IsRunning)
{
try
+ {
+ int delay;
+ using (await MixLock.LockAsync())
{
// If stop was requested return.
if (IsRunning == false) return;
@@ -91,27 +94,24 @@ namespace WalletWasabi.Services
// if mixing >= connConf: delay = new Random().Next(2, 7);
if (State.GetActivelyMixingRounds().Count() > 0)
{
- var delay = new Random().Next(2, 7);
- await Task.Delay(TimeSpan.FromSeconds(delay), Stop.Token);
- await ProcessStatusAsync();
+ delay = new Random().Next(2, 7);
}
else if (Interlocked.Read(ref _frequentStatusProcessingIfNotMixing) == 1 || State.GetPassivelyMixingRounds().Count() > 0)
{
double rand = double.Parse($"0.{new Random().Next(2, 8)}"); // randomly between every 0.2 * connConfTimeout - 7 and 0.8 * connConfTimeout
- int delay;
- using (await MixLock.LockAsync())
- {
delay = Math.Max(0, (int)(rand * State.GetSmallestRegistrationTimeout() - 7));
}
-
- await Task.Delay(TimeSpan.FromSeconds(delay), Stop.Token);
- await ProcessStatusAsync();
- }
else
{
+ // dormant
await Task.Delay(1000); // dormant
+ continue;
}
}
+
+ await Task.Delay(TimeSpan.FromSeconds(delay), Stop.Token);
+ await ProcessStatusAsync();
+ }
catch (TaskCanceledException ex)
{
Logger.LogTrace<CcjClient>(ex);
@@ -136,13 +136,15 @@ namespace WalletWasabi.Services
{
try
{
- IEnumerable<CcjRunningRoundState> states = await SatoshiClient.GetAllRoundStatesAsync();
+ IEnumerable<CcjRunningRoundState> states;
+ int delay;
using (await MixLock.LockAsync())
{
+ states = await SatoshiClient.GetAllRoundStatesAsync();
State.UpdateRoundsByStates(states.ToArray());
+ delay = new Random().Next(0, 7); // delay the response to defend timing attack privacy
}
- int delay = new Random().Next(0, 7); // delay the response to defend timing attack privacy
await Task.Delay(TimeSpan.FromSeconds(delay), Stop.Token);
using (await MixLock.LockAsync())

Make sure the MixLock is properly used