diff --git a/clients/client-core/src/client/topology_control.rs b/clients/client-core/src/client/topology_control.rs index b685cfb8b4..9f35f6c3f1 100644 --- a/clients/client-core/src/client/topology_control.rs +++ b/clients/client-core/src/client/topology_control.rs @@ -186,13 +186,10 @@ impl TopologyRefresher { /// # Arguments /// /// * `topology`: active topology constructed from validator api data - /// * `mixnodes_count`: total number of active mixnodes - fn check_layer_distribution( - &self, - active_topology: &NymTopology, - mixnodes_count: usize, - ) -> bool { + fn check_layer_distribution(&self, active_topology: &NymTopology) -> bool { let mixes = active_topology.mixes(); + let mixnodes_count = active_topology.num_mixnodes(); + if active_topology.gateways().is_empty() { return false; } @@ -257,11 +254,10 @@ impl TopologyRefresher { Ok(gateways) => gateways, }; - let mixnodes_count = mixnodes.len(); let topology = nym_topology_from_detailed(mixnodes, gateways) .filter_system_version(&self.client_version); - if !self.check_layer_distribution(&topology, mixnodes_count) { + if !self.check_layer_distribution(&topology) { warn!("The current filtered active topology has extremely skewed layer distribution. It cannot be used."); None } else { diff --git a/common/topology/src/lib.rs b/common/topology/src/lib.rs index 6ef41c9aad..2e9cde725b 100644 --- a/common/topology/src/lib.rs +++ b/common/topology/src/lib.rs @@ -84,6 +84,10 @@ impl NymTopology { &self.mixes } + pub fn num_mixnodes(&self) -> usize { + self.mixes.values().flat_map(|m| m.iter()).count() + } + pub fn mixes_as_vec(&self) -> Vec { let mut mixes: Vec = vec![];