Prevent 0 peers and increase max connections
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -279,7 +279,7 @@ namespace WalletWasabi.Gui
await AddKnownBitcoinFullNodeAsHiddenServiceAsync(AddressManager);
}
Nodes = new NodesGroup(Network, connectionParameters, requirements: Constants.NodeRequirements);
-
+ Nodes.MaximumNodeConnection = 12;
RegTestMempoolServingNode = null;
}

MODIFY
WalletWasabi/Wallets/P2pBlockProvider.cs
WalletWasabi/Wallets/P2pBlockProvider.cs
@@ -109,15 +109,12 @@ namespace WalletWasabi.Wallets
if (!block.Check())
{
Logger.LogInfo($"Disconnected node: {node.RemoteSocketAddress}, because invalid block received.");
- node.DisconnectAsync("Invalid block received.");
+ DisconnectNode(node, "Invalid block received.", force: true);
continue;
}
- if (Nodes.ConnectedNodes.Count > 1) // To minimize risking missing unconfirmed transactions.
- {
Logger.LogInfo($"Disconnected node: {node.RemoteSocketAddress}. Block downloaded: {block.GetHash()}.");
- node.DisconnectAsync("Thank you!");
- }
+ DisconnectNode(node, "Thank you!");
await NodeTimeoutsAsync(false).ConfigureAwait(false);
}
@@ -127,14 +124,14 @@ namespace WalletWasabi.Wallets
await NodeTimeoutsAsync(true).ConfigureAwait(false);
- node.DisconnectAsync("Block download took too long.");
+ DisconnectNode(node, "Block download took too long."); // it could be a slow connection and not a misbehaving node
continue;
}
catch (Exception ex)
{
Logger.LogDebug(ex);
Logger.LogInfo($"Disconnected node: {node.RemoteSocketAddress}, because block download failed: {ex.Message}.");
- node.DisconnectAsync("Block download failed.");
+ DisconnectNode(node, "Block download failed.", force: true);
continue;
}
@@ -289,6 +286,15 @@ namespace WalletWasabi.Wallets
}
}
+ private void DisconnectNode(Node node, string reason, bool force = false)
+ {
+ if (Nodes.ConnectedNodes.Count > 2 || force)
+ {
+ node.DisconnectAsync(reason);
+ }
+ }
+
+
/// <summary>
/// Current timeout used when downloading a block from the remote node. It is defined in seconds.
/// </summary>

Prevent 0 peers and increase max connections