From 52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 16:45:34 +0000 Subject: sync: test sync works without negentropy and add disable option in sync --- src/config.rs | 7 +++++++ src/http/nip11.rs | 2 ++ src/sync/mod.rs | 11 ++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index f3a3e2a..8c6de05 100644 --- a/src/config.rs +++ b/src/config.rs @@ -104,6 +104,12 @@ pub struct Config { /// Note: The connection timeout is capped at this value #[arg(long, env = "NGIT_SYNC_BASE_BACKOFF_SECS", default_value_t = 5)] pub sync_base_backoff_secs: u64, + + /// Disable NIP-77 negentropy sync (default: false) + /// When enabled, sync will use REQ+EOSE instead of negentropy for history sync. + /// Primarily useful for testing that sync works without negentropy support. + #[arg(long, env = "NGIT_SYNC_DISABLE_NEGENTROPY", default_value_t = false)] + pub sync_disable_negentropy: bool, } impl Config { @@ -163,6 +169,7 @@ impl Config { sync_max_backoff_secs: 3600, sync_disconnect_check_interval_secs: 60, sync_base_backoff_secs: 5, + sync_disable_negentropy: false, } } } diff --git a/src/http/nip11.rs b/src/http/nip11.rs index 8c18dde..7df8306 100644 --- a/src/http/nip11.rs +++ b/src/http/nip11.rs @@ -109,6 +109,7 @@ mod tests { sync_max_backoff_secs: 3600, sync_disconnect_check_interval_secs: 60, sync_base_backoff_secs: 5, + sync_disable_negentropy: false, }; let doc = RelayInformationDocument::from_config(&config); @@ -147,6 +148,7 @@ mod tests { sync_max_backoff_secs: 3600, sync_disconnect_check_interval_secs: 60, sync_base_backoff_secs: 5, + sync_disable_negentropy: false, }; let doc = RelayInformationDocument::from_config(&config); diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 3f3966a..c4c3c7f 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -511,8 +511,9 @@ impl SyncManager { } }; - // Check if relay supports NIP-77 negentropy - let use_negentropy = connection.supports_negentropy().await; + // Check if relay supports NIP-77 negentropy AND negentropy is not disabled + let use_negentropy = !self.config.sync_disable_negentropy + && connection.supports_negentropy().await; // Unsubscribe all current subscriptions connection.unsubscribe_all().await; @@ -948,7 +949,11 @@ impl SyncManager { ); // Check if relay supports NIP-77 negentropy for efficient sync - let use_negentropy = if let Some(connection) = self.connections.get(relay_url) { + // Respect the sync_disable_negentropy config option + let use_negentropy = if self.config.sync_disable_negentropy { + tracing::debug!(relay = %relay_url, "Negentropy disabled via config"); + false + } else if let Some(connection) = self.connections.get(relay_url) { connection.supports_negentropy().await } else { false -- cgit v1.2.3