Extract coinjoin finalization handling
MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
using Microsoft.Extensions.Hosting;
using NBitcoin;
-using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
@@ -82,12 +81,14 @@ public class CoinJoinManager : BackgroundService
? GetMixableWallets()
: ImmutableDictionary<string, Wallet>.Empty;
+ // Nofify when a wallet meets the criteria for participating in a coinjoin.
var openedWallets = mixableWallets.Where(x => !trackedCoinJoins.ContainsKey(x.Key)).ToImmutableList();
foreach (var openedWallet in openedWallets.Select(x => x.Value))
{
NotifyMixableWalletLoaded(openedWallet);
}
+ // Nofitify when a wallet is no longer meet the criteria for participating in a coinjoin.
var closedWallets = trackedCoinJoins.Where(x => !mixableWallets.ContainsKey(x.Key)).ToImmutableList();
foreach (var closedWallet in closedWallets.Select(x => x.Value))
{
@@ -95,11 +96,20 @@ public class CoinJoinManager : BackgroundService
NotifyMixableWalletUnloaded(closedWallet);
}
+ // Handles coinjoin finalization and notification.
var finishedCoinJoins = trackedCoinJoins.Where(x => x.Value.IsCompleted).Select(x => x.Value).ToImmutableArray();
foreach (var finishedCoinJoin in finishedCoinJoins)
{
NotifyCoinJoinCompletion(finishedCoinJoin);
+ await HandleCoinJoinFinalizationAsync(finishedCoinJoin, trackedCoinJoins, stoppingToken).ConfigureAwait(false);
+ }
+
+ TrackedCoinJoins = trackedCoinJoins.ToImmutableDictionary();
+ }
+ }
+ private async Task HandleCoinJoinFinalizationAsync(CoinJoinTracker finishedCoinJoin, Dictionary<string, CoinJoinTracker> trackedCoinJoins, CancellationToken cancellationToken)
+ {
var walletToRemove = finishedCoinJoin.Wallet;
if (!trackedCoinJoins.Remove(walletToRemove.WalletName))
{
@@ -129,7 +139,7 @@ public class CoinJoinManager : BackgroundService
catch (InvalidOperationException ioe)
{
Logger.LogError(ioe);
- await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken).ConfigureAwait(false);
+ await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@@ -146,10 +156,6 @@ public class CoinJoinManager : BackgroundService
}
}
- TrackedCoinJoins = trackedCoinJoins.ToImmutableDictionary();
- }
- }
-
/// <summary>
/// Mark all the outputs we had in any of our wallets used.
/// </summary>

Extract coinjoin finalization handling