From 6b55efedba7c069eff7a3e335845a961d40274db Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 22 Dec 2025 21:03:49 +0000 Subject: chore: cargo fmt and clippy --- src/sync/health.rs | 12 +++++++----- src/sync/mod.rs | 2 +- src/sync/relay_connection.rs | 4 ++-- tests/common/sync_helpers.rs | 35 +++++++++++++---------------------- tests/sync/tag_variations.rs | 2 +- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/sync/health.rs b/src/sync/health.rs index a10427f..2948707 100644 --- a/src/sync/health.rs +++ b/src/sync/health.rs @@ -136,12 +136,14 @@ impl RelayHealth { // Check if we're in stability period after recovery // (recovered from failures but not yet proven stable) - if let (Some(last_success), Some(last_failure)) = (self.last_success_time, self.last_failure_time) { + if let (Some(last_success), Some(last_failure)) = + (self.last_success_time, self.last_failure_time) + { // Only consider stability period if recovery happened after the last failure if last_success > last_failure { let time_since_recovery = now.duration_since(last_success); let stability_period = Duration::from_secs(STABILITY_PERIOD_SECS); - + if time_since_recovery < stability_period { // Still in stability period - remain degraded to prove stability return HealthState::Degraded; @@ -339,9 +341,10 @@ impl RelayHealthTracker { // Respect existing next_retry_at if it's later (e.g., from rate limiting) let new_retry_at = now + backoff; health.next_retry_at = Some( - health.next_retry_at + health + .next_retry_at .unwrap_or(new_retry_at) - .max(new_retry_at) + .max(new_retry_at), ); let new_state = health.state(); @@ -393,7 +396,6 @@ impl RelayHealthTracker { } } - /// Check if relay is currently rate limited /// /// Returns true if the relay is in RateLimited state and the cooldown period diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 6ec39e8..65affc6 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1599,7 +1599,7 @@ impl SyncManager { write_policy: &Nip34WritePolicy, local_relay: &LocalRelay, ) -> ProcessResult { - use nostr_relay_builder::prelude::{WritePolicyResult, WritePolicy}; + use nostr_relay_builder::prelude::{WritePolicy, WritePolicyResult}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; // Check if event already exists match database.event_by_id(&event.id).await { diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs index de20e0f..bd9ab80 100644 --- a/src/sync/relay_connection.rs +++ b/src/sync/relay_connection.rs @@ -24,7 +24,7 @@ use crate::nostr::builder::SharedDatabase; #[derive(Debug)] pub enum RelayEvent { /// A new event was received (event, subscription_id) - Event(Event, SubscriptionId), + Event(Box, SubscriptionId), /// End of stored events for a subscription EndOfStoredEvents(SubscriptionId), /// NOTICE message from relay @@ -219,7 +219,7 @@ impl RelayConnection { "Received event" ); if event_sender - .send(RelayEvent::Event(*event, subscription_id.clone())) + .send(RelayEvent::Event(Box::new(*event), subscription_id.clone())) .await .is_err() { diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index cccfbdd..8279a04 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs @@ -795,9 +795,8 @@ impl MetricsTestHarness { /// Start syncing relay on a specific port pointing to source[idx] pub async fn start_syncing_relay_on_port(&mut self, source_idx: usize, port: u16) { let source_url = self.source_relays[source_idx].url().to_string(); - self.syncing_relay = Some( - TestRelay::start_on_port_with_options(port, Some(source_url), false).await, - ); + self.syncing_relay = + Some(TestRelay::start_on_port_with_options(port, Some(source_url), false).await); } /// Start syncing relay pointing to random unused port (for failure tests) @@ -1122,16 +1121,15 @@ async fn send_to_relay(relay: &TestRelay, event: &Event) -> Result<(), String> { /// let result = run_sync_test(&[], &[comment]).await; /// // Assert comment synced to result.syncing_relay /// ``` -pub async fn run_sync_test( - historic_events: &[Event], - live_events: &[Event], -) -> SyncTestResult { +pub async fn run_sync_test(historic_events: &[Event], live_events: &[Event]) -> SyncTestResult { // Validate usage - cannot provide events in both slices let historic_mode = !historic_events.is_empty(); let live_mode = !live_events.is_empty(); - + if historic_mode && live_mode { - panic!("Invalid usage: both historic_events and live_events provided. Use one or the other."); + panic!( + "Invalid usage: both historic_events and live_events provided. Use one or the other." + ); } // Note: Both slices can be empty - this tests just the announcement sync @@ -1144,11 +1142,8 @@ pub async fn run_sync_test( // 3. Create keys and announcement listing both relays let keys = Keys::generate(); - let announcement = create_repo_announcement( - &keys, - &[&source.domain(), &syncing_domain], - "test-repo", - ); + let announcement = + create_repo_announcement(&keys, &[&source.domain(), &syncing_domain], "test-repo"); // 4. Send announcement + historic events to source BEFORE syncing relay starts send_to_relay(&source, &announcement) @@ -1161,12 +1156,8 @@ pub async fn run_sync_test( } // 5. Start syncing relay (connects to source) - let syncing = TestRelay::start_on_port_with_options( - syncing_port, - Some(source.url().into()), - false, - ) - .await; + let syncing = + TestRelay::start_on_port_with_options(syncing_port, Some(source.url().into()), false).await; // 6. Wait for sync connection to establish let _ = wait_for_sync_connection(syncing.url(), 1, Duration::from_secs(5)).await; @@ -1208,8 +1199,8 @@ mod sync_helper_tests { async fn test_run_sync_test_panics_with_both_slices() { let keys = Keys::generate(); let coord = repo_coord(&keys, "test"); - let historic = build_layer2_issue_event(&keys, &coord, "Historic") - .expect("Should create event"); + let historic = + build_layer2_issue_event(&keys, &coord, "Historic").expect("Should create event"); let live = build_layer3_reply_with_e_tag(&keys, &EventId::all_zeros(), "Live") .expect("Should create event"); diff --git a/tests/sync/tag_variations.rs b/tests/sync/tag_variations.rs index 5b3ec0b..7153104 100644 --- a/tests/sync/tag_variations.rs +++ b/tests/sync/tag_variations.rs @@ -344,7 +344,7 @@ async fn test_layer3_sync_with_lowercase_e_tag() { .with_max_level(tracing::Level::DEBUG) .with_test_writer() .try_init(); - + // 1. Start relays let relay_a = TestRelay::start().await; println!( -- cgit v1.2.3