Make coordinator use P2P block notifications
MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -62,8 +62,7 @@ namespace WalletWasabi.Backend
var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{RpcClient.Network}.dat");
var utxoSetFilePath = Path.Combine(indexBuilderServiceDir, $"UtxoSet{RpcClient.Network}.dat");
IndexBuilderService = new IndexBuilderService(RpcClient, TrustedNodeNotifyingBehavior, indexFilePath, utxoSetFilePath);
- Coordinator = new CcjCoordinator(RpcClient.Network, Path.Combine(DataDir, nameof(CcjCoordinator)), RpcClient, roundConfig);
- IndexBuilderService.NewBlock += IndexBuilderService_NewBlockAsync;
+ Coordinator = new CcjCoordinator(RpcClient.Network, TrustedNodeNotifyingBehavior, Path.Combine(DataDir, nameof(CcjCoordinator)), RpcClient, roundConfig);
IndexBuilderService.Synchronize();
Logger.LogInfo<IndexBuilderService>("IndexBuilderService is successfully initialized and started synchronization.");
@@ -177,18 +176,6 @@ namespace WalletWasabi.Backend
}
}
- public static async void IndexBuilderService_NewBlockAsync(object sender, Block block)
- {
- try
- {
- await Coordinator.ProcessBlockAsync(block);
- }
- catch (Exception ex)
- {
- Logger.LogWarning(ex, nameof(Global));
- }
- }
-
private static async Task AssertRpcNodeFullyInitializedAsync()
{
try

MODIFY
WalletWasabi.Backend/Startup.cs
WalletWasabi.Backend/Startup.cs
@@ -93,8 +93,6 @@ namespace WalletWasabi.Backend
if (Global.IndexBuilderService != null)
{
- Global.IndexBuilderService.NewBlock -= Global.IndexBuilderService_NewBlockAsync;
-
await Global.IndexBuilderService.StopAsync();
Logger.LogInfo<Startup>("IndexBuilderService is disposed.");
}
@@ -105,8 +103,11 @@ namespace WalletWasabi.Backend
Logger.LogInfo<Startup>("RoundConfigWatcher is disposed.");
}
+ if (Global.LocalNode != null)
+ {
Global.DisconnectDisposeNullLocalNode();
Logger.LogInfo<Startup>("LocalNode is disposed.");
}
}
}
+}

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1674,7 +1674,7 @@ namespace WalletWasabi.Tests
mempoolTxId.ToString()
});
- using (var coordinatorToTest = new CcjCoordinator(network, folder, rpc, coordinator.RoundConfig))
+ using (var coordinatorToTest = new CcjCoordinator(network, Global.TrustedNodeNotifyingBehavior, folder, rpc, coordinator.RoundConfig))
{
var txIds = await File.ReadAllLinesAsync(cjfile);
@@ -1689,7 +1689,7 @@ namespace WalletWasabi.Tests
"This line is invalid (the file is corrupted)",
offchainTxId.ToString(),
});
- var coordinatorToTest2 = new CcjCoordinator(network, folder, rpc, coordinatorToTest.RoundConfig);
+ var coordinatorToTest2 = new CcjCoordinator(network, Global.TrustedNodeNotifyingBehavior, folder, rpc, coordinatorToTest.RoundConfig);
coordinatorToTest2.Dispose();
txIds = await File.ReadAllLinesAsync(cjfile);
Assert.Single(txIds);

MODIFY
WalletWasabi/Services/CcjCoordinator.cs
WalletWasabi/Services/CcjCoordinator.cs
@@ -31,13 +31,16 @@ namespace WalletWasabi.Services
public Network Network { get; }
+ public TrustedNodeNotifyingBehavior TrustedNodeNotifyingBehavior { get; }
+
public string FolderPath { get; }
public UtxoReferee UtxoReferee { get; }
- public CcjCoordinator(Network network, string folderPath, RPCClient rpc, CcjRoundConfig roundConfig)
+ public CcjCoordinator(Network network, TrustedNodeNotifyingBehavior trustedNodeNotifyingBehavior, string folderPath, RPCClient rpc, CcjRoundConfig roundConfig)
{
Network = Guard.NotNull(nameof(network), network);
+ TrustedNodeNotifyingBehavior = Guard.NotNull(nameof(trustedNodeNotifyingBehavior), trustedNodeNotifyingBehavior);
FolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(folderPath), folderPath, trim: true);
RpcClient = Guard.NotNull(nameof(rpc), rpc);
RoundConfig = Guard.NotNull(nameof(roundConfig), roundConfig);
@@ -111,6 +114,20 @@ namespace WalletWasabi.Services
Logger.LogInfo<CcjCoordinator>($"{nameof(CcjRound.RoundCount)} file was corrupt. Resetting to 0.");
Logger.LogDebug<CcjCoordinator>(ex);
}
+
+ TrustedNodeNotifyingBehavior.Block += TrustedNodeNotifyingBehavior_BlockAsync;
+ }
+
+ private async void TrustedNodeNotifyingBehavior_BlockAsync(object sender, Block block)
+ {
+ try
+ {
+ await ProcessBlockAsync(block);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogWarning<CcjCoordinator>(ex);
+ }
}
public async Task ProcessBlockAsync(Block block)
@@ -370,6 +387,11 @@ namespace WalletWasabi.Services
{
using (RoundsListLock.Lock())
{
+ if (TrustedNodeNotifyingBehavior != null)
+ {
+ TrustedNodeNotifyingBehavior.Block -= TrustedNodeNotifyingBehavior_BlockAsync;
+ }
+
foreach (CcjRound round in Rounds)
{
round.StatusChanged -= Round_StatusChangedAsync;

MODIFY
WalletWasabi/Services/IndexBuilderService.cs
WalletWasabi/Services/IndexBuilderService.cs
@@ -28,8 +28,6 @@ namespace WalletWasabi.Services
private Dictionary<OutPoint, Script> Bech32UtxoSet { get; }
private List<ActionHistoryHelper> Bech32UtxoSetHistory { get; }
- public event EventHandler<Block> NewBlock;
-
private class ActionHistoryHelper
{
public enum Operation
@@ -231,11 +229,6 @@ namespace WalletWasabi.Services
continue;
}
- if (blockCount - height <= 2)
- {
- NewBlock?.Invoke(this, block);
- }
-
if (prevHash != null)
{
// In case of reorg:

Make coordinator use P2P block notifications