Ignore boot and reserved nodes with peer ID the same as in local node itself (#11851)

This commit is contained in:
Nazar Mokrynskyi
2022-07-17 00:24:46 +03:00
committed by GitHub
parent 74f0f45bb1
commit f514bc3892
+41 -4
View File
@@ -148,6 +148,47 @@ where
/// for the network processing to advance. From it, you can extract a `NetworkService` using
/// `worker.service()`. The `NetworkService` can be shared through the codebase.
pub fn new(mut params: Params<B, H, Client>) -> Result<Self, Error> {
// Private and public keys configuration.
let local_identity = params.network_config.node_key.clone().into_keypair()?;
let local_public = local_identity.public();
let local_peer_id = local_public.to_peer_id();
params.network_config.boot_nodes = params
.network_config
.boot_nodes
.into_iter()
.filter(|boot_node| {
if boot_node.peer_id == local_peer_id {
warn!(
target: "sub-libp2p",
"Local peer ID used in bootnode, ignoring: {}",
boot_node,
);
false
} else {
true
}
})
.collect();
params.network_config.default_peers_set.reserved_nodes = params
.network_config
.default_peers_set
.reserved_nodes
.into_iter()
.filter(|reserved_node| {
if reserved_node.peer_id == local_peer_id {
warn!(
target: "sub-libp2p",
"Local peer ID used in reserved node, ignoring: {}",
reserved_node,
);
false
} else {
true
}
})
.collect();
// Ensure the listen addresses are consistent with the transport.
ensure_addresses_consistent_with_transport(
params.network_config.listen_addresses.iter(),
@@ -190,10 +231,6 @@ where
.extra_sets
.insert(0, transactions_handler_proto.set_config());
// Private and public keys configuration.
let local_identity = params.network_config.node_key.clone().into_keypair()?;
let local_public = local_identity.public();
let local_peer_id = local_public.to_peer_id();
info!(
target: "sub-libp2p",
"🏷 Local node identity is: {}",