Add coordantor service, fix graceful shutdown
MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -37,6 +37,8 @@ namespace WalletWasabi.Backend
public static IndexBuilderService IndexBuilderService { get; private set; }
+ public static CcjCoordinator Coordinator { get; private set; }
+
public static Config Config { get; private set; }
public async static Task InitializeAsync(Network network = null, string rpcuser = null, string rpcpassword = null, RPCClient rpc = null)
@@ -89,6 +91,9 @@ namespace WalletWasabi.Backend
var utxoSetFilePath = Path.Combine(indexBuilderServiceDir, $"UtxoSet{RpcClient.Network}.dat");
IndexBuilderService = new IndexBuilderService(RpcClient, indexFilePath, utxoSetFilePath);
IndexBuilderService.Synchronize();
+
+ Coordinator = new CcjCoordinator();
+ Coordinator.Start();
}
public static async Task InitializeConfigAsync()

MODIFY
WalletWasabi.Backend/Startup.cs
WalletWasabi.Backend/Startup.cs
@@ -57,15 +57,30 @@ namespace WalletWasabi.Backend
app.UseMvc();
var applicationLifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
- applicationLifetime.ApplicationStopping.Register(OnShutdownAsync);
+ applicationLifetime.ApplicationStopping.Register(OnShutdown); // Don't register OnShutdownAsync, that won't hold up the shutdown
}
- private async void OnShutdownAsync()
+ private void OnShutdown()
{
+ OnShutdownAsync().GetAwaiter().GetResult(); // This is needed, if async function is regisered then it won't wait until it finishes
+ }
+
+ private async Task OnShutdownAsync()
+ {
+ var stopTasks = new List<Task>();
+
if(Global.IndexBuilderService != null)
{
- await Global.IndexBuilderService.StopAsync();
+ var t = Global.IndexBuilderService.StopAsync();
+ stopTasks.Add(t);
}
+ if (Global.Coordinator != null)
+ {
+ var t = Global.Coordinator.StopAsync();
+ stopTasks.Add(t);
+ }
+
+ await Task.WhenAll(stopTasks);
}
}
}

MODIFY
WalletWasabi/Services/IndexBuilderService.cs
WalletWasabi/Services/IndexBuilderService.cs
@@ -268,6 +268,11 @@ namespace WalletWasabi.Services
foreach (var tx in block.Transactions)
{
+ // If stop was requested return.
+ // Because this tx iteration can take even minutes
+ // It doesn't need to be accessed with a thread safe fasion with Interlocked through IsRunning, this may have some performance benefit
+ if (_running != 1) return;
+
for (int i = 0; i < tx.Outputs.Count; i++)
{
var output = tx.Outputs[i];

Add coordantor service, fix graceful shutdown