From 12ccf3d649ce2f0a091472b38fa789e83fefb18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Fri, 11 Oct 2024 00:15:04 -0700 Subject: [PATCH 1/3] fix(client): always adding retry delay, even on first connection --- fedimint-api-client/src/api/peer.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fedimint-api-client/src/api/peer.rs b/fedimint-api-client/src/api/peer.rs index 9c3e14554c5..75a1585248e 100644 --- a/fedimint-api-client/src/api/peer.rs +++ b/fedimint-api-client/src/api/peer.rs @@ -193,12 +193,15 @@ impl FederationPeerClientConnectionState { async fn wait(&mut self) { let now_ts = now(); let desired_timeout = self.connection_backoff.next().unwrap_or(Self::MAX_BACKOFF); - let since_last_connect = match self.last_connection_attempt_or { - Some(last) => now_ts.duration_since(last).unwrap_or_default(), + + let sleep_duration = match self.last_connection_attempt_or { + Some(last) => { + let since_last_connect = now_ts.duration_since(last).unwrap_or_default(); + desired_timeout.saturating_sub(since_last_connect) + } None => Duration::ZERO, }; - let sleep_duration = desired_timeout.saturating_sub(since_last_connect); if Duration::ZERO < sleep_duration { debug!( target: LOG_CLIENT_NET_API, From 4a65639234191cfbcdb3586c5b864233d1f1f3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Fri, 11 Oct 2024 00:18:12 -0700 Subject: [PATCH 2/3] refactor(client): rename weirdly named field Adding `_or` to an `Option` field is confusing. --- fedimint-api-client/src/api/peer.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fedimint-api-client/src/api/peer.rs b/fedimint-api-client/src/api/peer.rs index 75a1585248e..98ee474ec18 100644 --- a/fedimint-api-client/src/api/peer.rs +++ b/fedimint-api-client/src/api/peer.rs @@ -145,7 +145,7 @@ where ) { let mut connection_state_guard = connection_state.lock().await; - if connection_state_guard.last_connection_attempt_or.is_none() { + if connection_state_guard.last_connection_attempt.is_none() { debug!( target: LOG_CLIENT_NET_API, peer_id = %peer_id, @@ -169,7 +169,7 @@ where struct FederationPeerClientConnectionState { /// Last time a connection attempt was made, or `None` if no attempt has /// been made yet. - last_connection_attempt_or: Option, + last_connection_attempt: Option, connection_backoff: backoff_util::FibonacciBackoff, } @@ -179,7 +179,7 @@ impl FederationPeerClientConnectionState { fn new() -> Self { Self { - last_connection_attempt_or: None, + last_connection_attempt: None, connection_backoff: backoff_util::custom_backoff( Self::MIN_BACKOFF, Self::MAX_BACKOFF, @@ -194,7 +194,7 @@ impl FederationPeerClientConnectionState { let now_ts = now(); let desired_timeout = self.connection_backoff.next().unwrap_or(Self::MAX_BACKOFF); - let sleep_duration = match self.last_connection_attempt_or { + let sleep_duration = match self.last_connection_attempt { Some(last) => { let since_last_connect = now_ts.duration_since(last).unwrap_or_default(); desired_timeout.saturating_sub(since_last_connect) @@ -210,7 +210,7 @@ impl FederationPeerClientConnectionState { fedimint_core::runtime::sleep(sleep_duration).await; } - self.last_connection_attempt_or = Some(now_ts); + self.last_connection_attempt = Some(now_ts); } fn reset(&mut self) { From d96498c08fb08e2407941e50fe0bb01155e5756a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Thu, 10 Oct 2024 23:59:12 -0700 Subject: [PATCH 3/3] chore: optimize rustls --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index ce86b338d49..66ad65745e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -220,6 +220,7 @@ rand_chacha = { opt-level = 3 } rand_core = { opt-level = 3 } rand = { opt-level = 3 } ring = { opt-level = 3 } +rustls = { opt-level = 3 } secp256k1 = { opt-level = 3 } secp256k1-sys = { opt-level = 3 } subtle = { opt-level = 3 }