Remove locks
MODIFY
WalletWasabi/CoinJoin/Coordinator/Coordinator.cs
WalletWasabi/CoinJoin/Coordinator/Coordinator.cs
@@ -3,6 +3,7 @@ using NBitcoin.RPC;
using Nito.AsyncEx;
using System;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
@@ -16,6 +17,7 @@ using WalletWasabi.CoinJoin.Coordinator.Participants;
using WalletWasabi.CoinJoin.Coordinator.Rounds;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
+using WalletWasabi.WabiSabi.Backend.Rounds;
namespace WalletWasabi.CoinJoin.Coordinator
{
@@ -31,7 +33,7 @@ namespace WalletWasabi.CoinJoin.Coordinator
RpcClient = Guard.NotNull(nameof(rpc), rpc);
RoundConfig = Guard.NotNull(nameof(roundConfig), roundConfig);
- Rounds = new List<CoordinatorRound>();
+ Rounds = ImmutableList<CoordinatorRound>.Empty;
RoundsListLock = new AsyncLock();
LastSuccessfulCoinJoinTime = DateTimeOffset.UtcNow;
@@ -132,7 +134,7 @@ namespace WalletWasabi.CoinJoin.Coordinator
public DateTimeOffset LastSuccessfulCoinJoinTime { get; private set; }
- private List<CoordinatorRound> Rounds { get; }
+ private ImmutableList<CoordinatorRound> Rounds { get; set; }
private AsyncLock RoundsListLock { get; }
private List<uint256> CoinJoins { get; } = new List<uint256>();
@@ -227,7 +229,7 @@ namespace WalletWasabi.CoinJoin.Coordinator
round.StatusChanged += Round_StatusChangedAsync;
round.PhaseChanged += Round_PhaseChangedAsync;
await round.ExecuteNextPhaseAsync(RoundPhase.InputRegistration).ConfigureAwait(false);
- Rounds.Add(round);
+ Rounds = Rounds.Add(round);
}
}
}
@@ -342,7 +344,7 @@ namespace WalletWasabi.CoinJoin.Coordinator
{
IEnumerable<Alice> alicesDidntSign = round.GetAlicesByNot(AliceState.SignedCoinJoin, syncLock: false);
- if (TryGetCurrentInputRegisterableRound(out CoordinatorRound? nextRound, syncLock: false))
+ if (TryGetCurrentInputRegisterableRound(out CoordinatorRound? nextRound))
{
int nextRoundAlicesCount = nextRound.CountAlices(syncLock: false);
var alicesSignedCount = round.AnonymitySet - alicesDidntSign.Count();
@@ -391,51 +393,31 @@ namespace WalletWasabi.CoinJoin.Coordinator
}
public void AbortAllRoundsInInputRegistration(string reason, [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
- {
- using (RoundsListLock.Lock())
{
foreach (var r in Rounds.Where(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration))
{
r.Abort(reason, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber);
}
}
- }
public IEnumerable<CoordinatorRound> GetRunningRounds()
- {
- using (RoundsListLock.Lock())
{
return Rounds.Where(x => x.Status == CoordinatorRoundStatus.Running).OrderBy(x => x.RemainingInputRegistrationTime).ToArray();
}
- }
- public bool TryGetCurrentInputRegisterableRound([NotNullWhen(true)] out CoordinatorRound? coordinatorRound, bool syncLock = true)
- {
- if (syncLock)
- {
- using (RoundsListLock.Lock())
+ public bool TryGetCurrentInputRegisterableRound([NotNullWhen(true)] out CoordinatorRound? coordinatorRound)
{
coordinatorRound = Rounds.FirstOrDefault(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration);
return coordinatorRound is not null;
}
- }
-
- coordinatorRound = Rounds.FirstOrDefault(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration);
- return coordinatorRound is not null;
- }
public bool TryGetRound(long roundId, [NotNullWhen(true)] out CoordinatorRound? coordinatorRound)
- {
- using (RoundsListLock.Lock())
{
coordinatorRound = Rounds.SingleOrDefault(x => x.RoundId == roundId);
return coordinatorRound is not null;
}
- }
public bool AnyRunningRoundContainsInput(OutPoint input, out List<Alice> alices)
- {
- using (RoundsListLock.Lock())
{
alices = new List<Alice>();
foreach (var round in Rounds.Where(x => x.Status == CoordinatorRoundStatus.Running))
@@ -450,7 +432,6 @@ namespace WalletWasabi.CoinJoin.Coordinator
}
return alices.Count > 0;
}
- }
public int GetCoinJoinCount()
{
@@ -472,8 +453,6 @@ namespace WalletWasabi.CoinJoin.Coordinator
if (!_disposedValue)
{
if (disposing)
- {
- using (RoundsListLock.Lock())
{
if (BlockNotifier is { })
{
@@ -499,7 +478,6 @@ namespace WalletWasabi.CoinJoin.Coordinator
Logger.LogDebug(ex);
}
}
- }
_disposedValue = true;
}

Remove locks