upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-18 20:32:13 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-18 20:32:13 +0000
commitee113a654e2971a6ebdb07398cc5638dbe59b48c (patch)
tree6e4aacd207553c367d9b533fd6d4824d34994c82 /src/nostr
parente7e61d1abfb3609c6818e6040294c6be19ba805f (diff)
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.
Diffstat (limited to 'src/nostr')
-rw-r--r--src/nostr/builder.rs54
-rw-r--r--src/nostr/policy/mod.rs19
2 files changed, 1 insertions, 72 deletions
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::{
17 AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, 17 AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult,
18 RelatedEventPolicy, StatePolicy, StateResult, 18 RelatedEventPolicy, StatePolicy, StateResult,
19}; 19};
20use crate::sync::{RepoSyncIndex, RepoSyncNeeds, SyncLevel}; 20
21 21
22/// Type alias for the shared database used by the relay 22/// Type alias for the shared database used by the relay
23pub type SharedDatabase = Arc<dyn NostrDatabase>; 23pub type SharedDatabase = Arc<dyn NostrDatabase>;
@@ -99,14 +99,6 @@ impl Nip34WritePolicy {
99 self.ctx.set_local_relay(relay); 99 self.ctx.set_local_relay(relay);
100 } 100 }
101 101
102 /// Set the repo sync index so that user-submitted purgatory announcements can
103 /// be registered for state event sync immediately.
104 ///
105 /// This must be called after SyncManager is created.
106 pub fn set_repo_sync_index(&self, index: RepoSyncIndex) {
107 self.ctx.set_repo_sync_index(index);
108 }
109
110 /// Handle repository announcement event 102 /// Handle repository announcement event
111 async fn handle_announcement(&self, event: &Event) -> WritePolicyResult { 103 async fn handle_announcement(&self, event: &Event) -> WritePolicyResult {
112 let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex()); 104 let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex());
@@ -156,50 +148,6 @@ impl Nip34WritePolicy {
156 event_id_str 148 event_id_str
157 ); 149 );
158 150
159 // Register repo in repo_sync_index with StateOnly level so that
160 // state event sync starts promptly via the next batch EOSE recompute.
161 // This handles user-submitted purgatory announcements - the SelfSubscriber
162 // only sees DB events, so it won't pick these up automatically.
163 if let Some(repo_sync_index) = self.ctx.get_repo_sync_index() {
164 if let Ok(announcement) =
165 RepositoryAnnouncement::from_event(event.clone())
166 {
167 use std::collections::HashSet;
168 let repo_id = format!(
169 "30617:{}:{}",
170 event.pubkey,
171 announcement.identifier
172 );
173
174 // Extract relay URLs from the announcement event tags
175 let relays: HashSet<String> = event
176 .tags
177 .iter()
178 .flat_map(|tag| {
179 let tag_vec = tag.as_slice();
180 if !tag_vec.is_empty() && tag_vec[0] == "relays" {
181 tag_vec[1..].iter().map(|s| s.to_string()).collect::<Vec<_>>()
182 } else {
183 vec![]
184 }
185 })
186 .collect();
187
188 let mut index = repo_sync_index.write().await;
189 index.entry(repo_id.clone()).or_insert_with(|| RepoSyncNeeds {
190 relays,
191 root_events: HashSet::new(),
192 sync_level: SyncLevel::StateOnly,
193 });
194 drop(index);
195
196 tracing::debug!(
197 repo_id = %repo_id,
198 "Registered purgatory announcement in repo_sync_index as StateOnly"
199 );
200 }
201 }
202
203 WritePolicyResult::Reject { 151 WritePolicyResult::Reject {
204 status: true, // Client sees OK 152 status: true, // Client sees OK
205 message: "purgatory: won't be served until git data arrives".into(), 153 message: "purgatory: won't be served until git data arrives".into(),
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs
index c958586..1566b6c 100644
--- a/src/nostr/policy/mod.rs
+++ b/src/nostr/policy/mod.rs
@@ -20,7 +20,6 @@ pub use crate::git::sync::AlignmentResult;
20 20
21use super::SharedDatabase; 21use super::SharedDatabase;
22use crate::purgatory::Purgatory; 22use crate::purgatory::Purgatory;
23use crate::sync::RepoSyncIndex;
24use nostr_relay_builder::LocalRelay; 23use nostr_relay_builder::LocalRelay;
25use std::sync::Arc; 24use std::sync::Arc;
26 25
@@ -35,8 +34,6 @@ pub struct PolicyContext {
35 pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, 34 pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>,
36 /// Configuration reference for policy settings (includes blacklists) 35 /// Configuration reference for policy settings (includes blacklists)
37 pub config: crate::config::Config, 36 pub config: crate::config::Config,
38 /// Repo sync index for registering purgatory announcements (set after SyncManager creation)
39 pub repo_sync_index: Arc<std::sync::RwLock<Option<RepoSyncIndex>>>,
40} 37}
41 38
42impl PolicyContext { 39impl PolicyContext {
@@ -54,7 +51,6 @@ impl PolicyContext {
54 purgatory, 51 purgatory,
55 local_relay: Arc::new(std::sync::RwLock::new(None)), 52 local_relay: Arc::new(std::sync::RwLock::new(None)),
56 config, 53 config,
57 repo_sync_index: Arc::new(std::sync::RwLock::new(None)),
58 } 54 }
59 } 55 }
60 56
@@ -72,19 +68,4 @@ impl PolicyContext {
72 let guard = self.local_relay.read().unwrap(); 68 let guard = self.local_relay.read().unwrap();
73 guard.clone() 69 guard.clone()
74 } 70 }
75
76 /// Set the repo sync index after SyncManager has been created.
77 ///
78 /// This allows purgatory announcements submitted by users to be registered
79 /// in the sync index so state event sync starts promptly.
80 pub fn set_repo_sync_index(&self, index: RepoSyncIndex) {
81 let mut guard = self.repo_sync_index.write().unwrap();
82 *guard = Some(index);
83 }
84
85 /// Get a clone of the repo sync index if it has been set.
86 pub fn get_repo_sync_index(&self) -> Option<RepoSyncIndex> {
87 let guard = self.repo_sync_index.read().unwrap();
88 guard.clone()
89 }
90} 71}