upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sync/algorithms.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-12 10:09:47 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-12 10:20:42 +0000
commitde07e31fad60f9c68a08807cde17ff81d8371a65 (patch)
tree1c670ff38f6702b6e437877049038fbbf3281f97 /src/sync/algorithms.rs
parent307c380a91a3575ab2266ed08427d24c7b2d016e (diff)
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
Diffstat (limited to 'src/sync/algorithms.rs')
-rw-r--r--src/sync/algorithms.rs4
1 files changed, 3 insertions, 1 deletions
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};
11 11
12use nostr_sdk::prelude::*; 12use nostr_sdk::prelude::*;
13 13
14use super::{ConnectionStatus, PendingBatch, RelayState}; 14use super::{ConnectionStatus, PendingBatch, RelayState, SyncMethod};
15 15
16// ============================================================================= 16// =============================================================================
17// Data Structures 17// Data Structures
@@ -396,6 +396,7 @@ mod tests {
396 root_events: HashSet::new(), 396 root_events: HashSet::new(),
397 }, 397 },
398 outstanding_subs: HashSet::new(), 398 outstanding_subs: HashSet::new(),
399 sync_method: SyncMethod::ReqEose,
399 }], 400 }],
400 ); 401 );
401 402
@@ -504,6 +505,7 @@ mod tests {
504 root_events: HashSet::new(), 505 root_events: HashSet::new(),
505 }, 506 },
506 outstanding_subs: HashSet::new(), 507 outstanding_subs: HashSet::new(),
508 sync_method: SyncMethod::ReqEose,
507 }], 509 }],
508 ); 510 );
509 511