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

Merged
merged 24 commits into from
Feb 20, 2025

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
.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

Copy link
Member

@jxs jxs Feb 19, 2025

Choose a reason for hiding this comment

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

sorry, missed this!

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

no, one calls the other underneath :)

# Conflicts:
#	anchor/network/src/discovery.rs
#	anchor/network/src/network.rs
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Overall looks good to me Daniel! Left some minor suggestions

@@ -12,7 +12,7 @@ ethereum_ssz = { workspace = true }
ethereum_ssz_derive = { workspace = true }
futures = { workspace = true }
hex = "0.4.3"
libp2p = { version = "0.54", default-features = false, features = [
libp2p = { git = "https://github.com/libp2p/rust-libp2p.git", rev = "082eb16", default-features = false, features = [
Copy link
Member

Choose a reason for hiding this comment

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

interesting! Didn't know one could this, I suggest we use our own fork or yours Daniel, as Dr Huang may rebase and I fear that commit may disapear, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that can happen. The commit can disappear from the branch, but it stays in the repo if it was pushed. For example this commit is still accessible via the link: sigp/lighthouse@7f33d35, even though it no longer is in the current commit chain of the PR branch.

Copy link
Member

Choose a reason for hiding this comment

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

ok thanks for confirming Daniel :)

.filter_map(|(enr, _)| manager.discovered_peer(enr))
.collect::<Vec<_>>();
for dial in to_dial {
let _ = self.swarm.dial(dial);
Copy link
Member

@jxs jxs Feb 19, 2025

Choose a reason for hiding this comment

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

sorry, missed this!

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

no, one calls the other underneath :)

local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<(), ConnectionDenied> {
self.peer_store.handle_pending_inbound_connection(
Copy link
Member

Choose a reason for hiding this comment

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

for the sake of consistency I suggest we always check the connection_limits first as in the handle_pending_outbound connection as priority matters in these checks. By checking first peer_behaviour first we may introduce a peer to the peer-store that then may be reject by connection-limits and therefore we aborting the connection to it

Copy link
Member Author

Choose a reason for hiding this comment

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

I put it intentionally this way to add the peer to the peer store regardless (so that we are aware of it and can use it if we need any peers). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

ah! Interesting, yeah that seems clever Daniel, can we then leave a comment then explaining it?

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

jxs
jxs previously approved these changes Feb 20, 2025
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Daniel

local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<(), ConnectionDenied> {
self.peer_store.handle_pending_inbound_connection(
Copy link
Member

Choose a reason for hiding this comment

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

ah! Interesting, yeah that seems clever Daniel, can we then leave a comment then explaining it?

@@ -12,7 +12,7 @@ ethereum_ssz = { workspace = true }
ethereum_ssz_derive = { workspace = true }
futures = { workspace = true }
hex = "0.4.3"
libp2p = { version = "0.54", default-features = false, features = [
libp2p = { git = "https://github.com/libp2p/rust-libp2p.git", rev = "082eb16", default-features = false, features = [
Copy link
Member

Choose a reason for hiding this comment

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

ok thanks for confirming Daniel :)

jxs
jxs previously approved these changes Feb 20, 2025
@dknopik dknopik merged commit 8d2ae13 into sigp:unstable Feb 20, 2025
10 checks passed
@dknopik
Copy link
Member Author

dknopik commented Feb 20, 2025

Thanks everyone! 🎉

@dknopik dknopik mentioned this pull request Feb 20, 2025
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.

3 participants