Skip to content

Commit 641f6be

Browse files
author
Jonas Bostoen
authored
Explicit peers (#5333)
* 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
1 parent de91c77 commit 641f6be

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

beacon_node/lighthouse_network/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct Config {
101101
/// List of libp2p nodes to initially connect to.
102102
pub libp2p_nodes: Vec<Multiaddr>,
103103

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

107107
/// Disables peer scoring altogether.

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
144144
// initialise the node's ID
145145
let local_keypair = utils::load_private_key(&config, &log);
146146

147+
// Trusted peers will also be marked as explicit in GossipSub.
148+
// Cfr. https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#explicit-peering-agreements
149+
let trusted_peers: Vec<PeerId> = config
150+
.trusted_peers
151+
.iter()
152+
.map(|x| PeerId::from(x.clone()))
153+
.collect();
154+
147155
// set up a collection of variables accessible outside of the network crate
148156
let network_globals = {
149157
// Create an ENR or load from disk if appropriate
@@ -158,11 +166,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
158166
let globals = NetworkGlobals::new(
159167
enr,
160168
meta_data,
161-
config
162-
.trusted_peers
163-
.iter()
164-
.map(|x| PeerId::from(x.clone()))
165-
.collect(),
169+
trusted_peers,
166170
config.disable_peer_scoring,
167171
&log,
168172
);
@@ -275,6 +279,11 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
275279
.with_peer_score(params, thresholds)
276280
.expect("Valid score params and thresholds");
277281

282+
// Mark trusted peers as explicit.
283+
for explicit_peer in config.trusted_peers.iter() {
284+
gossipsub.add_explicit_peer(&PeerId::from(explicit_peer.clone()));
285+
}
286+
278287
// If we are using metrics, then register which topics we want to make sure to keep
279288
// track of
280289
if ctx.libp2p_registry.is_some() {

0 commit comments

Comments
 (0)