From de07e31fad60f9c68a08807cde17ff81d8371a65 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 12 Dec 2025 10:09:47 +0000 Subject: fix: unify sync state tracking for negentropy and REQ+EOSE paths When negentropy (NIP-77) sync was enabled, the RelaySyncIndex was never updated to reflect historical sync completion. This caused the three-way diff algorithm in compute_actions() to malfunction, leading to: - Repeated sync attempts for the same items - Incorrect filter counting for consolidation - Potential premature relay disconnection This fix unifies both sync paths (REQ+EOSE and Negentropy) through a consistent PendingBatch flow: 1. Added SyncMethod enum to distinguish between sync types 2. Updated PendingBatch struct to include sync_method field 3. Extracted confirm_batch() method for unified batch confirmation 4. Modified negentropy_sync_and_process() to: - Create a PendingBatch before sync - Add batch to pending_sync_index - On success: Remove batch and call confirm_batch() - On failure: Remove batch without confirming The confirm_batch() method moves repos and root_events from the batch to the RelayState.repos and RelayState.root_events, ensuring the three-way diff works correctly regardless of sync method. Closes: negentropy-sync-state-tracking.md --- src/sync/algorithms.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/sync/algorithms.rs') diff --git a/src/sync/algorithms.rs b/src/sync/algorithms.rs index 3063516..5b5b520 100644 --- a/src/sync/algorithms.rs +++ b/src/sync/algorithms.rs @@ -11,7 +11,7 @@ use std::collections::{HashMap, HashSet}; use nostr_sdk::prelude::*; -use super::{ConnectionStatus, PendingBatch, RelayState}; +use super::{ConnectionStatus, PendingBatch, RelayState, SyncMethod}; // ============================================================================= // Data Structures @@ -396,6 +396,7 @@ mod tests { root_events: HashSet::new(), }, outstanding_subs: HashSet::new(), + sync_method: SyncMethod::ReqEose, }], ); @@ -504,6 +505,7 @@ mod tests { root_events: HashSet::new(), }, outstanding_subs: HashSet::new(), + sync_method: SyncMethod::ReqEose, }], ); -- cgit v1.2.3