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

Basic peer manager based on libp2p peer_store and connection_limits #126

Open
wants to merge 15 commits into
base: unstable
Choose a base branch
from

Conversation

dknopik
Copy link
Member

@dknopik dknopik commented Feb 5, 2025

Draft of basic peer manager using connection_limits and a preliminary version of peer_store.

This is just a draft, as the exact design of peer_store is still TBD and a few things are missing.

@dknopik
Copy link
Member Author

dknopik commented Feb 10, 2025

I propose we review and merge this, even though upstream has not merged the peer store yet. We need something to test. Very open for other suggestions though

@dknopik dknopik marked this pull request as ready for review February 10, 2025 14:52
@dknopik dknopik requested review from diegomrsantos and jxs February 10, 2025 14:53
Cargo.toml Outdated Show resolved Hide resolved
.filter_map(|(enr, _)| manager.discovered_peer(enr))
.collect::<Vec<_>>();
for dial in to_dial {
let _ = self.swarm.dial(dial);

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

The event only allows us to dial a single peer.

Choose a reason for hiding this comment

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

Yes, I think it creates an event for each peer. But honestly, I don't know the reason. Maybe decoupling?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jxs: Is there a relevant difference between these approaches to dial?

Choose a reason for hiding this comment

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

We could also encapsulate this code inside the Peer Manager. Similar to https://github.com/sigp/lighthouse/blob/stable/beacon_node/lighthouse_network/src/service/mod.rs#L1845

Comment on lines 33 to 46
/// A fraction of `PeerManager::target_peers` that we allow to connect to us in excess of
/// `PeerManager::target_peers`. For clarity, if `PeerManager::target_peers` is 50 and
/// PEER_EXCESS_FACTOR = 0.1 we allow 10% more nodes, i.e 55.
const PEER_EXCESS_FACTOR: f32 = 0.1;
/// A fraction of `PeerManager::target_peers` that we want to be outbound-only connections.
const TARGET_OUTBOUND_ONLY_FACTOR: f32 = 0.3;
/// A fraction of `PeerManager::target_peers` that if we get below, we start a discovery query to
/// reach our target. MIN_OUTBOUND_ONLY_FACTOR must be < TARGET_OUTBOUND_ONLY_FACTOR.
const MIN_OUTBOUND_ONLY_FACTOR: f32 = 0.2;
/// The fraction of extra peers beyond the PEER_EXCESS_FACTOR that we allow us to dial for when
/// requiring subnet peers. More specifically, if our target peer limit is 50, and our excess peer
/// limit is 55, and we are at 55 peers, the following parameter provisions a few more slots of
/// dialing priority peers we need for validator duties.
const PRIORITY_PEER_EXCESS: f32 = 0.2;
Copy link

@diegomrsantos diegomrsantos Feb 17, 2025

Choose a reason for hiding this comment

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

Would this be better encapsulated inside the Peer Manager?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, will do

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.

2 participants