Skip to content

Comments

Add basic peer manager#108

Closed
diegomrsantos wants to merge 8 commits intosigp:unstablefrom
diegomrsantos:peer-manager
Closed

Add basic peer manager#108
diegomrsantos wants to merge 8 commits intosigp:unstablefrom
diegomrsantos:peer-manager

Conversation

@diegomrsantos
Copy link
Member

@diegomrsantos diegomrsantos commented Jan 16, 2025

Issue Addressed

Related to #18

Proposed Changes

Dependencies:

Updated Cargo.toml and anchor/network/Cargo.toml to include new dependencies such as smallvec, arbitrary, delay_map, and itertools.

Network Types:

Added peer_manager module to anchor/network/src/lib.rs.

Network Implementation:

Enhanced anchor/network/src/behaviour.rs and anchor/network/src/network.rs to integrate the PeerManager.
The PeerManager is responsible for managing peer connections, including dialing, connecting, and disconnecting peers.
It includes logic to maintain the target peer count, ensuring the network has the desired number of peers connected.

Peer Manager:

Added a new peer_manager directory with modules for managing peers.
Implemented functionality in PeerManager to handle peer connections, maintain the target peer count, and manage peer discovery.

Additional Info

For now, it's mostly a copy from LH with a few modifications. However, there are efforts to make the LH code more modular, generic, and thus easier to reuse. See sigp/lighthouse#6840 and sigp/lighthouse#6757

@diegomrsantos diegomrsantos changed the title add basic peer manage add basic peer manager Jan 16, 2025
@diegomrsantos diegomrsantos force-pushed the peer-manager branch 3 times, most recently from 01ebfd7 to d0970c4 Compare January 22, 2025 13:47
Comment on lines +175 to +176
self.outbound_ping_peers.insert(peer_id);
self.events.push(PeerManagerEvent::Ping(peer_id));
Copy link
Member Author

Choose a reason for hiding this comment

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

@AgeManning do you know why we need this? I thought it was handled by libp2p's Ping.

Copy link
Member

Choose a reason for hiding this comment

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

We don't use libp2p ping instead we made our own in our RPC.

For anchor we can remove this, i think.

@diegomrsantos diegomrsantos marked this pull request as ready for review January 23, 2025 19:48
@diegomrsantos diegomrsantos requested review from AgeManning, dknopik and jking-aus and removed request for AgeManning and dknopik January 23, 2025 19:48
Comment on lines +379 to +393
// Updates peer's scores and unban any peers if required.
//let actions = self.peers.write().update_scores();
//for (peer_id, action) in actions {
// self.handle_score_action(&peer_id, action, None);
//}

// Update peer score metrics;
//self.update_peer_score_metrics();

// Prune any excess peers back to our target in such a way that incentivises good scores and
// a uniform distribution of subnets.
//self.prune_excess_peers();

// Unban any peers that have served their temporary ban timeout
//self.unban_temporary_banned_peers();
Copy link
Member

Choose a reason for hiding this comment

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

What's the plan for the commented calls here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We'll need it eventually, but it's not important for now. The plan is to reuse the LH code anyway.

Comment on lines +44 to +46
/// The current syncing state of the peer. The state may be determined after it's initial
/// connection.
sync_status: SyncStatus,
Copy link
Member

Choose a reason for hiding this comment

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

SSV has no sync status communicated via network, right?

Copy link
Member Author

@diegomrsantos diegomrsantos Jan 24, 2025

Choose a reason for hiding this comment

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

I don't know, we need input here. But I'd say it's not important for now.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, Anchor doesn't sync anything. So can prob remove

@diegomrsantos
Copy link
Member Author

We connect at the libp2p level but never perform a handshake with the remote peer, so both sides promptly disconnect. I think we can merge this PR as it is and address this next. It's tracked here #116.

@dknopik @jking-aus thoughts?

@diegomrsantos diegomrsantos changed the title add basic peer manager Add basic peer manager 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.

I didn't really review this. Looks like most of the stuff we have in Lighthouse.

I think its a good place to start so we can get it up and running then fine-tune, remove parts and maybe modularize lighthouse in the future to not require all the code.

}

#[derive(Clone, Copy, Debug, Serialize, PartialEq, AsRefStr, IntoStaticStr, EnumIter)]
pub enum ClientKind {
Copy link
Member

Choose a reason for hiding this comment

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

We probably should change this just to have Anchor and SSV.

I think they are using libp2p identify, so once we figure out their agent string, we can identify them here.


// helper function to identify clients from their agent_version. Returns the client
// kind and it's associated version and the OS kind.
fn client_from_agent_version(agent_version: &str) -> (ClientKind, String, String) {
Copy link
Member

Choose a reason for hiding this comment

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

We add theirs here

use PeerConnectionStatus::*;

#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct MetaData {
Copy link
Member

Choose a reason for hiding this comment

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

I think this might be their NodeInfo thingy


#[derive(Clone, Debug, Serialize)]
/// The current sync status of the peer.
pub enum SyncStatus {
Copy link
Member

Choose a reason for hiding this comment

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

Most of the stuff in this file we can remove, but fine to keep for now

@diegomrsantos diegomrsantos marked this pull request as draft January 29, 2025 14:35
@dknopik
Copy link
Member

dknopik commented Feb 20, 2025

Closing this, as #126 is now merged. Still, we should keep this one in mind for possible future extensions of the peer manager.

@dknopik dknopik closed this 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