From ee113a654e2971a6ebdb07398cc5638dbe59b48c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 18 Feb 2026 20:32:13 +0000 Subject: fix: replace repo_sync_index wiring with purgatory announcement sync timer Instead of threading repo_sync_index through PolicyContext/builder.rs/main.rs to handle user-submitted purgatory announcements, add a simple background timer (run_purgatory_announcement_sync, every 5s) that scans the purgatory for announcement entries and registers them in repo_sync_index as StateOnly. This is simpler and covers both flows: - Sync-path announcements: inline registration still happens during event processing (sync/mod.rs:1839+), timer provides a safety net - User-submitted announcements: SelfSubscriber never sees them (rejected from DB), timer is the primary registration path The timer calls sync_purgatory_announcements_to_index() which: 1. Snapshots purgatory via new announcements_for_sync() public method 2. Or_inserts StateOnly entries (never downgrades Full entries) 3. Detects newly added relay URLs and calls handle_new_sync_filters to connect and subscribe - fixing the failing test that expected relay discovery from a user-submitted purgatory announcement Removes: repo_sync_index field from PolicyContext, set/get_repo_sync_index methods, set_repo_sync_index on Nip34WritePolicy, wiring in main.rs, and the inline AcceptPurgatory registration block in builder.rs. --- src/nostr/builder.rs | 54 +--------------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'src/nostr/builder.rs') diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 8d1e461..c2d4939 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs @@ -17,7 +17,7 @@ use crate::nostr::policy::{ AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, RelatedEventPolicy, StatePolicy, StateResult, }; -use crate::sync::{RepoSyncIndex, RepoSyncNeeds, SyncLevel}; + /// Type alias for the shared database used by the relay pub type SharedDatabase = Arc; @@ -99,14 +99,6 @@ impl Nip34WritePolicy { self.ctx.set_local_relay(relay); } - /// Set the repo sync index so that user-submitted purgatory announcements can - /// be registered for state event sync immediately. - /// - /// This must be called after SyncManager is created. - pub fn set_repo_sync_index(&self, index: RepoSyncIndex) { - self.ctx.set_repo_sync_index(index); - } - /// Handle repository announcement event async fn handle_announcement(&self, event: &Event) -> WritePolicyResult { let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex()); @@ -156,50 +148,6 @@ impl Nip34WritePolicy { event_id_str ); - // Register repo in repo_sync_index with StateOnly level so that - // state event sync starts promptly via the next batch EOSE recompute. - // This handles user-submitted purgatory announcements - the SelfSubscriber - // only sees DB events, so it won't pick these up automatically. - if let Some(repo_sync_index) = self.ctx.get_repo_sync_index() { - if let Ok(announcement) = - RepositoryAnnouncement::from_event(event.clone()) - { - use std::collections::HashSet; - let repo_id = format!( - "30617:{}:{}", - event.pubkey, - announcement.identifier - ); - - // Extract relay URLs from the announcement event tags - let relays: HashSet = event - .tags - .iter() - .flat_map(|tag| { - let tag_vec = tag.as_slice(); - if !tag_vec.is_empty() && tag_vec[0] == "relays" { - tag_vec[1..].iter().map(|s| s.to_string()).collect::>() - } else { - vec![] - } - }) - .collect(); - - let mut index = repo_sync_index.write().await; - index.entry(repo_id.clone()).or_insert_with(|| RepoSyncNeeds { - relays, - root_events: HashSet::new(), - sync_level: SyncLevel::StateOnly, - }); - drop(index); - - tracing::debug!( - repo_id = %repo_id, - "Registered purgatory announcement in repo_sync_index as StateOnly" - ); - } - } - WritePolicyResult::Reject { status: true, // Client sees OK message: "purgatory: won't be served until git data arrives".into(), -- cgit v1.2.3