Create tx broadcaster in global ctor
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -102,6 +102,7 @@ namespace WalletWasabi.Gui
Synchronizer = new WasabiSynchronizer(Network, BitcoinStore, httpClientFactory);
LegalChecker = new(DataDir);
+ TransactionBroadcaster = new TransactionBroadcaster(Network, BitcoinStore, Synchronizer, WalletManager);
}
}
@@ -296,7 +297,7 @@ namespace WalletWasabi.Gui
cancel.ThrowIfCancellationRequested();
- TransactionBroadcaster = new TransactionBroadcaster(Network, BitcoinStore, Synchronizer, Nodes, WalletManager, BitcoinCoreNode?.RpcClient);
+ TransactionBroadcaster.Initialize(Nodes, BitcoinCoreNode?.RpcClient);
CoinJoinProcessor = new CoinJoinProcessor(Synchronizer, WalletManager, BitcoinCoreNode?.RpcClient);
#region JsonRpcServerInitialization

MODIFY
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
@@ -19,23 +19,27 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
{
public class TransactionBroadcaster
{
- public TransactionBroadcaster(Network network, BitcoinStore bitcoinStore, WasabiSynchronizer synchronizer, NodesGroup nodes, WalletManager walletManager, IRPCClient rpc)
+ public TransactionBroadcaster(Network network, BitcoinStore bitcoinStore, WasabiSynchronizer synchronizer, WalletManager walletManager)
{
- Nodes = Guard.NotNull(nameof(nodes), nodes);
Network = Guard.NotNull(nameof(network), network);
BitcoinStore = Guard.NotNull(nameof(bitcoinStore), bitcoinStore);
Synchronizer = Guard.NotNull(nameof(synchronizer), synchronizer);
WalletManager = Guard.NotNull(nameof(walletManager), walletManager);
- RpcClient = rpc;
}
public BitcoinStore BitcoinStore { get; }
public WasabiSynchronizer Synchronizer { get; }
public Network Network { get; }
- public NodesGroup Nodes { get; }
- public IRPCClient RpcClient { get; private set; }
+ public NodesGroup? Nodes { get; private set; }
+ public IRPCClient? RpcClient { get; private set; }
public WalletManager WalletManager { get; }
+ public void Initialize(NodesGroup nodes, IRPCClient? rpc)
+ {
+ Nodes = Guard.NotNull(nameof(nodes), nodes);
+ RpcClient = rpc;
+ }
+
private async Task BroadcastTransactionToNetworkNodeAsync(SmartTransaction transaction, Node node)
{
Logger.LogInfo($"Trying to broadcast transaction with random node ({node.RemoteSocketAddress}):{transaction.GetHash()}.");
@@ -143,7 +147,12 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
throw new InvalidOperationException($"Transaction broadcasting to nodes does not work in {Network.RegTest}.");
}
- Node node = Nodes.ConnectedNodes.RandomElement();
+ if (Nodes is null)
+ {
+ throw new InvalidOperationException($"Nodes are not yet initialized.");
+ }
+
+ Node? node = Nodes.ConnectedNodes.RandomElement();
while (node is null || !node.IsConnected || Nodes.ConnectedNodes.Count < 5)
{
// As long as we are connected to at least 4 nodes, we can always try again.
@@ -189,6 +198,11 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
private async Task BroadcastTransactionWithRpcAsync(SmartTransaction transaction)
{
+ if (RpcClient is null)
+ {
+ throw new InvalidOperationException("Trying to broadcast on RPC but it is not initialized.");
+ }
+
await RpcClient.SendRawTransactionAsync(transaction.Transaction).ConfigureAwait(false);
BelieveTransaction(transaction);
Logger.LogInfo($"Transaction is successfully broadcasted with RPC: {transaction.GetHash()}.");

Create tx broadcaster in global ctor