Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(networkmanager): regularly disconnect from random peers #2553

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

vpavlin
Copy link
Member

@vpavlin vpavlin commented Mar 25, 2024

Description

As reported by @chaitanyaprem, NetworkMonitor was stuck at maxConnections = 50 and although it discovered new peers, it was not able to connect with internal error Too many connections

This PR bumps macConnections to 150 and adds simple logic to regularly check and disconnect from half of currently connected peers selected randomly.

Changes

  • Add MaxConnectedPeers constant (150)
  • Set maxConnections to the constant above
  • Disconnect random peers regularly

How to test

  1. make networkmonitor
  2. ./build/networkmonitor --cluster-id=1 --metrics-server --rln-relay-eth-client-address=https://sepolia.infura.io/v3/...

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just added a naïve question :)

Comment on lines +138 to +141
if outConns.len >= toInt(MaxConnectedPeers/2):
for p in outConns[0 ..< toInt(outConns.len/2)]:
trace "Pruning Peer", Peer = $p
asyncSpawn(node.switch.disconnect(p))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why disconnect only out and not in too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, it is mostly NM discovering and connecting to other nodes, so the out is more important, but it is a good point to also make sure in is not filling up too much

@@ -429,7 +441,8 @@ proc initAndStartApp(

nodeBuilder.withNodeKey(key)
nodeBuilder.withRecord(record)
nodeBuilder.withPeerManagerConfig(maxRelayPeers = none(int), shardAware = true)
nodeBUilder.withSwitchConfiguration(maxConnections = some(MaxConnectedPeers))
nodeBuilder.withPeerManagerConfig(maxRelayPeers = some(20), shardAware = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shard aware peer manager will try to keep each shard populated with the same average # of peers.
It prevent too many in connections and also keep a % of max connection for service peers.
Are you sure that's what you want in this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I am not sure - what do you think?:) I probably want same average # of peers per shard. I don't really need any in connections since the main goal of NM is to discover nodes and keep track of the network, but not really to be discoverable by others, so limiting in connections might be useful?

I'll probably metge this PR and we can think about it for next one

@vpavlin vpavlin merged commit 70c53fc into master Mar 26, 2024
13 of 15 checks passed
@vpavlin vpavlin deleted the fix/networkmonitor-max-connections branch March 26, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants