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:
parent
de91c77cb2
commit
641f6be3f0
@ -101,7 +101,7 @@ pub struct Config {
|
|||||||
/// List of libp2p nodes to initially connect to.
|
/// List of libp2p nodes to initially connect to.
|
||||||
pub libp2p_nodes: Vec<Multiaddr>,
|
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>,
|
pub trusted_peers: Vec<PeerIdSerialized>,
|
||||||
|
|
||||||
/// Disables peer scoring altogether.
|
/// Disables peer scoring altogether.
|
||||||
|
@ -144,6 +144,14 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
|
|||||||
// initialise the node's ID
|
// initialise the node's ID
|
||||||
let local_keypair = utils::load_private_key(&config, &log);
|
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
|
// set up a collection of variables accessible outside of the network crate
|
||||||
let network_globals = {
|
let network_globals = {
|
||||||
// Create an ENR or load from disk if appropriate
|
// 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(
|
let globals = NetworkGlobals::new(
|
||||||
enr,
|
enr,
|
||||||
meta_data,
|
meta_data,
|
||||||
config
|
trusted_peers,
|
||||||
.trusted_peers
|
|
||||||
.iter()
|
|
||||||
.map(|x| PeerId::from(x.clone()))
|
|
||||||
.collect(),
|
|
||||||
config.disable_peer_scoring,
|
config.disable_peer_scoring,
|
||||||
&log,
|
&log,
|
||||||
);
|
);
|
||||||
@ -275,6 +279,11 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
|
|||||||
.with_peer_score(params, thresholds)
|
.with_peer_score(params, thresholds)
|
||||||
.expect("Valid score params and 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
|
// If we are using metrics, then register which topics we want to make sure to keep
|
||||||
// track of
|
// track of
|
||||||
if ctx.libp2p_registry.is_some() {
|
if ctx.libp2p_registry.is_some() {
|
||||||
|
Loading…
Reference in New Issue
Block a user