Move node selection to P2PManager
MODIFY
WalletWasabi/Wallets/P2PBlockProvider.cs
WalletWasabi/Wallets/P2PBlockProvider.cs
@@ -42,14 +42,8 @@ public class P2PBlockProvider : IBlockProvider
cancellationToken.ThrowIfCancellationRequested();
try
{
- // If no connection, wait, then continue.
- while (Nodes.ConnectedNodes.Count == 0)
- {
- await Task.Delay(100, cancellationToken).ConfigureAwait(false);
- }
+ Node? node = await P2PNodesManager.GetNodeAsync(cancellationToken).ConfigureAwait(false);
- // Select a random node we are connected to.
- Node? node = Nodes.ConnectedNodes.RandomElement();
if (node is null || !node.IsConnected)
{
await Task.Delay(100, cancellationToken).ConfigureAwait(false);

MODIFY
WalletWasabi/Wallets/P2PNodesManager.cs
WalletWasabi/Wallets/P2PNodesManager.cs
+using System.Threading;
using System.Threading.Tasks;
using NBitcoin;
using NBitcoin.Protocol;
+using WalletWasabi.Extensions;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
@@ -20,6 +22,17 @@ public class P2PNodesManager
private bool IsTorEnabled { get; }
private int NodeTimeouts { get; set; }
+ public async Task<Node?> GetNodeAsync(CancellationToken cancellationToken)
+ {
+ while (Nodes.ConnectedNodes.Count == 0)
+ {
+ await Task.Delay(100, cancellationToken).ConfigureAwait(false);
+ }
+
+ // Select a random node we are connected to.
+ return Nodes.ConnectedNodes.RandomElement();
+ }
+
public void DisconnectNode(Node node, string logIfDisconnect, bool force = false)
{
if (Nodes.ConnectedNodes.Count > 3 || force)

MODIFY
WalletWasabi/Wallets/SmartBlockProvider.cs
WalletWasabi/Wallets/SmartBlockProvider.cs
@@ -24,9 +24,6 @@ public class SmartBlockProvider : IBlockProvider
{
}
- /// <summary>
- /// For testing.
- /// </summary>
internal SmartBlockProvider(IRepository<uint256, Block> blockRepository, IBlockProvider rpcBlockProvider, IBlockProvider specificNodeBlockProvider, IBlockProvider p2PBlockProvider, IMemoryCache cache)
{
BlockRepository = blockRepository;

Move node selection to P2PManager