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
This commit is contained in:
Jonas Bostoen 2024-03-07 23:22:39 +01:00 committed by GitHub
parent de91c77cb2
commit 641f6be3f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

View File

@ -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.

View File

@ -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
@ -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,
);
@ -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() {