90e9e3cff8
* feat: unify HTTP client creation and enable domain fronting Enhanced the base nym_http_api_client to reduce fragmentation and enable domain fronting: - Added SerializationFormat enum for explicit JSON/bincode choice (no auto-detection) - Added from_network() method to create clients from NymNetworkDetails with domain fronting - Added with_bincode() builder method for explicit serialization configuration - Set Accept header based on serialization preference - Added deprecation paths for NymApiClient wrapper and nym_api::Client re-export - Enabled domain fronting support via network defaults feature This is part of a broader effort to consolidate HTTP client implementations across the codebase, reducing ~500 lines of wrapper code and providing automatic domain fronting for censorship resistance. * feat: migrate NymApiClient usage to unified HTTP client - Wire up domain fronting configuration in NymNetworkDetails - Implement NymApiClientExt trait for base nym_http_api_client::Client - Migrate direct NymApiClient usage in multiple components: - nym-network-monitor - verloc measurements - connection tester - coconut/ecash client - validator rewarder - Add Copy derive to ApiUrlConst to enable iteration - Update error handling and Display implementations This enables automatic domain fronting for all Nym API calls via the configured CDN front hosts. * 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 * feat: complete migration to unified HTTP client and fix all compilation errors - Added missing NymApiClientExt trait methods (get_all_expanded_nodes, change_base_urls) - Fixed all compilation errors across the workspace - Updated nym-node to use unified client instead of deprecated NymApiClient - Fixed type conversions for RewardedSetResponse → EpochRewardedSet - Added nym-http-api-client dependency where needed - Updated all examples and documentation to use new client API * fix: provide all API URLs for automatic failover in endpoint rotation Previously, when rotating API endpoints, only a single URL was provided to the HTTP client, defeating the purpose of having multiple URLs for resilience. Changes: - NymApiTopologyProvider now provides all URLs in rotated order when switching endpoints - NymApisClient similarly provides all URLs starting from the working endpoint - Added clarifying comments for broadcast/exhaustive query methods where single URLs are intentionally used - This enables the HTTP client's built-in failover mechanism while maintaining endpoint rotation behavior The fix ensures that if the primary endpoint fails, the client can automatically failover to alternative endpoints without manual intervention, improving overall network resilience. * Update common/client-core/src/client/base_client/mod.rs Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> * Remove error generics, address PR comments * Explicit warning on missing fronting configuration * Assorted CI fixes * Registry proc-macro * Rename macro * Syn workspace version * Where do we need to put inventory * Ergonomics and call sites, incept the builder * fix: Address critical issues in client configuration registry implementation - Fixed HeaderMapInit parsing bug that would cause compilation errors - Added comprehensive documentation with usage examples and DSL reference - Improved error handling with better error messages for invalid headers - Added test coverage for both macro and registry functionality - Added debug inspection capabilities for registered configurations - Fixed module name conflicts in tests by using separate modules All tests now passing: - 7 macro tests validating DSL parsing and code generation - 4 registry tests verifying configuration collection and application * Use default value for the ports until api is deployed * Feature/improved http error (#6025) * use display impl for urls * feat: attempt to add more details to reqwest errors * temporarily restored GenericRequestFailure variant * another restoration * cleanup * Some debug tooling, and default timeout fix * Fix user-agent override * Fix various wasm things --------- Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> Co-authored-by: Bogdan-Ștefan Neacşu <bogdan@nymtech.net>
175 lines
5.5 KiB
Rust
175 lines
5.5 KiB
Rust
// Copyright 2025 Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
use nym_ecash_signer_check::SignerCheckError;
|
|
use nym_validator_client::coconut::EcashApiError;
|
|
use nym_validator_client::nym_api::{error::NymAPIError, EpochId};
|
|
use nym_validator_client::nyxd::error::NyxdError;
|
|
use std::io;
|
|
use std::net::SocketAddr;
|
|
use thiserror::Error;
|
|
use time::OffsetDateTime;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum CredentialProxyError {
|
|
#[error("encountered an internal io error: {source}")]
|
|
IoError {
|
|
#[from]
|
|
source: io::Error,
|
|
},
|
|
|
|
#[error("could not derive valid client url with the provided webhook parameters")]
|
|
InvalidWebhookUrl,
|
|
|
|
#[error("failed to serialise recovery data: {source}")]
|
|
SerdeJsonFailure {
|
|
#[from]
|
|
source: serde_json::Error,
|
|
},
|
|
|
|
#[error("the provided expiration date is too late")]
|
|
ExpirationDateTooLate,
|
|
|
|
#[error("the provided expiration date is too early")]
|
|
ExpirationDateTooEarly,
|
|
|
|
#[error("failed to bind to {address}: {source}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?")]
|
|
SocketBindFailure {
|
|
address: SocketAddr,
|
|
source: io::Error,
|
|
},
|
|
|
|
#[error("the api server failed with the following message: {source}")]
|
|
HttpServerFailure { source: io::Error },
|
|
|
|
#[error("the ecash contract address is not set")]
|
|
UnavailableEcashContract,
|
|
|
|
#[error("the DKG contract address is not set")]
|
|
UnavailableDKGContract,
|
|
|
|
#[error("the bandwidth contract doesn't have any admin set")]
|
|
MissingBandwidthContractAdmin,
|
|
|
|
#[error(
|
|
"the provided mnemonic does not correspond to the current admin of the bandwidth contract"
|
|
)]
|
|
MismatchedMnemonic,
|
|
|
|
#[error("failed to interact with the nyx chain: {source}")]
|
|
NyxdFailure {
|
|
#[from]
|
|
source: NyxdError,
|
|
},
|
|
|
|
#[error("validator client error: {0}")]
|
|
ValidatorClientError(#[from] nym_validator_client::ValidatorClientError),
|
|
|
|
#[error("failed to perform ecash operation: {source}")]
|
|
EcashApiFailure {
|
|
#[from]
|
|
source: EcashApiError,
|
|
},
|
|
|
|
#[error("Nym API request failed: {source}")]
|
|
NymApiFailure { source: Box<NymAPIError> },
|
|
|
|
#[error("Compact ecash internal error: {0}")]
|
|
CompactEcashInternalError(#[from] nym_compact_ecash::error::CompactEcashError),
|
|
|
|
#[error("there are no rpc endpoints provided in the environment")]
|
|
NoNyxEndpointsAvailable,
|
|
|
|
#[error("the threshold value for epoch {epoch_id} is not available")]
|
|
UnavailableThreshold { epoch_id: EpochId },
|
|
|
|
#[error(
|
|
"we have only {available} api clients available while the minimum threshold is {threshold}"
|
|
)]
|
|
InsufficientNumberOfSigners { available: usize, threshold: u64 },
|
|
|
|
#[error(
|
|
"we have only managed to obtain {available} partial credentials while the minimum threshold is {threshold}"
|
|
)]
|
|
InsufficientNumberOfCredentials { available: usize, threshold: u64 },
|
|
|
|
#[error("failed to interact with the credentials: {source}")]
|
|
CredentialsFailure {
|
|
#[from]
|
|
source: nym_credentials::Error,
|
|
},
|
|
|
|
#[error("the DKG has not yet been initialised in the system")]
|
|
UninitialisedDkg,
|
|
|
|
#[error("credentials can't yet be issued in the system. approximate expected availability: {availability}")]
|
|
CredentialsNotYetIssuable { availability: OffsetDateTime },
|
|
|
|
#[error("reached seemingly impossible ecash failure")]
|
|
UnknownEcashFailure,
|
|
|
|
#[error("experienced internal database error: {0}")]
|
|
InternalDatabaseError(#[from] sqlx::Error),
|
|
|
|
#[error("experienced internal storage error: {reason}")]
|
|
DatabaseInconsistency { reason: String },
|
|
|
|
#[error("failed to perform startup SQL migration: {0}")]
|
|
StartupMigrationFailure(#[from] sqlx::migrate::MigrateError),
|
|
|
|
#[error("timed out while attempting to obtain partial wallet from {client_repr}")]
|
|
EcashApiRequestTimeout { client_repr: String },
|
|
|
|
#[error("failed to create deposit")]
|
|
DepositFailure,
|
|
|
|
#[error("can't obtain sufficient number of credential shares due to unavailable quorum")]
|
|
UnavailableSigningQuorum,
|
|
|
|
#[error("failed to perform quorum check: {source}")]
|
|
QuorumCheckFailure {
|
|
#[from]
|
|
source: SignerCheckError,
|
|
},
|
|
|
|
#[error(
|
|
"this operation couldn't be completed as the program is in the process of shutting down"
|
|
)]
|
|
ShutdownInProgress,
|
|
|
|
#[error("failed to obtain wallet shares with id {id}: {message}")]
|
|
ShareByIdLoadError { message: String, id: i64 },
|
|
|
|
#[error("failed to obtain wallet shares with device_id {device_id} and credential_id: {credential_id}: {message}")]
|
|
ShareByDeviceLoadError {
|
|
message: String,
|
|
device_id: String,
|
|
credential_id: String,
|
|
},
|
|
|
|
#[error("could not find shares with id {id}")]
|
|
SharesByIdNotFound { id: i64 },
|
|
|
|
#[error("could not find shares with device_id {device_id} and credential_id: {credential_id}")]
|
|
SharesByDeviceNotFound {
|
|
device_id: String,
|
|
credential_id: String,
|
|
},
|
|
}
|
|
|
|
impl From<NymAPIError> for CredentialProxyError {
|
|
fn from(source: NymAPIError) -> Self {
|
|
CredentialProxyError::NymApiFailure {
|
|
source: Box::new(source),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl CredentialProxyError {
|
|
pub fn database_inconsistency<S: Into<String>>(reason: S) -> CredentialProxyError {
|
|
CredentialProxyError::DatabaseInconsistency {
|
|
reason: reason.into(),
|
|
}
|
|
}
|
|
}
|