Take out hosted services registration from core node
MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -33,7 +33,7 @@ namespace WalletWasabi.Backend
public P2pNode P2pNode { get; private set; }
- public HostedServices HostedServices { get; set; }
+ public HostedServices HostedServices { get; }
public IndexBuilderService IndexBuilderService { get; private set; }

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -199,7 +199,6 @@ namespace WalletWasabi.Gui
new CoreNodeParams(
Network,
BitcoinStore.MempoolService,
- HostedServices,
Config.LocalBitcoinCoreDataDir,
tryRestart: false,
tryDeleteDataDir: false,
@@ -213,6 +212,10 @@ namespace WalletWasabi.Gui
Cache),
cancel)
.ConfigureAwait(false);
+
+ HostedServices.Register<BlockNotifier>(new BlockNotifier(TimeSpan.FromSeconds(7), BitcoinCoreNode.RpcClient, BitcoinCoreNode.P2pNode), "Block Notifier");
+ HostedServices.Register<RpcMonitor>(new RpcMonitor(TimeSpan.FromSeconds(7), BitcoinCoreNode.RpcClient), "RPC Monitor");
+ HostedServices.Register<RpcFeeProvider>(new RpcFeeProvider(TimeSpan.FromMinutes(1), BitcoinCoreNode.RpcClient), "RPC Fee Provider");
}
}
catch (Exception ex)

MODIFY
WalletWasabi.Tests/Helpers/TestNodeBuilder.cs
WalletWasabi.Tests/Helpers/TestNodeBuilder.cs
@@ -14,13 +14,12 @@ namespace WalletWasabi.Tests.Helpers
{
public static class TestNodeBuilder
{
- public static async Task<CoreNode> CreateAsync(HostedServices hostedServices, [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "", string additionalFolder = "", MempoolService? mempoolService = null)
+ public static async Task<CoreNode> CreateAsync([CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "", string additionalFolder = "", MempoolService? mempoolService = null)
{
var network = Network.RegTest;
var nodeParameters = new CoreNodeParams(
network,
mempoolService ?? new MempoolService(),
- hostedServices,
Path.Combine(Common.GetWorkDir(callerFilePath, callerMemberName), additionalFolder),
tryRestart: true,
tryDeleteDataDir: true,

MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/NodeBuildingTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/NodeBuildingTests.cs
@@ -16,21 +16,14 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task CanBuildCoreNodeAsync()
{
- using var services = new HostedServices();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync(CancellationToken.None);
+ var coreNode = await TestNodeBuilder.CreateAsync();
await coreNode.TryStopAsync();
- await services.StopAllAsync(CancellationToken.None);
}
[Fact]
public async Task NodesDifferAsync()
{
- using var services1 = new HostedServices();
- using var services2 = new HostedServices();
- var coreNodes = await Task.WhenAll(TestNodeBuilder.CreateAsync(services1, additionalFolder: "0"), TestNodeBuilder.CreateAsync(services2, additionalFolder: "1"));
- await services1.StartAllAsync(CancellationToken.None);
- await services2.StartAllAsync(CancellationToken.None);
+ var coreNodes = await Task.WhenAll(TestNodeBuilder.CreateAsync(additionalFolder: "0"), TestNodeBuilder.CreateAsync(additionalFolder: "1"));
CoreNode node1 = coreNodes[0];
CoreNode node2 = coreNodes[1];
try
@@ -41,8 +34,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services1.StopAllAsync(CancellationToken.None);
- await services2.StopAllAsync(CancellationToken.None);
await Task.WhenAll(node1.TryStopAsync(), node2.TryStopAsync());
}
}
@@ -50,9 +41,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task RpcWorksAsync()
{
- using var services = new HostedServices();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync(CancellationToken.None);
+ var coreNode = await TestNodeBuilder.CreateAsync();
try
{
var blockCount = await coreNode.RpcClient.GetBlockCountAsync();
@@ -60,7 +49,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync(CancellationToken.None);
await coreNode.TryStopAsync();
}
}
@@ -68,9 +56,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task P2pWorksAsync()
{
- using var services = new HostedServices();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync(CancellationToken.None);
+ var coreNode = await TestNodeBuilder.CreateAsync();
using var node = await coreNode.CreateNewP2pNodeAsync();
try
{
@@ -80,7 +66,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync(CancellationToken.None);
node.Disconnect();
await coreNode.TryStopAsync();
}

MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/P2pBasedTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/P2pBasedTests.cs
@@ -24,9 +24,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task MempoolNotifiesAsync()
{
- using HostedServices services = new();
- CoreNode coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync();
+ CoreNode coreNode = await TestNodeBuilder.CreateAsync();
using var node = await coreNode.CreateNewP2pNodeAsync();
try
@@ -91,7 +89,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync();
node.Disconnect();
await coreNode.TryStopAsync();
}
@@ -100,9 +97,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task TrustedNotifierNotifiesTxAsync()
{
- using HostedServices services = new();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync();
+ var coreNode = await TestNodeBuilder.CreateAsync();
try
{
var rpc = coreNode.RpcClient;
@@ -143,7 +138,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync();
await coreNode.TryStopAsync();
}
}
@@ -151,8 +145,10 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task BlockNotifierTestsAsync()
{
+ var coreNode = await TestNodeBuilder.CreateAsync();
using HostedServices services = new();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
+ services.Register<BlockNotifier>(new BlockNotifier(TimeSpan.FromSeconds(7), coreNode.RpcClient, coreNode.P2pNode), "Block Notifier");
+
await services.StartAllAsync();
try
{

MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/RpcBasedTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/RpcBasedTests.cs
@@ -152,9 +152,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task AllFeeEstimateAsync()
{
- using var services = new HostedServices();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync(CancellationToken.None);
+ var coreNode = await TestNodeBuilder.CreateAsync();
try
{
var rpc = coreNode.RpcClient;
@@ -171,7 +169,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync(CancellationToken.None);
await coreNode.TryStopAsync();
}
}
@@ -179,9 +176,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task CantDoubleSpendAsync()
{
- using var services = new HostedServices();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync(CancellationToken.None);
+ var coreNode = await TestNodeBuilder.CreateAsync();
try
{
var rpc = coreNode.RpcClient;
@@ -216,7 +211,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync(CancellationToken.None);
await coreNode.TryStopAsync();
}
}
@@ -224,9 +218,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public async Task VerboseBlockInfoAsync()
{
- using var services = new HostedServices();
- var coreNode = await TestNodeBuilder.CreateAsync(services);
- await services.StartAllAsync(CancellationToken.None);
+ var coreNode = await TestNodeBuilder.CreateAsync();
try
{
var rpc = coreNode.RpcClient;
@@ -235,7 +227,6 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
}
finally
{
- await services.StopAllAsync(CancellationToken.None);
await coreNode.TryStopAsync();
}
}

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -29,8 +29,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
{
RuntimeParams.SetDataDir(Path.Combine(Common.DataDir, "RegTests", "Backend"));
RuntimeParams.LoadAsync().GetAwaiter().GetResult();
- var hostedServices = new HostedServices();
- BackendRegTestNode = TestNodeBuilder.CreateAsync(hostedServices, callerFilePath: "RegTests", callerMemberName: "BitcoinCoreData").GetAwaiter().GetResult();
+ BackendRegTestNode = TestNodeBuilder.CreateAsync(callerFilePath: "RegTests", callerMemberName: "BitcoinCoreData").GetAwaiter().GetResult();
var walletName = "wallet.dat";
BackendRegTestNode.RpcClient.CreateWalletAsync(walletName).GetAwaiter().GetResult();
@@ -79,15 +78,11 @@ namespace WalletWasabi.Tests.XunitConfiguration
}
Global = global;
- Global.HostedServices = hostedServices;
- var hostInitializationTask = BackendHost.RunWithTasksAsync();
+ BackendHost.RunWithTasksAsync().GetAwaiter().GetResult();
Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}");
HttpClient = new HttpClient();
BackendHttpClient = new ClearnetHttpClient(HttpClient, () => BackendEndPointUri);
-
- var delayTask = Task.Delay(3000);
- Task.WaitAny(delayTask, hostInitializationTask); // Wait for server to initialize (Without this OSX CI will fail)
}
/// <summary>String representation of backend URI: <c>http://localhost:RANDOM_PORT</c>.</summary>

MODIFY
WalletWasabi/BitcoinCore/CoreNode.cs
WalletWasabi/BitcoinCore/CoreNode.cs
@@ -31,7 +31,6 @@ namespace WalletWasabi.BitcoinCore
public EndPoint RpcEndPoint { get; private set; }
public IRPCClient RpcClient { get; private set; }
private BitcoindRpcProcessBridge Bridge { get; set; }
- public HostedServices HostedServices { get; private set; }
public string DataDir { get; private set; }
public Network Network { get; private set; }
public MempoolService MempoolService { get; private set; }
@@ -46,7 +45,6 @@ namespace WalletWasabi.BitcoinCore
{
var coreNode = new CoreNode
{
- HostedServices = coreNodeParams.HostedServices,
DataDir = coreNodeParams.DataDir,
Network = coreNodeParams.Network,
MempoolService = coreNodeParams.MempoolService
@@ -239,10 +237,6 @@ namespace WalletWasabi.BitcoinCore
await coreNode.P2pNode.ConnectAsync(cancel).ConfigureAwait(false);
cancel.ThrowIfCancellationRequested();
- coreNode.HostedServices.Register<BlockNotifier>(new BlockNotifier(TimeSpan.FromSeconds(7), coreNode.RpcClient, coreNode.P2pNode), "Block Notifier");
- coreNode.HostedServices.Register<RpcMonitor>(new RpcMonitor(TimeSpan.FromSeconds(7), coreNode.RpcClient), "RPC Monitor");
- coreNode.HostedServices.Register<RpcFeeProvider>(new RpcFeeProvider(TimeSpan.FromMinutes(1), coreNode.RpcClient), "RPC Fee Provider");
-
return coreNode;
}
}

MODIFY
WalletWasabi/BitcoinCore/CoreNodeParams.cs
WalletWasabi/BitcoinCore/CoreNodeParams.cs
@@ -12,7 +12,6 @@ namespace WalletWasabi.BitcoinCore
public CoreNodeParams(
Network network,
MempoolService mempoolService,
- HostedServices hostedServices,
string dataDir,
bool tryRestart,
bool tryDeleteDataDir,
@@ -27,7 +26,6 @@ namespace WalletWasabi.BitcoinCore
{
Network = Guard.NotNull(nameof(network), network);
MempoolService = Guard.NotNull(nameof(mempoolService), mempoolService);
- HostedServices = Guard.NotNull(nameof(hostedServices), hostedServices);
DataDir = Guard.NotNullOrEmptyOrWhitespace(nameof(dataDir), dataDir);
TryRestart = tryRestart;
TryDeleteDataDir = tryDeleteDataDir;
@@ -44,7 +42,6 @@ namespace WalletWasabi.BitcoinCore
public string DataDir { get; }
public Network Network { get; }
public MempoolService MempoolService { get; }
- public HostedServices HostedServices { get; }
public bool TryRestart { get; }
public bool TryDeleteDataDir { get; }
public int? TxIndex { get; }

Take out hosted services registration from core node