mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 03:41:02 +00:00
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:
@@ -225,6 +225,8 @@ pub struct Protocol<B: BlockT, H: ExHashT> {
|
|||||||
protocol_engine_by_name: HashMap<Cow<'static, [u8]>, ConsensusEngineId>,
|
protocol_engine_by_name: HashMap<Cow<'static, [u8]>, ConsensusEngineId>,
|
||||||
/// Prometheus metrics.
|
/// Prometheus metrics.
|
||||||
metrics: Option<Metrics>,
|
metrics: Option<Metrics>,
|
||||||
|
/// The `PeerId`'s of all boot nodes.
|
||||||
|
boot_node_ids: Arc<HashSet<PeerId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -434,7 +436,8 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
|||||||
protocol_id: ProtocolId,
|
protocol_id: ProtocolId,
|
||||||
peerset_config: sc_peerset::PeersetConfig,
|
peerset_config: sc_peerset::PeersetConfig,
|
||||||
block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,
|
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)> {
|
) -> error::Result<(Protocol<B, H>, sc_peerset::PeersetHandle)> {
|
||||||
let info = chain.info();
|
let info = chain.info();
|
||||||
let sync = ChainSync::new(
|
let sync = ChainSync::new(
|
||||||
@@ -483,7 +486,8 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
|||||||
Some(Metrics::register(r)?)
|
Some(Metrics::register(r)?)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
},
|
||||||
|
boot_node_ids,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((protocol, peerset_handle))
|
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.peerset_handle.report_peer(who.clone(), rep::GENESIS_MISMATCH);
|
||||||
self.behaviour.disconnect_peer(&who);
|
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;
|
return CustomMessageOutcome::None;
|
||||||
}
|
}
|
||||||
if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version {
|
if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version {
|
||||||
@@ -2151,7 +2166,8 @@ mod tests {
|
|||||||
reserved_nodes: Vec::new(),
|
reserved_nodes: Vec::new(),
|
||||||
},
|
},
|
||||||
Box::new(DefaultBlockAnnounceValidator::new(client.clone())),
|
Box::new(DefaultBlockAnnounceValidator::new(client.clone())),
|
||||||
None
|
None,
|
||||||
|
Default::default(),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let dummy_peer_id = PeerId::random();
|
let dummy_peer_id = PeerId::random();
|
||||||
|
|||||||
@@ -185,6 +185,8 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let boot_node_ids = Arc::new(boot_node_ids);
|
||||||
|
|
||||||
// Check for duplicate bootnodes.
|
// Check for duplicate bootnodes.
|
||||||
known_addresses.iter()
|
known_addresses.iter()
|
||||||
.try_for_each(|(peer_id, addr)|
|
.try_for_each(|(peer_id, addr)|
|
||||||
@@ -245,7 +247,8 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
|||||||
params.protocol_id.clone(),
|
params.protocol_id.clone(),
|
||||||
peerset_config,
|
peerset_config,
|
||||||
params.block_announce_validator,
|
params.block_announce_validator,
|
||||||
params.metrics_registry.as_ref()
|
params.metrics_registry.as_ref(),
|
||||||
|
boot_node_ids.clone(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Build the swarm.
|
// Build the swarm.
|
||||||
@@ -776,7 +779,7 @@ pub struct NetworkWorker<B: BlockT + 'static, H: ExHashT> {
|
|||||||
/// Prometheus network metrics.
|
/// Prometheus network metrics.
|
||||||
metrics: Option<Metrics>,
|
metrics: Option<Metrics>,
|
||||||
/// The `PeerId`'s of all boot nodes.
|
/// The `PeerId`'s of all boot nodes.
|
||||||
boot_node_ids: HashSet<PeerId>,
|
boot_node_ids: Arc<HashSet<PeerId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Metrics {
|
struct Metrics {
|
||||||
|
|||||||
Reference in New Issue
Block a user