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
This commit is contained in:
Bastian Köcher
2020-03-24 15:24:09 +01:00
committed by GitHub
parent ba06d5ef64
commit 6beb6acbd5
2 changed files with 24 additions and 5 deletions
+19 -3
View File
@@ -225,6 +225,8 @@ pub struct Protocol<B: BlockT, H: ExHashT> {
protocol_engine_by_name: HashMap<Cow<'static, [u8]>, ConsensusEngineId>,
/// Prometheus metrics.
metrics: Option<Metrics>,
/// The `PeerId`'s of all boot nodes.
boot_node_ids: Arc<HashSet<PeerId>>,
}
#[derive(Default)]
@@ -434,7 +436,8 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
protocol_id: ProtocolId,
peerset_config: sc_peerset::PeersetConfig,
block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,
metrics_registry: Option<&Registry>
metrics_registry: Option<&Registry>,
boot_node_ids: Arc<HashSet<PeerId>>,
) -> error::Result<(Protocol<B, H>, sc_peerset::PeersetHandle)> {
let info = chain.info();
let sync = ChainSync::new(
@@ -483,7 +486,8 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
Some(Metrics::register(r)?)
} else {
None
}
},
boot_node_ids,
};
Ok((protocol, peerset_handle))
@@ -1014,6 +1018,17 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
);
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();