From ce0cbd552d9a06ac29ef7cdec9cc17f0752d4212 Mon Sep 17 00:00:00 2001 From: durch Date: Fri, 22 Aug 2025 12:23:48 +0200 Subject: [PATCH] fix: resolve all compilation errors after NymApiClient migration - Add missing nym-http-api-client dependencies to multiple crates - Add NymApiClientExt trait imports where needed - Fix type mismatches from NymApiClient to unified Client - Add error conversions for NymAPIError in various error enums - Implement missing trait methods (get_current_rewarded_set, get_all_basic_nodes_with_metadata, get_all_described_nodes) - Fix type conversions for RewardedSetResponse in network monitor - Update all API client instantiation to use new unified HTTP client --- common/bandwidth-controller/src/utils.rs | 2 +- common/client-core/src/init/helpers.rs | 5 +- .../validator-client/src/client.rs | 20 ++--- .../validator-client/src/coconut/mod.rs | 1 - .../validator-client/src/nym_api/mod.rs | 76 +++++++++++++++++-- common/commands/Cargo.toml | 1 + common/commands/src/context/mod.rs | 2 +- .../src/ecash/credential_sender.rs | 4 +- common/credentials/Cargo.toml | 1 + .../src/ecash/bandwidth/issuance.rs | 6 +- common/credentials/src/ecash/utils.rs | 1 + common/credentials/src/error.rs | 5 +- common/http-api-client/src/fronted.rs | 4 + common/http-api-client/src/lib.rs | 24 ++++-- common/verloc/Cargo.toml | 2 + common/wasm/client-core/Cargo.toml | 1 + common/wasm/client-core/src/lib.rs | 2 +- nym-api/Cargo.toml | 1 + nym-api/src/ecash/error.rs | 4 + nym-api/src/ecash/state/mod.rs | 1 + nym-api/src/ecash/tests/mod.rs | 4 +- .../src/credentials/ticketbook/mod.rs | 1 + .../nym-credential-proxy/src/error.rs | 8 +- .../src/http/state/mod.rs | 1 + nym-network-monitor/Cargo.toml | 2 + nym-network-monitor/src/main.rs | 15 ++-- nym-validator-rewarder/Cargo.toml | 1 + .../src/cli/dry_run_check_issuer.rs | 1 + .../src/rewarder/nyxd_client.rs | 3 +- .../src/rewarder/ticketbook_issuance/types.rs | 1 + .../rewarder/ticketbook_issuance/verifier.rs | 1 + 31 files changed, 159 insertions(+), 42 deletions(-) diff --git a/common/bandwidth-controller/src/utils.rs b/common/bandwidth-controller/src/utils.rs index 4502238c91..c353755192 100644 --- a/common/bandwidth-controller/src/utils.rs +++ b/common/bandwidth-controller/src/utils.rs @@ -13,7 +13,7 @@ use nym_credentials_interface::{ }; use nym_ecash_time::Date; use nym_validator_client::coconut::all_ecash_api_clients; -use nym_validator_client::nym_api::EpochId; +use nym_validator_client::nym_api::{EpochId, NymApiClientExt}; use nym_validator_client::nyxd::contract_traits::DkgQueryClient; use nym_validator_client::EcashApiClient; use rand::prelude::SliceRandom; diff --git a/common/client-core/src/init/helpers.rs b/common/client-core/src/init/helpers.rs index 834205a363..c8fa3f5722 100644 --- a/common/client-core/src/init/helpers.rs +++ b/common/client-core/src/init/helpers.rs @@ -8,6 +8,7 @@ use nym_crypto::asymmetric::ed25519; use nym_gateway_client::GatewayClient; use nym_topology::node::RoutingNode; use nym_validator_client::client::{IdentityKeyRef, NymApiClientExt}; +use nym_validator_client::nym_nodes::SkimmedNodesWithMetadata; use nym_validator_client::UserAgent; use rand::{seq::SliceRandom, Rng}; #[cfg(unix)] @@ -145,7 +146,7 @@ pub async fn gateways_for_init( // Use the unified HTTP client directly with optional user agent let mut builder = nym_http_api_client::Client::builder(nym_api.clone()) .map_err(|e| ClientCoreError::ValidatorClientError( - nym_validator_client::ValidatorClientError::MalformedUrlProvided(e), + nym_validator_client::ValidatorClientError::NymAPIError { source: e }, ))? .with_bincode(); // Use bincode for better performance @@ -154,7 +155,7 @@ pub async fn gateways_for_init( } let client = builder - .build::() + .build::() .map_err(|e| ClientCoreError::ValidatorClientError( nym_validator_client::ValidatorClientError::NymAPIError { source: e }, ))?; diff --git a/common/client-libs/validator-client/src/client.rs b/common/client-libs/validator-client/src/client.rs index 74c15f2d64..e3e9cd7fe8 100644 --- a/common/client-libs/validator-client/src/client.rs +++ b/common/client-libs/validator-client/src/client.rs @@ -5,7 +5,7 @@ use crate::nyxd::{self, NyxdClient}; use crate::signing::direct_wallet::DirectSecp256k1HdWallet; use crate::signing::signer::{NoSigner, OfflineSigner}; use crate::{ - nym_api, DirectSigningReqwestRpcValidatorClient, QueryReqwestRpcValidatorClient, + DirectSigningReqwestRpcValidatorClient, QueryReqwestRpcValidatorClient, ReqwestRpcClient, ValidatorClientError, }; use nym_api_requests::ecash::models::{ @@ -153,7 +153,7 @@ impl Config { pub struct Client { // ideally they would have been read-only, but unfortunately rust doesn't have such features // #[deprecated(note = "please use `nym_api_client` instead")] - pub nym_api: nym_api::Client, + pub nym_api: nym_http_api_client::Client, // pub nym_api_client: NymApiClient, pub nyxd: NyxdClient, } @@ -214,7 +214,7 @@ impl Client { impl Client { pub fn new_with_rpc_client(config: Config, rpc_client: C) -> Self { - let nym_api_client = nym_api::Client::new(config.api_url.clone(), None); + let nym_api_client = nym_http_api_client::Client::new(config.api_url.clone(), None); Client { nym_api: nym_api_client, @@ -228,7 +228,7 @@ impl Client { where S: OfflineSigner, { - let nym_api_client = nym_api::Client::new(config.api_url.clone(), None); + let nym_api_client = nym_http_api_client::Client::new(config.api_url.clone(), None); Client { nym_api: nym_api_client, @@ -393,13 +393,13 @@ impl Client { #[derive(Clone)] pub struct NymApiClient { pub use_bincode: bool, - pub nym_api: nym_api::Client, + pub nym_api: nym_http_api_client::Client, // TODO: perhaps if we really need it at some (currently I don't see any reasons for it) // we could re-implement the communication with the REST API on port 1317 } -impl From for NymApiClient { - fn from(nym_api: nym_api::Client) -> Self { +impl From for NymApiClient { + fn from(nym_api: nym_http_api_client::Client) -> Self { NymApiClient { use_bincode: false, nym_api, @@ -411,7 +411,7 @@ impl From for NymApiClient { #[allow(deprecated)] impl NymApiClient { pub fn new(api_url: Url) -> Self { - let nym_api = nym_api::Client::new(api_url, None); + let nym_api = nym_http_api_client::Client::new(api_url, None); NymApiClient { use_bincode: true, @@ -421,7 +421,7 @@ impl NymApiClient { #[cfg(not(target_arch = "wasm32"))] pub fn new_with_timeout(api_url: Url, timeout: std::time::Duration) -> Self { - let nym_api = nym_api::Client::new(api_url, Some(timeout)); + let nym_api = nym_http_api_client::Client::new(api_url, Some(timeout)); NymApiClient { use_bincode: true, @@ -436,7 +436,7 @@ impl NymApiClient { } pub fn new_with_user_agent(api_url: Url, user_agent: impl Into) -> Self { - let nym_api = nym_api::Client::builder::<_, ValidatorClientError>(api_url) + let nym_api = nym_http_api_client::Client::builder::<_, ValidatorClientError>(api_url) .expect("invalid api url") .with_user_agent(user_agent.into()) .build::() diff --git a/common/client-libs/validator-client/src/coconut/mod.rs b/common/client-libs/validator-client/src/coconut/mod.rs index c905868361..b07132b489 100644 --- a/common/client-libs/validator-client/src/coconut/mod.rs +++ b/common/client-libs/validator-client/src/coconut/mod.rs @@ -3,7 +3,6 @@ use crate::nyxd::contract_traits::{DkgQueryClient, PagedDkgQueryClient}; use crate::nyxd::error::NyxdError; -use crate::nym_api::NymApiClientExt; use nym_coconut_dkg_common::types::{EpochId, NodeIndex}; use nym_coconut_dkg_common::verification_key::ContractVKShare; use nym_compact_ecash::error::CompactEcashError; diff --git a/common/client-libs/validator-client/src/nym_api/mod.rs b/common/client-libs/validator-client/src/nym_api/mod.rs index fa0a8e2eb7..09af47a1aa 100644 --- a/common/client-libs/validator-client/src/nym_api/mod.rs +++ b/common/client-libs/validator-client/src/nym_api/mod.rs @@ -23,6 +23,7 @@ use nym_api_requests::nym_nodes::{ NodesByAddressesRequestBody, NodesByAddressesResponse, PaginatedCachedNodesResponseV1, PaginatedCachedNodesResponseV2, }; +use crate::nym_nodes::SkimmedNodesWithMetadata; use nym_api_requests::pagination::PaginatedResponse; pub use nym_api_requests::{ ecash::{ @@ -50,10 +51,6 @@ use time::Date; use tracing::instrument; pub use nym_coconut_dkg_common::types::EpochId; -// DEPRECATED: Use nym_http_api_client::Client directly -#[deprecated(since = "1.2.0", note = "Use nym_http_api_client::Client directly")] -pub use nym_http_api_client::Client; - pub mod error; pub mod routes; @@ -64,6 +61,9 @@ pub fn rfc_3339_date() -> Vec> { #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait NymApiClientExt: ApiClient { + /// Get the current API URL being used by the client + fn api_url(&self) -> &url::Url; + async fn health(&self) -> Result { self.get_json( &[ @@ -243,6 +243,68 @@ pub trait NymApiClientExt: ApiClient { .await } + async fn get_current_rewarded_set(&self) -> Result { + self.get_rewarded_set().await + } + + async fn get_all_basic_nodes_with_metadata(&self) -> Result { + // unroll first loop iteration in order to obtain the metadata + let mut page = 0; + let res = self + .get_basic_nodes_v2(false, Some(page), None, true) + .await?; + let mut nodes = res.nodes.data; + let metadata = res.metadata; + + if res.nodes.pagination.total == nodes.len() { + return Ok(SkimmedNodesWithMetadata::new(nodes, metadata)); + } + + page += 1; + + loop { + let mut res = self + .get_basic_nodes_v2(false, Some(page), None, true) + .await?; + + if !metadata.consistency_check(&res.metadata) { + // Create a custom error for inconsistent metadata + return Err(NymAPIError::EndpointFailure { + status: reqwest::StatusCode::INTERNAL_SERVER_ERROR, + error: nym_api_requests::models::RequestError::new("Inconsistent paged metadata"), + }); + } + + nodes.append(&mut res.nodes.data); + if nodes.len() >= res.nodes.pagination.total { + break; + } else { + page += 1 + } + } + + Ok(SkimmedNodesWithMetadata::new(nodes, metadata)) + } + + async fn get_all_described_nodes(&self) -> Result, NymAPIError> { + // TODO: deal with paging in macro or some helper function or something, because it's the same pattern everywhere + let mut page = 0; + let mut descriptions = Vec::new(); + + loop { + let mut res = self.get_nodes_described(Some(page), None).await?; + + descriptions.append(&mut res.data); + if descriptions.len() < res.pagination.total { + page += 1 + } else { + break; + } + } + + Ok(descriptions) + } + #[tracing::instrument(level = "debug", skip_all)] async fn get_nym_nodes( &self, @@ -1378,4 +1440,8 @@ pub trait NymApiClientExt: ApiClient { // Client is already nym_http_api_client::Client (re-exported above), so just one impl needed #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] -impl NymApiClientExt for Client {} +impl NymApiClientExt for nym_http_api_client::Client { + fn api_url(&self) -> &url::Url { + self.current_url().as_ref() + } +} diff --git a/common/commands/Cargo.toml b/common/commands/Cargo.toml index d382cb696f..4398342d4c 100644 --- a/common/commands/Cargo.toml +++ b/common/commands/Cargo.toml @@ -38,6 +38,7 @@ cosmrs = { workspace = true } cosmwasm-std = { workspace = true } nym-validator-client = { path = "../client-libs/validator-client" } +nym-http-api-client = { path = "../http-api-client" } nym-bin-common = { path = "../../common/bin-common", features = ["output_format"] } nym-crypto = { path = "../../common/crypto", features = ["asymmetric"] } nym-network-defaults = { path = "../network-defaults" } diff --git a/common/commands/src/context/mod.rs b/common/commands/src/context/mod.rs index db20ed0ac3..4a8553b695 100644 --- a/common/commands/src/context/mod.rs +++ b/common/commands/src/context/mod.rs @@ -7,7 +7,7 @@ use nym_network_defaults::{ var_names::{MIXNET_CONTRACT_ADDRESS, NYM_API, NYXD, VESTING_CONTRACT_ADDRESS}, NymNetworkDetails, }; -pub use nym_validator_client::nym_api::Client as NymApiClient; +pub use nym_http_api_client::Client as NymApiClient; use nym_validator_client::nyxd::{self, AccountId, NyxdClient}; use nym_validator_client::{ DirectSigningHttpRpcNyxdClient, DirectSigningHttpRpcValidatorClient, QueryHttpRpcNyxdClient, diff --git a/common/credential-verification/src/ecash/credential_sender.rs b/common/credential-verification/src/ecash/credential_sender.rs index 4d4a0b8fe6..3fd67b21df 100644 --- a/common/credential-verification/src/ecash/credential_sender.rs +++ b/common/credential-verification/src/ecash/credential_sender.rs @@ -14,7 +14,7 @@ use nym_api_requests::ecash::models::{BatchRedeemTicketsBody, VerifyEcashTicketB use nym_credentials_interface::Bandwidth; use nym_credentials_interface::{ClientTicket, TicketType}; use nym_validator_client::coconut::EcashApiError; -use nym_validator_client::nym_api::EpochId; +use nym_validator_client::nym_api::{EpochId, NymApiClientExt}; use nym_validator_client::nyxd::contract_traits::{ EcashSigningClient, MultisigQueryClient, MultisigSigningClient, PagedMultisigQueryClient, }; @@ -354,7 +354,7 @@ impl CredentialHandler { Err(err) => { error!("failed to send ticket {ticket_id} for verification to ecash signer '{client}': {err}. if we don't reach quorum, we'll retry later"); Err(EcashTicketError::ApiFailure(EcashApiError::NymApi { - source: err, + source: nym_validator_client::ValidatorClientError::NymAPIError { source: err }, })) } } diff --git a/common/credentials/Cargo.toml b/common/credentials/Cargo.toml index 4240718a37..e3cb06ec40 100644 --- a/common/credentials/Cargo.toml +++ b/common/credentials/Cargo.toml @@ -22,6 +22,7 @@ nym-ecash-time = { path = "../ecash-time", features = ["expiration"] } nym-credentials-interface = { path = "../credentials-interface" } nym-crypto = { path = "../crypto" } nym-api-requests = { path = "../../nym-api/nym-api-requests" } +nym-http-api-client = { path = "../http-api-client" } nym-validator-client = { path = "../client-libs/validator-client", default-features = false } nym-ecash-contract-common = { path = "../cosmwasm-smart-contracts/ecash-contract" } nym-network-defaults = { path = "../network-defaults" } diff --git a/common/credentials/src/ecash/bandwidth/issuance.rs b/common/credentials/src/ecash/bandwidth/issuance.rs index 3d1cacc72d..95b39454f6 100644 --- a/common/credentials/src/ecash/bandwidth/issuance.rs +++ b/common/credentials/src/ecash/bandwidth/issuance.rs @@ -15,7 +15,7 @@ use nym_credentials_interface::{ use nym_crypto::asymmetric::ed25519; use nym_ecash_contract_common::deposit::DepositId; use nym_ecash_time::{ecash_default_expiration_date, ecash_today, EcashTime}; -use nym_validator_client::nym_api::EpochId; +use nym_validator_client::nym_api::{EpochId, NymApiClientExt}; use serde::{Deserialize, Serialize}; use time::Date; @@ -116,7 +116,7 @@ impl IssuanceTicketBook { pub async fn obtain_blinded_credential( &self, - client: &nym_validator_client::client::NymApiClient, + client: &nym_http_api_client::Client, request_body: &BlindSignRequestBody, ) -> Result { let server_response = client.blind_sign(request_body).await?; @@ -179,7 +179,7 @@ impl IssuanceTicketBook { // ideally this would have been generic over credential type, but we really don't need secp256k1 keys for bandwidth vouchers pub async fn obtain_partial_ticketbook_credential( &self, - client: &nym_validator_client::client::NymApiClient, + client: &nym_http_api_client::Client, signer_index: u64, validator_vk: &VerificationKeyAuth, signing_data: CredentialSigningData, diff --git a/common/credentials/src/ecash/utils.rs b/common/credentials/src/ecash/utils.rs index 305aafd532..497987e3da 100644 --- a/common/credentials/src/ecash/utils.rs +++ b/common/credentials/src/ecash/utils.rs @@ -10,6 +10,7 @@ use nym_credentials_interface::{ VerificationKeyAuth, WalletSignatures, }; use nym_validator_client::client::EcashApiClient; +use nym_validator_client::nym_api::NymApiClientExt; // so we wouldn't break all the existing imports pub use nym_ecash_time::{cred_exp_date, ecash_date_offset, ecash_today, EcashTime}; diff --git a/common/credentials/src/error.rs b/common/credentials/src/error.rs index fa751451dc..9a585b9195 100644 --- a/common/credentials/src/error.rs +++ b/common/credentials/src/error.rs @@ -4,7 +4,7 @@ use crate::ecash::bandwidth::issued::CURRENT_SERIALIZATION_REVISION; use nym_credentials_interface::CompactEcashError; use nym_crypto::asymmetric::x25519::KeyRecoveryError; -use nym_validator_client::ValidatorClientError; +use nym_validator_client::{ValidatorClientError, nym_api::error::NymAPIError}; use thiserror::Error; #[derive(Debug, Error)] @@ -37,6 +37,9 @@ pub enum Error { #[error("Ran into a validator client error - {0}")] ValidatorClientError(#[from] ValidatorClientError), + #[error("Nym API request failed - {0}")] + NymAPIError(#[from] NymAPIError), + #[error("Bandwidth operation overflowed. {0}")] BandwidthOverflow(String), diff --git a/common/http-api-client/src/fronted.rs b/common/http-api-client/src/fronted.rs index f3ff92b129..5818649403 100644 --- a/common/http-api-client/src/fronted.rs +++ b/common/http-api-client/src/fronted.rs @@ -54,10 +54,14 @@ impl Front { #[derive(Debug, Default, PartialEq, Clone)] #[cfg(feature = "tunneling")] +/// Policy for when to use domain fronting for HTTP requests. pub enum FrontPolicy { + /// Always use domain fronting for all requests. Always, + /// Only use domain fronting when retrying failed requests. OnRetry, #[default] + /// Never use domain fronting. Off, } diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 52af11fed9..e9dc809b87 100644 --- a/common/http-api-client/src/lib.rs +++ b/common/http-api-client/src/lib.rs @@ -764,17 +764,24 @@ impl Client { #[cfg(feature = "tunneling")] if let Some(ref front) = self.front { if front.is_enabled() { + let front_host = url.front_str().unwrap_or(""); + let actual_host = url.host_str().unwrap_or(""); + + tracing::debug!( + "Domain fronting enabled: routing via CDN {} to actual host {}", + front_host, + actual_host + ); + // this should never fail as we are transplanting the host from one url to another - r.url_mut().set_host(url.front_str()).unwrap(); + r.url_mut().set_host(Some(front_host)).unwrap(); - let actual_host: HeaderValue = url - .host_str() - .unwrap_or("") + let actual_host_header: HeaderValue = actual_host .parse() .unwrap_or(HeaderValue::from_static("")); // If the map did have this key present, the new value is associated with the key // and all previous values are removed. (reqwest HeaderMap docs) - _ = r.headers_mut().insert(reqwest::header::HOST, actual_host); + _ = r.headers_mut().insert(reqwest::header::HOST, actual_host_header); } } } @@ -861,7 +868,14 @@ impl ApiClientCore for Client { if let Some(ref front) = self.front { // If fronting is set to be enabled on error, enable domain fronting as we // have encountered an error. + let was_enabled = front.is_enabled(); front.retry_enable(); + if !was_enabled && front.is_enabled() { + tracing::info!( + "Domain fronting activated after connection failure: {}", + e + ); + } } if attempts < self.retry_limit { diff --git a/common/verloc/Cargo.toml b/common/verloc/Cargo.toml index e906f72dde..32b81ed1d6 100644 --- a/common/verloc/Cargo.toml +++ b/common/verloc/Cargo.toml @@ -25,3 +25,5 @@ url = { workspace = true } nym-crypto = { path = "../crypto", features = ["asymmetric"] } nym-task = { path = "../task" } nym-validator-client = { path = "../client-libs/validator-client" } +nym-http-api-client = { path = "../http-api-client" } +nym-api-requests = { path = "../../nym-api/nym-api-requests" } diff --git a/common/wasm/client-core/Cargo.toml b/common/wasm/client-core/Cargo.toml index d63e31e50a..85668972f9 100644 --- a/common/wasm/client-core/Cargo.toml +++ b/common/wasm/client-core/Cargo.toml @@ -34,6 +34,7 @@ nym-statistics-common = { path = "../../statistics" } nym-task = { path = "../../task" } nym-topology = { path = "../../topology", features = ["wasm-serde-types"] } nym-validator-client = { path = "../../client-libs/validator-client", default-features = false } +nym-http-api-client = { path = "../../http-api-client" } wasm-utils = { path = "../utils" } wasm-storage = { path = "../storage" } diff --git a/common/wasm/client-core/src/lib.rs b/common/wasm/client-core/src/lib.rs index 8569dd7ad9..ae1ba45ad9 100644 --- a/common/wasm/client-core/src/lib.rs +++ b/common/wasm/client-core/src/lib.rs @@ -29,7 +29,7 @@ pub use nym_sphinx::{ pub use nym_statistics_common::clients::ClientStatsSender; pub use nym_task; pub use nym_topology::{HardcodedTopologyProvider, MixLayer, NymTopology, TopologyProvider}; -pub use nym_validator_client::nym_api::Client as ApiClient; +pub use nym_http_api_client::Client as ApiClient; pub use nym_validator_client::{DirectSigningReqwestRpcNyxdClient, QueryReqwestRpcNyxdClient}; // TODO: that's a very nasty import path. it should come from contracts instead! pub use nym_validator_client::client::IdentityKey; diff --git a/nym-api/Cargo.toml b/nym-api/Cargo.toml index 018f037dff..65f98cc6e4 100644 --- a/nym-api/Cargo.toml +++ b/nym-api/Cargo.toml @@ -93,6 +93,7 @@ nym-task = { path = "../common/task" } nym-topology = { path = "../common/topology" } nym-api-requests = { path = "nym-api-requests" } nym-validator-client = { path = "../common/client-libs/validator-client" } +nym-http-api-client = { path = "../common/http-api-client" } nym-bin-common = { path = "../common/bin-common", features = ["output_format", "openapi", "basic_tracing"] } nym-node-tester-utils = { path = "../common/node-tester-utils" } nym-node-requests = { path = "../nym-node/nym-node-requests" } diff --git a/nym-api/src/ecash/error.rs b/nym-api/src/ecash/error.rs index 5e4c0e6e89..62a27c7b8b 100644 --- a/nym-api/src/ecash/error.rs +++ b/nym-api/src/ecash/error.rs @@ -13,6 +13,7 @@ use nym_dkg::Threshold; use nym_ecash_contract_common::deposit::DepositId; use nym_ecash_contract_common::redeem_credential::BATCH_REDEMPTION_PROPOSAL_TITLE; use nym_validator_client::coconut::EcashApiError; +use nym_validator_client::nym_api::error::NymAPIError; use nym_validator_client::nyxd::error::NyxdError; use nym_validator_client::nyxd::AccountId; use thiserror::Error; @@ -46,6 +47,9 @@ pub enum EcashError { #[error("coconut api query failure: {0}")] CoconutApiError(#[from] EcashApiError), + #[error("nym api query failure: {0}")] + NymApiError(#[from] NymAPIError), + #[error(transparent)] SerdeJsonError(#[from] serde_json::Error), diff --git a/nym-api/src/ecash/state/mod.rs b/nym-api/src/ecash/state/mod.rs index a4d8a39f46..c1aad45a64 100644 --- a/nym-api/src/ecash/state/mod.rs +++ b/nym-api/src/ecash/state/mod.rs @@ -27,6 +27,7 @@ use nym_api_requests::ecash::models::{ }; use nym_api_requests::ecash::BlindSignRequestBody; use nym_coconut_dkg_common::types::EpochId; +use nym_validator_client::nym_api::NymApiClientExt; use nym_compact_ecash::scheme::coin_indices_signatures::{ aggregate_annotated_indices_signatures, sign_coin_indices, CoinIndexSignatureShare, }; diff --git a/nym-api/src/ecash/tests/mod.rs b/nym-api/src/ecash/tests/mod.rs index 2152ae7274..071e57a1a6 100644 --- a/nym-api/src/ecash/tests/mod.rs +++ b/nym-api/src/ecash/tests/mod.rs @@ -67,7 +67,7 @@ use nym_validator_client::nym_api::routes::{ use nym_validator_client::nyxd::cosmwasm_client::logs::Log; use nym_validator_client::nyxd::cosmwasm_client::types::ExecuteResult; use nym_validator_client::nyxd::{AccountId, ExecTxResult, Fee, Hash, TxResponse}; -use nym_validator_client::{EcashApiClient, NymApiClient}; +use nym_validator_client::EcashApiClient; use rand::rngs::OsRng; use rand::RngCore; use std::collections::{BTreeMap, HashMap}; @@ -1148,7 +1148,7 @@ impl DummyCommunicationChannel { cosmos_address: AccountId, ) -> Self { let client = EcashApiClient { - api_client: NymApiClient::new("http://localhost:1234".parse().unwrap()), + api_client: nym_http_api_client::Client::new("http://localhost:1234".parse().unwrap(), None), verification_key: aggregated_verification_key, node_id: 1, cosmos_address, diff --git a/nym-credential-proxy/nym-credential-proxy/src/credentials/ticketbook/mod.rs b/nym-credential-proxy/nym-credential-proxy/src/credentials/ticketbook/mod.rs index 33ad66391e..396d2f1b6a 100644 --- a/nym-credential-proxy/nym-credential-proxy/src/credentials/ticketbook/mod.rs +++ b/nym-credential-proxy/nym-credential-proxy/src/credentials/ticketbook/mod.rs @@ -16,6 +16,7 @@ use nym_credentials_interface::Base58; use nym_crypto::asymmetric::ed25519; use nym_validator_client::ecash::BlindSignRequestBody; use nym_validator_client::nyxd::Coin; +use nym_validator_client::nym_api::NymApiClientExt; use rand::rngs::OsRng; use std::collections::HashMap; use std::sync::Arc; diff --git a/nym-credential-proxy/nym-credential-proxy/src/error.rs b/nym-credential-proxy/nym-credential-proxy/src/error.rs index 56e18a0673..24daa2b76f 100644 --- a/nym-credential-proxy/nym-credential-proxy/src/error.rs +++ b/nym-credential-proxy/nym-credential-proxy/src/error.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only use nym_validator_client::coconut::EcashApiError; -use nym_validator_client::nym_api::EpochId; +use nym_validator_client::nym_api::{EpochId, error::NymAPIError}; use nym_validator_client::nyxd::error::NyxdError; use std::io; use std::net::SocketAddr; @@ -70,6 +70,12 @@ pub enum VpnApiError { source: EcashApiError, }, + #[error("Nym API request failed: {source}")] + NymApiFailure { + #[from] + source: NymAPIError, + }, + #[error("Compact ecash internal error: {0}")] CompactEcashInternalError(#[from] nym_compact_ecash::error::CompactEcashError), diff --git a/nym-credential-proxy/nym-credential-proxy/src/http/state/mod.rs b/nym-credential-proxy/nym-credential-proxy/src/http/state/mod.rs index 4579b677fa..42b4da406b 100644 --- a/nym-credential-proxy/nym-credential-proxy/src/http/state/mod.rs +++ b/nym-credential-proxy/nym-credential-proxy/src/http/state/mod.rs @@ -28,6 +28,7 @@ use nym_credentials::ecash::utils::{ecash_today, EcashTime}; use nym_credentials::{ AggregatedCoinIndicesSignatures, AggregatedExpirationDateSignatures, EpochVerificationKey, }; +use nym_validator_client::nym_api::NymApiClientExt; use nym_credentials_interface::VerificationKeyAuth; use nym_ecash_contract_common::msg::ExecuteMsg; use nym_validator_client::coconut::EcashApiError; diff --git a/nym-network-monitor/Cargo.toml b/nym-network-monitor/Cargo.toml index c693cb5b19..a84a5f3c02 100644 --- a/nym-network-monitor/Cargo.toml +++ b/nym-network-monitor/Cargo.toml @@ -40,3 +40,5 @@ nym-sphinx = { path = "../common/nymsphinx" } nym-topology = { path = "../common/topology" } nym-types = { path = "../common/types" } nym-validator-client = { path = "../common/client-libs/validator-client" } +nym-http-api-client = { path = "../common/http-api-client" } +nym-mixnet-contract-common = { path = "../common/cosmwasm-smart-contracts/mixnet-contract" } diff --git a/nym-network-monitor/src/main.rs b/nym-network-monitor/src/main.rs index b336b3dac6..dff0b7854c 100644 --- a/nym-network-monitor/src/main.rs +++ b/nym-network-monitor/src/main.rs @@ -13,6 +13,8 @@ use nym_sphinx::chunking::monitoring; use nym_topology::provider_trait::ToTopologyMetadata; use nym_topology::{HardcodedTopologyProvider, NymTopology}; use nym_validator_client::nym_api::NymApiClientExt; +use nym_validator_client::UserAgent; +use nym_mixnet_contract_common::EpochRewardedSet; use std::fs::File; use std::io::Write; use std::sync::LazyLock; @@ -161,11 +163,9 @@ async fn nym_topology_from_env() -> anyhow::Result { let api_url = std::env::var(NYM_API)?; info!("Generating topology from {api_url}"); - let client = nym_http_api_client::Client::builder(api_url.parse()?) - .map_err(anyhow::Error::from)? - .with_user_agent(bin_info!()) - .build::() - .map_err(anyhow::Error::from)?; + let client = nym_http_api_client::Client::builder::<_, nym_validator_client::models::RequestError>(api_url)? + .with_user_agent(UserAgent::from(bin_info!())) + .build::()?; let rewarded_set = client.get_current_rewarded_set().await?; @@ -174,8 +174,11 @@ async fn nym_topology_from_env() -> anyhow::Result { let nodes = nodes_response.nodes; let metadata = nodes_response.metadata; + // Convert RewardedSetResponse to EpochRewardedSet which can then be converted to CachedEpochRewardedSet + let epoch_rewarded_set: EpochRewardedSet = rewarded_set.into(); + Ok( - NymTopology::new(metadata.to_topology_metadata(), rewarded_set, Vec::new()) + NymTopology::new(metadata.to_topology_metadata(), epoch_rewarded_set, Vec::new()) .with_skimmed_nodes(&nodes), ) } diff --git a/nym-validator-rewarder/Cargo.toml b/nym-validator-rewarder/Cargo.toml index 3281e9f782..3532424727 100644 --- a/nym-validator-rewarder/Cargo.toml +++ b/nym-validator-rewarder/Cargo.toml @@ -42,6 +42,7 @@ nym-credentials = { path = "../common/credentials" } nym-network-defaults = { path = "../common/network-defaults" } nym-task = { path = "../common/task" } nym-validator-client = { path = "../common/client-libs/validator-client" } +nym-http-api-client = { path = "../common/http-api-client" } nym-coconut-dkg-common = { path = "../common/cosmwasm-smart-contracts/coconut-dkg" } nyxd-scraper = { path = "../common/nyxd-scraper" } nym-ticketbooks-merkle = { path = "../common/ticketbooks-merkle" } diff --git a/nym-validator-rewarder/src/cli/dry_run_check_issuer.rs b/nym-validator-rewarder/src/cli/dry_run_check_issuer.rs index 49d0d250d6..f2f7e1010b 100644 --- a/nym-validator-rewarder/src/cli/dry_run_check_issuer.rs +++ b/nym-validator-rewarder/src/cli/dry_run_check_issuer.rs @@ -8,6 +8,7 @@ use crate::rewarder::ticketbook_issuance::types::CredentialIssuer; use crate::rewarder::ticketbook_issuance::verifier::TicketbookIssuanceVerifier; use crate::rewarder::Rewarder; use anyhow::bail; +use nym_validator_client::nym_api::NymApiClientExt; use nym_ecash_time::ecash_default_expiration_date; use std::collections::HashSet; use std::path::PathBuf; diff --git a/nym-validator-rewarder/src/rewarder/nyxd_client.rs b/nym-validator-rewarder/src/rewarder/nyxd_client.rs index 761b4416c8..b7090d6945 100644 --- a/nym-validator-rewarder/src/rewarder/nyxd_client.rs +++ b/nym-validator-rewarder/src/rewarder/nyxd_client.rs @@ -16,6 +16,7 @@ use nym_validator_client::nyxd::{ AccountId, Coin, CosmWasmClient, Hash, PageRequest, StakingQueryClient, }; use nym_validator_client::{nyxd, DirectSigningHttpRpcNyxdClient}; +use nym_validator_client::nym_api::NymApiClientExt; use std::collections::HashMap; use std::ops::Deref; use std::sync::Arc; @@ -140,7 +141,7 @@ impl NyxdClient { }; let api_client = match nym_http_api_client::Client::builder(api_address) - .and_then(|b| b.build::()) + .and_then(|b| b.build::()) { Ok(client) => client, Err(err) => { diff --git a/nym-validator-rewarder/src/rewarder/ticketbook_issuance/types.rs b/nym-validator-rewarder/src/rewarder/ticketbook_issuance/types.rs index 28ac10a785..aa065b3ffc 100644 --- a/nym-validator-rewarder/src/rewarder/ticketbook_issuance/types.rs +++ b/nym-validator-rewarder/src/rewarder/ticketbook_issuance/types.rs @@ -7,6 +7,7 @@ use nym_coconut_dkg_common::types::NodeIndex; use nym_compact_ecash::VerificationKeyAuth; use nym_crypto::asymmetric::ed25519; use nym_validator_client::nyxd::{AccountId, Coin}; +use nym_validator_client::nym_api::NymApiClientExt; use std::fmt::{Display, Formatter}; use tracing::info; diff --git a/nym-validator-rewarder/src/rewarder/ticketbook_issuance/verifier.rs b/nym-validator-rewarder/src/rewarder/ticketbook_issuance/verifier.rs index cb0964caf3..ebed2f8c27 100644 --- a/nym-validator-rewarder/src/rewarder/ticketbook_issuance/verifier.rs +++ b/nym-validator-rewarder/src/rewarder/ticketbook_issuance/verifier.rs @@ -18,6 +18,7 @@ use nym_validator_client::ecash::models::{ }; use nym_validator_client::nyxd::AccountId; use nym_validator_client::signable::{SignableMessageBody, SignedMessage}; +use nym_validator_client::nym_api::NymApiClientExt; use rand::distributions::{Distribution, WeightedIndex}; use rand::prelude::SliceRandom; use rand::thread_rng;