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

Refactor PeerManager to introduce Connectivity Module #6858

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

Conversation

diegomrsantos
Copy link

@diegomrsantos diegomrsantos commented Jan 24, 2025

Issue Addressed

#6860

Proposed Changes

  1. Introduction of Connectivity Struct:

    • Added a new Connectivity struct that uses the NetworkGlobalsProvider trait.
    • Encapsulates peer management parameters and methods such as dial_peer, peers_discovered, and maintain_peer_count.
  2. NetworkGlobalsProvider Trait:

    • A new trait NetworkGlobalsProvider is introduced. The idea is to create a generic and minimal invasive interface to the current code which other projects are free to decide how to implement.
    • Methods include connected_outbound_only_peers, connected_or_dialing_peers, update_min_ttl, and should_dial.
  3. Refactoring PeerManager:

    • PeerManager now includes the Connectivity struct.
    • Methods within PeerManager delegate connectivity-related operations to the Connectivity struct.
      Removed direct use of discovery_enabled and network global operations from PeerManager.
  4. File Changes:

    • connectivity.rs: Added implementation of the Connectivity struct.
    • mod.rs: Updated to include the new Connectivity struct and network_globals_provider.
    • network_behaviour.rs: Updated to use connectivity methods for checking connection limits.
    • network_globals_provider.rs: New file introducing the NetworkGlobalsProvider trait and its implementation for Arc<NetworkGlobals>.

Additional Info

The plan is to continue refactoring PeerManager and introducing new modules.

@CLAassistant
Copy link

CLAassistant commented Jan 24, 2025

CLA assistant check
All committers have signed the CLA.

@diegomrsantos diegomrsantos force-pushed the pm-connectivity-to-unstable branch from 472cf2e to 6d4bb6f Compare January 24, 2025 18:18
@diegomrsantos diegomrsantos changed the title Pm connectivity to unstable Refactor Peer Management to introduce Connectivity Module Jan 27, 2025
@diegomrsantos diegomrsantos marked this pull request as ready for review January 27, 2025 12:14
@diegomrsantos diegomrsantos requested a review from jxs as a code owner January 27, 2025 12:14
@diegomrsantos diegomrsantos changed the title Refactor Peer Management to introduce Connectivity Module Refactor PeerManager to introduce Connectivity Module Jan 27, 2025
Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

This looks good to me. Seems like a good way to split things up.

Historically there have been some sneaky bugs in the peer manager when we try to modify its workings. It usually requires a bit more testing than most other parts of code.

We are currently in the planning of making a testnet release for an upcomming fork. We'll have to decide whether to put this in with electra or leave it for later.

Have you done any testing on lighthouse for this?

if wanted_peers > 0 {
self.events
.push(PeerManagerEvent::DiscoverPeers(wanted_peers));
// debug!(self.log,
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this log?

I notice this is down lower in the file

Copy link
Author

Choose a reason for hiding this comment

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

I'm very sorry about that. I decided to make the code more similar to the original one. Please retake a look.

.update_min_ttl(&peer_id, *min_ttl);
}
if self.dial_peer(enr.clone()) {
//debug!(self.log, "Added discovered ENR peer to dial queue"; "peer_id" => %peer_id);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this log?

}
}

/// This function checks the status of our current peers and optionally requests a discovery
Copy link
Member

Choose a reason for hiding this comment

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

These comments are now longer correct. This function returns a usize and doesn't request any discoveries. Maybe we need to change the name of the function to better reflect this change of logic.

/// Peers that have been returned by discovery requests that are suitable for dialing are
/// returned here.
///
/// This function decides whether or not to dial these peers.
Copy link
Member

Choose a reason for hiding this comment

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

These comments should describe what the return value is used for as this logic has changed here and it might be easier for future people to understand when looking at what these functions do

@diegomrsantos diegomrsantos force-pushed the pm-connectivity-to-unstable branch 4 times, most recently from e3e4d4f to 8dd9692 Compare January 28, 2025 15:37
@diegomrsantos diegomrsantos force-pushed the pm-connectivity-to-unstable branch from 8dd9692 to abd0f51 Compare January 28, 2025 19:31
@jimmygchen jimmygchen added ready-for-review The code is ready for review Networking labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Networking ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants