From 4a1a4b641504e1a0047147e3979d40117c9ecdb1 Mon Sep 17 00:00:00 2001 From: Drazen Urch Date: Mon, 28 Mar 2022 13:33:55 +0200 Subject: [PATCH] Different values for mixes and gateways (#1169) --- validator-api/src/config/mod.rs | 28 +++++++++++++++---- validator-api/src/config/template.rs | 3 +- validator-api/src/main.rs | 21 ++++++++++++++ .../src/network_monitor/monitor/mod.rs | 10 ++++--- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/validator-api/src/config/mod.rs b/validator-api/src/config/mod.rs index 567aba8858..b458777574 100644 --- a/validator-api/src/config/mod.rs +++ b/validator-api/src/config/mod.rs @@ -34,7 +34,8 @@ const DEFAULT_PER_NODE_TEST_PACKETS: usize = 3; const DEFAULT_CACHE_INTERVAL: Duration = Duration::from_secs(30); const DEFAULT_MONITOR_THRESHOLD: u8 = 60; -const DEFAULT_MIN_RELIABILITY: u8 = 50; +const DEFAULT_MIN_MIXNODE_RELIABILITY: u8 = 50; +const DEFAULT_MIN_GATEWAY_RELIABILITY: u8 = 20; #[derive(Debug, Default, Deserialize, PartialEq, Serialize)] pub struct Config { @@ -109,8 +110,8 @@ impl Default for Base { #[serde(default)] pub struct NetworkMonitor { // Mixnodes and gateways with relialability lower the this get blacklisted by network monitor, get no traffic and cannot be selected into a rewarded set. - min_reliability: u8, - + min_mixnode_reliability: u8, // defaults to 50 + min_gateway_reliability: u8, // defaults to 20 /// Specifies whether network monitoring service is enabled in this process. enabled: bool, @@ -192,7 +193,8 @@ impl NetworkMonitor { impl Default for NetworkMonitor { fn default() -> Self { NetworkMonitor { - min_reliability: DEFAULT_MIN_RELIABILITY, + min_mixnode_reliability: DEFAULT_MIN_MIXNODE_RELIABILITY, + min_gateway_reliability: DEFAULT_MIN_GATEWAY_RELIABILITY, enabled: false, testnet_mode: false, all_validator_apis: default_api_endpoints(), @@ -334,6 +336,16 @@ impl Config { self } + pub fn with_min_mixnode_reliability(mut self, min_mixnode_reliability: u8) -> Self { + self.network_monitor.min_mixnode_reliability = min_mixnode_reliability; + self + } + + pub fn with_min_gateway_reliability(mut self, min_gateway_reliability: u8) -> Self { + self.network_monitor.min_gateway_reliability = min_gateway_reliability; + self + } + #[cfg(not(feature = "coconut"))] pub fn with_eth_private_key(mut self, eth_private_key: String) -> Self { self.network_monitor.eth_private_key = eth_private_key; @@ -423,8 +435,12 @@ impl Config { self.network_monitor.minimum_test_routes } - pub fn get_min_reliability(&self) -> u8 { - self.network_monitor.min_reliability + pub fn get_min_mixnode_reliability(&self) -> u8 { + self.network_monitor.min_mixnode_reliability + } + + pub fn get_min_gateway_reliability(&self) -> u8 { + self.network_monitor.min_gateway_reliability } pub fn get_route_test_packets(&self) -> usize { diff --git a/validator-api/src/config/template.rs b/validator-api/src/config/template.rs index a9c9005fb2..815bc8e8e7 100644 --- a/validator-api/src/config/template.rs +++ b/validator-api/src/config/template.rs @@ -21,7 +21,8 @@ mixnet_contract_address = '{{ base.mixnet_contract_address }}' [network_monitor] # Mixnodes and gateways with relialability lower the this get blacklisted by network monitor, get no traffic and cannot be selected into a rewarded set. -min_reliability = {{ network_monitor.min_reliability }} +min_mixnode_reliability = {{ network_monitor.min_mixnode_reliability }} # deafults to 50 +min_gateway_reliability = {{ network_monitor.min_gateway_reliability }} # defaults to 20 # Specifies whether network monitoring service is enabled in this process. enabled = {{ network_monitor.enabled }} diff --git a/validator-api/src/main.rs b/validator-api/src/main.rs index 037fc3911e..3419cb41c6 100644 --- a/validator-api/src/main.rs +++ b/validator-api/src/main.rs @@ -64,6 +64,9 @@ const ETH_PRIVATE_KEY: &str = "eth_private_key"; const REWARDING_MONITOR_THRESHOLD_ARG: &str = "monitor-threshold"; +const MIN_MIXNODE_RELIABILITY_ARG: &str = "min_mixnode_reliability"; +const MIN_GATEWAY_RELIABILITY_ARG: &str = "min_gateway_reliability"; + fn parse_validators(raw: &str) -> Vec { raw.split(',') .map(|raw_validator| { @@ -276,6 +279,24 @@ fn override_config(mut config: Config, matches: &ArgMatches<'_>) -> Config { config = config.with_minimum_interval_monitor_threshold(monitor_threshold) } + if let Some(reliability) = matches + .value_of(MIN_MIXNODE_RELIABILITY_ARG) + .map(|t| t.parse::()) + { + config = config.with_min_mixnode_reliability( + reliability.expect("Provided reliability is not a u8 number!"), + ) + } + + if let Some(reliability) = matches + .value_of(MIN_GATEWAY_RELIABILITY_ARG) + .map(|t| t.parse::()) + { + config = config.with_min_gateway_reliability( + reliability.expect("Provided reliability is not a u8 number!"), + ) + } + #[cfg(feature = "coconut")] if let Some(keypair_path) = matches.value_of(KEYPAIR_ARG) { let keypair_bs58 = std::fs::read_to_string(keypair_path) diff --git a/validator-api/src/network_monitor/monitor/mod.rs b/validator-api/src/network_monitor/monitor/mod.rs index 6dc3483167..ce3df86727 100644 --- a/validator-api/src/network_monitor/monitor/mod.rs +++ b/validator-api/src/network_monitor/monitor/mod.rs @@ -42,7 +42,8 @@ pub(super) struct Monitor { /// The minimum number of test routes that need to be constructed (and working) in order for /// a monitor test run to be valid. minimum_test_routes: usize, - min_reliability: u8, + min_mixnode_reliability: u8, + min_gateway_reliability: u8, } impl Monitor { @@ -67,7 +68,8 @@ impl Monitor { route_test_packets: config.get_route_test_packets(), test_routes: config.get_test_routes(), minimum_test_routes: config.get_minimum_test_routes(), - min_reliability: config.get_min_reliability(), + min_mixnode_reliability: config.get_min_mixnode_reliability(), + min_gateway_reliability: config.get_min_gateway_reliability(), } } @@ -78,7 +80,7 @@ impl Monitor { // uptime calculations for result in test_summary.mixnode_results.iter() { - if result.reliability < self.min_reliability { + if result.reliability < self.min_mixnode_reliability { self.packet_preparer .validator_cache() .insert_mixnodes_blacklist(result.identity.clone()) @@ -92,7 +94,7 @@ impl Monitor { } for result in test_summary.gateway_results.iter() { - if result.reliability < self.min_reliability { + if result.reliability < self.min_gateway_reliability { self.packet_preparer .validator_cache() .insert_gateways_blacklist(result.identity.clone())