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

Explicit peers #5333

Merged
merged 5 commits into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/src/config.rs
Expand Up @@ -101,7 +101,7 @@ pub struct Config {
/// List of libp2p nodes to initially connect to.
pub libp2p_nodes: Vec<Multiaddr>,

/// List of trusted libp2p nodes which are not scored.
/// List of trusted libp2p nodes which are not scored and marked as explicit.
pub trusted_peers: Vec<PeerIdSerialized>,

/// Disables peer scoring altogether.
Expand Down
19 changes: 14 additions & 5 deletions beacon_node/lighthouse_network/src/service/mod.rs
Expand Up @@ -144,6 +144,14 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
// initialise the node's ID
let local_keypair = utils::load_private_key(&config, &log);

// Trusted peers will also be marked as explicit in GossipSub.
// Cfr. https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#explicit-peering-agreements
let trusted_peers: Vec<PeerId> = config
.trusted_peers
.iter()
.map(|x| PeerId::from(x.clone()))
.collect();

// set up a collection of variables accessible outside of the network crate
let network_globals = {
// Create an ENR or load from disk if appropriate
Expand All @@ -158,11 +166,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
let globals = NetworkGlobals::new(
enr,
meta_data,
config
.trusted_peers
.iter()
.map(|x| PeerId::from(x.clone()))
.collect(),
trusted_peers,
config.disable_peer_scoring,
&log,
);
Expand Down Expand Up @@ -275,6 +279,11 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
.with_peer_score(params, thresholds)
.expect("Valid score params and thresholds");

// Mark trusted peers as explicit.
for explicit_peer in config.trusted_peers.iter() {
gossipsub.add_explicit_peer(&PeerId::from(explicit_peer.clone()));
}

(gossipsub, update_gossipsub_scores)
};

Expand Down