Skip to content

Commit

Permalink
Make OnlyStaticPeers load only static peers (#7514)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Sep 30, 2024
1 parent 481f302 commit b4b0b02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Nethermind/Nethermind.Init/Steps/InitializeNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ private async Task InitPeer()
_ = new NodeSourceToDiscV4Feeder(enrDiscovery, _api.DiscoveryApp, 50).Run(_api.ProcessExit!.Token);
}

CompositeNodeSource nodeSources = new(_api.StaticNodesManager, nodesLoader, enrDiscovery, _api.DiscoveryApp);
CompositeNodeSource nodeSources = _networkConfig.OnlyStaticPeers
? new(_api.StaticNodesManager, nodesLoader)
: new(_api.StaticNodesManager, nodesLoader, enrDiscovery, _api.DiscoveryApp);
_api.PeerPool = new PeerPool(nodeSources, _api.NodeStatsManager, peerStorage, _networkConfig, _api.LogManager);
_api.PeerManager = new PeerManager(
_api.RlpxPeer,
Expand Down
14 changes: 14 additions & 0 deletions src/Nethermind/Nethermind.Network.Test/NodesLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,19 @@ public void Can_load_persisted()
Assert.False(node.IsStatic);
}
}

[Test]
public void Can_load_only_static_nodes()
{
_networkConfig.StaticPeers = enode1String;
_networkConfig.Bootnodes = enode2String;
_networkConfig.OnlyStaticPeers = true;
List<Node> nodes = _loader.LoadInitialList();

Check failure on line 95 in src/Nethermind/Nethermind.Network.Test/NodesLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Build (release, Benchmarks)

'NodesLoader' does not contain a definition for 'LoadInitialList' and no accessible extension method 'LoadInitialList' accepting a first argument of type 'NodesLoader' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 95 in src/Nethermind/Nethermind.Network.Test/NodesLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Build (release, Benchmarks)

'NodesLoader' does not contain a definition for 'LoadInitialList' and no accessible extension method 'LoadInitialList' accepting a first argument of type 'NodesLoader' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 95 in src/Nethermind/Nethermind.Network.Test/NodesLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Benchmarks)

'NodesLoader' does not contain a definition for 'LoadInitialList' and no accessible extension method 'LoadInitialList' accepting a first argument of type 'NodesLoader' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 95 in src/Nethermind/Nethermind.Network.Test/NodesLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Benchmarks)

'NodesLoader' does not contain a definition for 'LoadInitialList' and no accessible extension method 'LoadInitialList' accepting a first argument of type 'NodesLoader' could be found (are you missing a using directive or an assembly reference?)
Assert.That(nodes.Count, Is.EqualTo(1));
foreach (Node node in nodes)
{
Assert.True(node.IsStatic);
}
}
}
}
11 changes: 7 additions & 4 deletions src/Nethermind/Nethermind.Network/NodesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ public IAsyncEnumerable<Node> DiscoverNodes(CancellationToken cancellationToken)
List<Node> allPeers = new();
LoadPeersFromDb(allPeers);

LoadConfigPeers(allPeers, _networkConfig.Bootnodes, n =>
if (!_networkConfig.OnlyStaticPeers)
{
n.IsBootnode = true;
if (_logger.IsDebug) _logger.Debug($"Bootnode : {n}");
});
LoadConfigPeers(allPeers, _networkConfig.Bootnodes, n =>
{
n.IsBootnode = true;
if (_logger.IsDebug) _logger.Debug($"Bootnode : {n}");
});
}

LoadConfigPeers(allPeers, _networkConfig.StaticPeers, n =>
{
Expand Down

0 comments on commit b4b0b02

Please sign in to comment.