diff --git a/nym-connect/CHANGELOG.md b/nym-connect/CHANGELOG.md index c1bf4a7b85..14f463bc8b 100644 --- a/nym-connect/CHANGELOG.md +++ b/nym-connect/CHANGELOG.md @@ -2,6 +2,11 @@ ## UNRELEASED +## [nym-connect-v1.1.9](https://github.com/nymtech/nym/tree/nym-connect-v1.1.9) (2023-02-07) + +- Only allow connections to gateways with performance >= 90% +- Perform health check on inital connection. Provide user feedback on a failed/bad health check + ## [nym-connect-v1.1.8](https://github.com/nymtech/nym/tree/nym-connect-v1.1.8) (2023-01-31) - Add supported apps in the menu + update guide ([#2868]) diff --git a/nym-connect/src-tauri/Cargo.toml b/nym-connect/src-tauri/Cargo.toml index 54c39aac73..93e21710bb 100644 --- a/nym-connect/src-tauri/Cargo.toml +++ b/nym-connect/src-tauri/Cargo.toml @@ -45,6 +45,8 @@ url = "2.2" yaml-rust = "0.4" client-core = { path = "../../clients/client-core" } +nym-api-requests = { path = "../../nym-api/nym-api-requests" } +contracts-common = { path = "../../common/cosmwasm-smart-contracts/contracts-common"} config-common = { path = "../../common/config", package = "config" } crypto = { path = "../../common/crypto" } logging = { path = "../../common/logging"} diff --git a/nym-connect/src-tauri/src/main.rs b/nym-connect/src-tauri/src/main.rs index 6540fa94f4..ec36c252d4 100644 --- a/nym-connect/src-tauri/src/main.rs +++ b/nym-connect/src-tauri/src/main.rs @@ -52,6 +52,7 @@ fn main() { crate::operations::connection::status::get_gateway_connection_status, crate::operations::connection::status::start_connection_health_check_task, crate::operations::directory::get_services, + crate::operations::directory::get_gateways_detailed, crate::operations::export::export_keys, crate::operations::window::hide_window, crate::operations::growth::test_and_earn::growth_tne_get_client_id, diff --git a/nym-connect/src-tauri/src/operations/directory/mod.rs b/nym-connect/src-tauri/src/operations/directory/mod.rs index efc2ba175b..66070a3b00 100644 --- a/nym-connect/src-tauri/src/operations/directory/mod.rs +++ b/nym-connect/src-tauri/src/operations/directory/mod.rs @@ -1,21 +1,35 @@ use itertools::Itertools; use crate::error::Result; -use crate::models::{DirectoryService, HarbourMasterService, PagedResult}; +use crate::models::{ + DirectoryService, DirectoryServiceProvider, HarbourMasterService, PagedResult, +}; +use contracts_common::types::Percent; +use nym_api_requests::models::GatewayBondAnnotated; static SERVICE_PROVIDER_WELLKNOWN_URL: &str = "https://nymtech.net/.wellknown/connect/service-providers.json"; static HARBOUR_MASTER_URL: &str = "https://harbourmaster.nymtech.net/v1/services/?size=100"; +static GATEWAYS_DETAILED_URL: &str = + "https://validator.nymtech.net/api/v1/status/gateways/detailed"; + #[tauri::command] -pub async fn get_services() -> Result> { +pub async fn get_services() -> Result> { log::trace!("Fetching services"); - let res = reqwest::get(SERVICE_PROVIDER_WELLKNOWN_URL) + let services_res = reqwest::get(SERVICE_PROVIDER_WELLKNOWN_URL) .await? .json::>() .await?; - log::trace!("Received: {:#?}", res); + log::trace!("Received: {:#?}", services_res); + + log::trace!("Fetching gateways"); + let gateway_res = reqwest::get(GATEWAYS_DETAILED_URL) + .await? + .json::>() + .await?; + log::trace!("Received: {:#?}", gateway_res); // TODO: get paged log::trace!("Fetching active services"); @@ -27,7 +41,7 @@ pub async fn get_services() -> Result> { let mut filtered: Vec = vec![]; - for service in &res { + for service in &services_res { let items: _ = service .items .clone() @@ -47,5 +61,32 @@ pub async fn get_services() -> Result> { }) } - Ok(filtered) + let perf_threshold = Percent::from_percentage_value(90).unwrap(); + + // Use only services that are active AND have a performance of >= 90% + let services_with_good_performance: Vec = filtered + .iter_mut() + .fold(vec![], |mut acc, sp| { + acc.append(&mut sp.items); + acc + }) + .into_iter() + .filter(|sp| { + gateway_res.iter().any(|gateway| { + gateway.gateway_bond.gateway.identity_key == sp.gateway + && gateway.performance >= perf_threshold + }) + }) + .collect(); + + Ok(services_with_good_performance) +} + +#[tauri::command] +pub async fn get_gateways_detailed() -> Result> { + let res = reqwest::get(GATEWAYS_DETAILED_URL) + .await? + .json::>() + .await?; + Ok(res) } diff --git a/nym-connect/src/components/ConnectionStatus.tsx b/nym-connect/src/components/ConnectionStatus.tsx index e917644efe..1be1f4487b 100644 --- a/nym-connect/src/components/ConnectionStatus.tsx +++ b/nym-connect/src/components/ConnectionStatus.tsx @@ -83,7 +83,6 @@ export const ConnectionStatus: FCWithChildren<{ serviceProvider?: ServiceProvider; }> = ({ status, serviceProvider, gatewayPerformance }) => { const color = status === 'connected' || status === 'disconnecting' ? '#21D072' : 'white'; - console.log(gatewayPerformance); return ( <> diff --git a/nym-connect/src/context/main.tsx b/nym-connect/src/context/main.tsx index 3ea8a3cad2..de73015510 100644 --- a/nym-connect/src/context/main.tsx +++ b/nym-connect/src/context/main.tsx @@ -57,19 +57,13 @@ export const ClientContextProvider: FCWithChildren = ({ children }) => { const timerId = useRef(); - const flattenProviders = (services: Services) => { - return services.reduce((a: ServiceProvider[], b) => { - return [...a, ...b.items]; - }, []); - }; - const initialiseApp = async () => { const services = await invoke('get_services'); - const allServiceProviders = flattenProviders(services as Services); const AppVersion = await getAppVersion(); + console.log(services); setAppVersion(AppVersion); - setServiceProviders(allServiceProviders); + setServiceProviders(services as ServiceProvider[]); }; useEffect(() => {