From 29c073d25cfa2ebe9e49a805ba11f244e4c0381f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 5 Dec 2022 09:28:32 +0000 Subject: [PATCH] Fixed layer distribution skewness check (#1766) --- clients/client-core/src/client/topology_control.rs | 12 ++++-------- common/topology/src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) 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![];