From 7324bb23b69bdd494390a48eaba59132bc2bb073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 2 Jun 2026 16:28:27 +0100 Subject: [PATCH] chore: LP registration adjustments (#6845) * remove mixnet fallback for LP registration * change LP registration timeouts and introduce exchange timeout * remove fallback client construction and disable mixnet via LP registration --- nym-registration-client/src/builder/mod.rs | 1 - nym-registration-client/src/clients/lp.rs | 37 +++++--------- .../src/lp_client/config.rs | 51 ++++++++++--------- 3 files changed, 41 insertions(+), 48 deletions(-) diff --git a/nym-registration-client/src/builder/mod.rs b/nym-registration-client/src/builder/mod.rs index e81d0977bc..af64450a24 100644 --- a/nym-registration-client/src/builder/mod.rs +++ b/nym-registration-client/src/builder/mod.rs @@ -143,7 +143,6 @@ impl RegistrationClientBuilder { config, bandwidth_controller, cancel_token: self.config.cancel_token.clone(), - fallback_client_builder: Some(self), }) } } diff --git a/nym-registration-client/src/clients/lp.rs b/nym-registration-client/src/clients/lp.rs index b924a8456f..6216614765 100644 --- a/nym-registration-client/src/clients/lp.rs +++ b/nym-registration-client/src/clients/lp.rs @@ -18,13 +18,12 @@ use rand09::{CryptoRng, RngCore, SeedableRng}; use std::sync::Arc; use tokio::net::TcpStream; use tokio_util::sync::CancellationToken; +use tracing::warn; pub struct LpBasedRegistrationClient { pub(crate) config: RegistrationClientConfig, pub(crate) bandwidth_controller: Box, pub(crate) cancel_token: CancellationToken, - // While we allow a fallback, we need to be able to build it - pub(crate) fallback_client_builder: Option, } impl LpBasedRegistrationClient { @@ -162,15 +161,11 @@ impl LpBasedRegistrationClient { self.register_wg_with_rng(&mut rng).await } - pub(crate) async fn register(mut self) -> Result { - let fallback = self.fallback_client_builder.take(); + async fn register_inner(mut self) -> Result { match &self.config.mode { RegistrationMode::Mixnet => { - if let Some(fallback) = fallback { - register_with_fallback(fallback).await - } else { - Err(RegistrationClientError::UnsupportedMode) - } + // mixnet registration is not supported for LP + Err(RegistrationClientError::UnsupportedMode) } RegistrationMode::Wireguard => { let lp_registration_result = self @@ -182,15 +177,9 @@ impl LpBasedRegistrationClient { // Everything went fine Some(Ok(res)) => Ok(res), - // LP reg failed, try fallback if we have one Some(Err(e)) => { tracing::error!("LP registration failed : {e}"); - if let Some(fallback) = fallback { - tracing::info!("Registering with fallback"); - register_with_fallback(fallback).await - } else { - Err(e) - } + Err(e) } // Cancelled registration @@ -199,12 +188,14 @@ impl LpBasedRegistrationClient { } } } -} -async fn register_with_fallback( - client_builder: RegistrationClientBuilder, -) -> Result { - // This is forcefully building a mixnet based client - let fallback_client = client_builder.build_mixnet().await?; - fallback_client.register().await + pub(crate) async fn register(mut self) -> Result { + let timeout = self.config.lp_registration_config.exchange_timeout; + tokio::time::timeout(timeout, self.register_inner()) + .await + .unwrap_or_else(|timeout| { + warn!("timed out while attempting to complete LP registration"); + Err(RegistrationClientError::Timeout(timeout)) + }) + } } diff --git a/nym-registration-client/src/lp_client/config.rs b/nym-registration-client/src/lp_client/config.rs index 506fc559a2..9684e99118 100644 --- a/nym-registration-client/src/lp_client/config.rs +++ b/nym-registration-client/src/lp_client/config.rs @@ -28,40 +28,43 @@ use std::time::Duration; /// - Optimize for latency over throughput (small messages) #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct LpRegistrationConfig { - /// TCP connection timeout (nym-102). + /// TCP connection timeout. /// /// Maximum time to wait for TCP connection establishment. - /// Default: 10 seconds. + /// Default: 5 seconds. pub connect_timeout: Duration, - /// Noise protocol handshake timeout (nym-102). + /// KKT/PSQ protocol handshake timeout. /// - /// Maximum time to wait for Noise handshake completion (all round-trips). - /// Default: 15 seconds. + /// Maximum time to wait for KKT/PSQ handshake completion with the entry (all round-trips). + /// Default: 8 seconds. pub handshake_timeout: Duration, - /// Registration request/response timeout (nym-102). + /// Registration request/response timeout. /// /// Maximum time to wait for registration request send + response receive. /// Includes credential verification on gateway side. - /// Default: 30 seconds. + /// Default: 8 seconds. pub registration_timeout: Duration, + /// Maximum time for the whole exchange (handshake + registration). + /// Default: 20 seconds. + pub exchange_timeout: Duration, + /// Forward packet send/receive timeout. /// - /// Maximum time to wait for forward packet send + response receive via entry gateway. - /// Covers the entire round-trip through entry to exit gateway and back. - /// Default: 30 seconds. + /// Maximum time to wait for forward packet to get sent via entry gateway. + /// Default: 3 seconds. pub forward_timeout: Duration, - /// Enable TCP_NODELAY (disable Nagle's algorithm) (nym-104). + /// Enable TCP_NODELAY (disable Nagle's algorithm). /// /// When true, disables Nagle's algorithm for lower latency. /// Recommended for registration messages which are small and latency-sensitive. /// Default: true. pub tcp_nodelay: bool, - /// TCP keepalive duration (nym-104). + /// TCP keepalive duration. /// /// When Some, enables TCP keepalive with specified interval. /// Since LP is registration-only with short-lived connections, keepalive is not needed. @@ -72,15 +75,14 @@ pub struct LpRegistrationConfig { impl Default for LpRegistrationConfig { fn default() -> Self { Self { - // nym-102: Sane timeout defaults for real network conditions - connect_timeout: Duration::from_secs(10), - handshake_timeout: Duration::from_secs(15), - registration_timeout: Duration::from_secs(30), - forward_timeout: Duration::from_secs(30), + connect_timeout: Duration::from_secs(5), + handshake_timeout: Duration::from_secs(8), + registration_timeout: Duration::from_secs(8), + exchange_timeout: Duration::from_secs(20), + forward_timeout: Duration::from_secs(3), - // nym-104: Optimized for registration-only protocol - tcp_nodelay: true, // Lower latency for small messages - tcp_keepalive: None, // Not needed for ephemeral connections + tcp_nodelay: true, + tcp_keepalive: None, } } } @@ -93,10 +95,11 @@ mod tests { fn test_default_config() { let config = LpRegistrationConfig::default(); - assert_eq!(config.connect_timeout, Duration::from_secs(10)); - assert_eq!(config.handshake_timeout, Duration::from_secs(15)); - assert_eq!(config.registration_timeout, Duration::from_secs(30)); - assert_eq!(config.forward_timeout, Duration::from_secs(30)); + assert_eq!(config.connect_timeout, Duration::from_secs(5)); + assert_eq!(config.handshake_timeout, Duration::from_secs(8)); + assert_eq!(config.registration_timeout, Duration::from_secs(8)); + assert_eq!(config.forward_timeout, Duration::from_secs(3)); + assert_eq!(config.exchange_timeout, Duration::from_secs(20)); assert!(config.tcp_nodelay); assert_eq!(config.tcp_keepalive, None); }