Skip to content

Commit

Permalink
Explicit peers (#5333)
Browse files Browse the repository at this point in the history
* Merge branch 'unstable' into feature/explicit-peers

* Merge latest unstable

* refactor: remove explicit-peers flag, mark trusted peers as explicit instead

* feat(beacon_node): add explicit peers to GossipSub, mark as trusted

* feat(beacon_node): add explicit peers cli + config
  • Loading branch information
mempirate authored Mar 7, 2024
1 parent de91c77 commit 641f6be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()));
}

// If we are using metrics, then register which topics we want to make sure to keep
// track of
if ctx.libp2p_registry.is_some() {
Expand Down

0 comments on commit 641f6be

Please sign in to comment.