From 24d9825a49f14ca73b6112fc5084e967dd11520f Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 28 Jan 2020 17:04:37 +0000 Subject: [PATCH 1/5] Fixed changelog v prefix on version --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e4b8acc1d..4f60174ed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog -## [Unreleased](https://github.com/nymtech/nym/tree/HEAD) +## [v0.4.0](https://github.com/nymtech/nym/tree/v0.4.0) (2020-01-28) -[Full Changelog](https://github.com/nymtech/nym/compare/0.4.0-rc.2...HEAD) +[Full Changelog](https://github.com/nymtech/nym/compare/v0.4.0-rc.2...v0.4.0) Nym 0.4.0 Platform @@ -10,9 +10,9 @@ In this release, we're taking a lot more care with version numbers, so that we c This release also integrates a health-checker and network topology refresh into the Nym client, so that the client can intelligently choose paths which route around any non-functional or incompatible nodes. -## [0.4.0-rc.2](https://github.com/nymtech/nym/tree/0.4.0-rc.2) (2020-01-28) +## [v0.4.0-rc.2](https://github.com/nymtech/nym/tree/v0.4.0-rc.2) (2020-01-28) -[Full Changelog](https://github.com/nymtech/nym/compare/v0.4.0-rc.1...0.4.0-rc.2) +[Full Changelog](https://github.com/nymtech/nym/compare/v0.4.0-rc.1...v0.4.0-rc.2) **Merged pull requests:** From d7b069e0e5b6ba84adc835e08d02fa91578f472f Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 18:06:39 +0000 Subject: [PATCH 2/5] validator responsible for running healtchecker loop --- validator/src/validator/mod.rs | 40 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/validator/src/validator/mod.rs b/validator/src/validator/mod.rs index 6ed56fa42b..26f031fab5 100644 --- a/validator/src/validator/mod.rs +++ b/validator/src/validator/mod.rs @@ -3,9 +3,12 @@ use crypto::identity::{ DummyMixIdentityKeyPair, DummyMixIdentityPrivateKey, DummyMixIdentityPublicKey, MixnetIdentityKeyPair, MixnetIdentityPrivateKey, MixnetIdentityPublicKey, }; +use directory_client::presence::Topology; use healthcheck::HealthChecker; -use log::debug; +use log::{debug, error, info}; +use std::time::Duration; use tokio::runtime::Runtime; +use topology::NymTopology; pub mod config; @@ -16,6 +19,7 @@ where Priv: MixnetIdentityPrivateKey, Pub: MixnetIdentityPublicKey, { + config: Config, #[allow(dead_code)] identity_keypair: IDPair, heath_check: HealthChecker, @@ -30,7 +34,33 @@ impl Validator(&self) { + let healthcheck_interval = Duration::from_secs_f64(self.config.health_check.interval); + debug!("healthcheck will run every {:?}", healthcheck_interval); + + loop { + let full_topology = T::new(self.config.health_check.directory_server.clone()); + let version_filtered_topology = full_topology.filter_node_versions( + crate::built_info::PKG_VERSION, + crate::built_info::PKG_VERSION, + crate::built_info::PKG_VERSION, + ); + + match self.heath_check.do_check(&version_filtered_topology).await { + Ok(health) => info!("current network health: \n{}", health), + Err(err) => error!("failed to perform healthcheck - {:?}", err), + }; + + tokio::time::delay_for(healthcheck_interval).await; } } @@ -39,9 +69,7 @@ impl Validator(); + rt.block_on(health_check_future); } } From eb3aa0baf18eb380f41b9025f207d7e35bd867f4 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 18:06:59 +0000 Subject: [PATCH 3/5] healthchecker no longer pulling entire topology itself --- common/healthcheck/src/lib.rs | 51 ++++++++------------------------ common/healthcheck/src/result.rs | 4 +-- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/common/healthcheck/src/lib.rs b/common/healthcheck/src/lib.rs index b95eefd454..7cd97692db 100644 --- a/common/healthcheck/src/lib.rs +++ b/common/healthcheck/src/lib.rs @@ -6,7 +6,7 @@ use log::{debug, error, info, trace}; use std::fmt::{Error, Formatter}; use std::marker::PhantomData; use std::time::Duration; -use topology::NymTopologyError; +use topology::{NymTopology, NymTopologyError}; pub mod config; mod path_check; @@ -42,8 +42,6 @@ where Priv: MixnetIdentityPrivateKey, Pub: MixnetIdentityPublicKey, { - directory_client: directory_client::Client, - interval: Duration, num_test_packets: usize, resolution_timeout: Duration, identity_keypair: IDPair, @@ -58,17 +56,14 @@ where Priv: crypto::identity::MixnetIdentityPrivateKey, Pub: crypto::identity::MixnetIdentityPublicKey, { - pub fn new(config: config::HealthCheck, identity_keypair: IDPair) -> Self { - debug!( - "healthcheck will be using the following directory server: {:?}", - config.directory_server - ); - let directory_client_config = directory_client::Config::new(config.directory_server); + pub fn new( + resolution_timeout_f64: f64, + num_test_packets: usize, + identity_keypair: IDPair, + ) -> Self { HealthChecker { - directory_client: directory_client::Client::new(directory_client_config), - interval: Duration::from_secs_f64(config.interval), - resolution_timeout: Duration::from_secs_f64(config.resolution_timeout), - num_test_packets: config.num_test_packets, + resolution_timeout: Duration::from_secs_f64(resolution_timeout_f64), + num_test_packets, identity_keypair, _phantom_private: PhantomData, @@ -76,18 +71,12 @@ where } } - pub async fn do_check(&self) -> Result { + pub async fn do_check( + &self, + current_topology: &T, + ) -> Result { trace!("going to perform a healthcheck!"); - let current_topology = match self.directory_client.presence_topology.get() { - Ok(topology) => topology, - Err(err) => { - error!("failed to obtain topology - {:?}", err); - return Err(HealthCheckerError::FailedToObtainTopologyError); - } - }; - trace!("current topology: {:?}", current_topology); - let mut healthcheck_result = HealthCheckResult::calculate( current_topology, self.num_test_packets, @@ -98,20 +87,4 @@ where healthcheck_result.sort_scores(); Ok(healthcheck_result) } - - pub async fn run(self) -> Result<(), HealthCheckerError> { - debug!( - "healthcheck will run every {:?} and will send {} packets to each node", - self.interval, self.num_test_packets - ); - - loop { - match self.do_check().await { - Ok(health) => info!("current network health: \n{}", health), - Err(err) => error!("failed to perform healthcheck - {:?}", err), - }; - - tokio::time::delay_for(self.interval).await; - } - } } diff --git a/common/healthcheck/src/result.rs b/common/healthcheck/src/result.rs index 83d1f8778c..9eda0885f5 100644 --- a/common/healthcheck/src/result.rs +++ b/common/healthcheck/src/result.rs @@ -27,7 +27,7 @@ impl HealthCheckResult { self.0.sort(); } - fn zero_score(topology: T) -> Self { + fn zero_score(topology: &T) -> Self { warn!("The network is unhealthy, could not send any packets - returning zero score!"); let mixes = topology.mix_nodes(); let providers = topology.providers(); @@ -103,7 +103,7 @@ impl HealthCheckResult { } pub async fn calculate( - topology: T, + topology: &T, iterations: usize, resolution_timeout: Duration, identity_keys: &IDPair, From e23dd5721333c51ffb1db6c0f922b250c3545ebb Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 18:07:24 +0000 Subject: [PATCH 4/5] Client using pre-filtered topology for the healthchecker --- Cargo.lock | 2 ++ nym-client/src/client/topology_control.rs | 35 +++++++++-------------- validator/Cargo.toml | 2 ++ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adaec6c811..a08936e126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1422,6 +1422,7 @@ dependencies = [ "built", "clap", "crypto", + "directory-client", "dotenv", "futures 0.3.1", "healthcheck", @@ -1431,6 +1432,7 @@ dependencies = [ "serde_derive", "tokio 0.2.10", "toml", + "topology", ] [[package]] diff --git a/nym-client/src/client/topology_control.rs b/nym-client/src/client/topology_control.rs index 9daafc0572..9833f81166 100644 --- a/nym-client/src/client/topology_control.rs +++ b/nym-client/src/client/topology_control.rs @@ -43,17 +43,8 @@ where refresh_rate: f64, identity_keypair: IDPair, ) -> Self { - // topology control run a healthcheck to determine healthy-ish nodes: // this is a temporary solution as the healthcheck will eventually be moved to validators - - let healthcheck_config = healthcheck::config::HealthCheck { - directory_server: directory_server.clone(), - // those are literally irrelevant when running single check - interval: 100000.0, - resolution_timeout: 5.0, - num_test_packets: 2, - }; - let health_checker = healthcheck::HealthChecker::new(healthcheck_config, identity_keypair); + let health_checker = healthcheck::HealthChecker::new(5.0, 2, identity_keypair); let mut topology_control = TopologyControl { directory_server, @@ -79,8 +70,16 @@ where async fn get_current_compatible_topology(&self) -> Result { let full_topology = T::new(self.directory_server.clone()); + let version_filtered_topology = full_topology.filter_node_versions( + built_info::PKG_VERSION, + built_info::PKG_VERSION, + built_info::PKG_VERSION, + ); - let healthcheck_result = self.health_checker.do_check().await; + let healthcheck_result = self + .health_checker + .do_check(&version_filtered_topology) + .await; let healthcheck_scores = match healthcheck_result { Err(err) => { error!("Error while performing the healthcheck: {:?}", err); @@ -89,21 +88,15 @@ where Ok(scores) => scores, }; - let healthy_topology = - healthcheck_scores.filter_topology_by_score(&full_topology, NODE_HEALTH_THRESHOLD); - - let versioned_healthy_topology = healthy_topology.filter_node_versions( - built_info::PKG_VERSION, - built_info::PKG_VERSION, - built_info::PKG_VERSION, - ); + let healthy_topology = healthcheck_scores + .filter_topology_by_score(&version_filtered_topology, NODE_HEALTH_THRESHOLD); // make sure you can still send a packet through the network: - if !versioned_healthy_topology.can_construct_path_through() { + if !healthy_topology.can_construct_path_through() { return Err(TopologyError::NoValidPathsError); } - Ok(versioned_healthy_topology) + Ok(healthy_topology) } pub(crate) fn get_inner_ref(&self) -> Arc>> { diff --git a/validator/Cargo.toml b/validator/Cargo.toml index 3895b662fe..00cc970649 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -21,7 +21,9 @@ toml = "0.5.5" ## internal crypto = {path = "../common/crypto"} +directory-client = { path = "../common/clients/directory-client" } healthcheck = {path = "../common/healthcheck" } +topology = {path = "../common/topology"} [build-dependencies] built = "0.3.2" From 2b73aa9976d3b5cc6991942c8f0a934887bde5fb Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 29 Jan 2020 10:14:53 +0000 Subject: [PATCH 5/5] Updated packages versions --- Cargo.lock | 8 ++++---- mixnode/Cargo.toml | 2 +- nym-client/Cargo.toml | 2 +- sfw-provider/Cargo.toml | 2 +- validator/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a08936e126..dbf0d16af9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1343,7 +1343,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "0.4.0" +version = "0.4.1" dependencies = [ "addressing", "bs58", @@ -1375,7 +1375,7 @@ dependencies = [ [[package]] name = "nym-mixnode" -version = "0.4.0" +version = "0.4.1" dependencies = [ "addressing", "bs58", @@ -1393,7 +1393,7 @@ dependencies = [ [[package]] name = "nym-sfw-provider" -version = "0.4.0" +version = "0.4.1" dependencies = [ "bs58", "built", @@ -1417,7 +1417,7 @@ dependencies = [ [[package]] name = "nym-validator" -version = "0.4.0" +version = "0.4.1" dependencies = [ "built", "clap", diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 130e068d65..4685d6416e 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-mixnode" -version = "0.4.0" +version = "0.4.1" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/nym-client/Cargo.toml b/nym-client/Cargo.toml index 388dcfa9ce..e5b16383f7 100644 --- a/nym-client/Cargo.toml +++ b/nym-client/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-client" -version = "0.4.0" +version = "0.4.1" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/sfw-provider/Cargo.toml b/sfw-provider/Cargo.toml index d0b34bb121..d2a7cf2c5c 100644 --- a/sfw-provider/Cargo.toml +++ b/sfw-provider/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-sfw-provider" -version = "0.4.0" +version = "0.4.1" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/validator/Cargo.toml b/validator/Cargo.toml index 00cc970649..c64de656cd 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-validator" -version = "0.4.0" +version = "0.4.1" authors = ["Jedrzej Stuczynski "] edition = "2018"