From 6beb6acbd574b74e9f02dc43fbc859e4890d0ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 24 Mar 2020 15:24:09 +0100 Subject: [PATCH] Print an error when a bootnode is on a different chain (#5377) * Print an error when a bootnode is on a different chain * Fix tests --- substrate/client/network/src/protocol.rs | 22 +++++++++++++++++++--- substrate/client/network/src/service.rs | 7 +++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs index f76c49fd76..7cf568065e 100644 --- a/substrate/client/network/src/protocol.rs +++ b/substrate/client/network/src/protocol.rs @@ -225,6 +225,8 @@ pub struct Protocol { protocol_engine_by_name: HashMap, ConsensusEngineId>, /// Prometheus metrics. metrics: Option, + /// The `PeerId`'s of all boot nodes. + boot_node_ids: Arc>, } #[derive(Default)] @@ -434,7 +436,8 @@ impl Protocol { protocol_id: ProtocolId, peerset_config: sc_peerset::PeersetConfig, block_announce_validator: Box + Send>, - metrics_registry: Option<&Registry> + metrics_registry: Option<&Registry>, + boot_node_ids: Arc>, ) -> error::Result<(Protocol, sc_peerset::PeersetHandle)> { let info = chain.info(); let sync = ChainSync::new( @@ -483,7 +486,8 @@ impl Protocol { Some(Metrics::register(r)?) } else { None - } + }, + boot_node_ids, }; Ok((protocol, peerset_handle)) @@ -1014,6 +1018,17 @@ impl Protocol { ); self.peerset_handle.report_peer(who.clone(), rep::GENESIS_MISMATCH); self.behaviour.disconnect_peer(&who); + + if self.boot_node_ids.contains(&who) { + error!( + target: "sync", + "Bootnode with peer id `{}` is on a different chain (our genesis: {} theirs: {})", + who, + self.genesis_hash, + status.genesis_hash, + ); + } + return CustomMessageOutcome::None; } if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version { @@ -2151,7 +2166,8 @@ mod tests { reserved_nodes: Vec::new(), }, Box::new(DefaultBlockAnnounceValidator::new(client.clone())), - None + None, + Default::default(), ).unwrap(); let dummy_peer_id = PeerId::random(); diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 83492e2e93..e06d3bd13e 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -185,6 +185,8 @@ impl NetworkWorker { } } + let boot_node_ids = Arc::new(boot_node_ids); + // Check for duplicate bootnodes. known_addresses.iter() .try_for_each(|(peer_id, addr)| @@ -245,7 +247,8 @@ impl NetworkWorker { params.protocol_id.clone(), peerset_config, params.block_announce_validator, - params.metrics_registry.as_ref() + params.metrics_registry.as_ref(), + boot_node_ids.clone(), )?; // Build the swarm. @@ -776,7 +779,7 @@ pub struct NetworkWorker { /// Prometheus network metrics. metrics: Option, /// The `PeerId`'s of all boot nodes. - boot_node_ids: HashSet, + boot_node_ids: Arc>, } struct Metrics {