diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 19:41:29 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 19:41:29 +0000 |
| commit | e22021f0b248ebcf3bd09210d59b2cdb4701032f (patch) | |
| tree | 3dd1a3a75a8b7424749c0b0505a3d1ab61ac7895 /src/nostr/policy | |
| parent | a804164468d3beafb243ece12555b4d1692a075d (diff) | |
fix: simplify purgatory sync - fix SelfSubscriber sync_level upgrade and negentropy fallback
Three targeted fixes for purgatory announcement sync:
1. SelfSubscriber sync_level upgrade: After or_insert_with in process_batch,
always set entry.sync_level = SyncLevel::Full so that when a promoted
announcement is broadcast via notify_event and SelfSubscriber receives it,
an existing StateOnly entry gets upgraded to Full and PR event subscriptions
are triggered immediately (not delayed up to 24h).
2. Negentropy fallback filter split: In handle_eose, when falling back from
negentropy to REQ+EOSE, split batch_repos by SyncLevel and call
build_sync_level_aware_filters instead of build_layer2_and_layer3_filters.
Prevents StateOnly (purgatory) repos from getting Layer 2 #a/#A/#q filters
prematurely, which caused nostr-sdk client deduplication to permanently
drop PR events after orphan rejection.
3. Recompute sync filters after announcement batch EOSE: Add
recompute_new_sync_filters_for_relay calls at all three batch-completion
paths in handle_eose for generic filter (announcement) batches. This
triggers state-only subscriptions for any purgatory repos registered during
that batch, fixing the 24h delay before state event sync starts.
4. User-submitted purgatory announcements: Add repo_sync_index field to
PolicyContext with setter/getter, wire in main.rs after SyncManager
creation, and register in AcceptPurgatory handler so user-submitted
announcements get StateOnly sync started immediately.
5. Update archive tests: test_archive_without_state_events_does_not_sync_git
updated to reflect that StateOnly subscription now proactively fetches
state events from source relays. test_archive_read_only_creates_bare_repo
un-ignored as it now works end-to-end.
Diffstat (limited to 'src/nostr/policy')
| -rw-r--r-- | src/nostr/policy/mod.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs index 1566b6c..c958586 100644 --- a/src/nostr/policy/mod.rs +++ b/src/nostr/policy/mod.rs | |||
| @@ -20,6 +20,7 @@ pub use crate::git::sync::AlignmentResult; | |||
| 20 | 20 | ||
| 21 | use super::SharedDatabase; | 21 | use super::SharedDatabase; |
| 22 | use crate::purgatory::Purgatory; | 22 | use crate::purgatory::Purgatory; |
| 23 | use crate::sync::RepoSyncIndex; | ||
| 23 | use nostr_relay_builder::LocalRelay; | 24 | use nostr_relay_builder::LocalRelay; |
| 24 | use std::sync::Arc; | 25 | use std::sync::Arc; |
| 25 | 26 | ||
| @@ -34,6 +35,8 @@ pub struct PolicyContext { | |||
| 34 | pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, | 35 | pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, |
| 35 | /// Configuration reference for policy settings (includes blacklists) | 36 | /// Configuration reference for policy settings (includes blacklists) |
| 36 | pub config: crate::config::Config, | 37 | 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>>>, | ||
| 37 | } | 40 | } |
| 38 | 41 | ||
| 39 | impl PolicyContext { | 42 | impl PolicyContext { |
| @@ -51,6 +54,7 @@ impl PolicyContext { | |||
| 51 | purgatory, | 54 | purgatory, |
| 52 | local_relay: Arc::new(std::sync::RwLock::new(None)), | 55 | local_relay: Arc::new(std::sync::RwLock::new(None)), |
| 53 | config, | 56 | config, |
| 57 | repo_sync_index: Arc::new(std::sync::RwLock::new(None)), | ||
| 54 | } | 58 | } |
| 55 | } | 59 | } |
| 56 | 60 | ||
| @@ -68,4 +72,19 @@ impl PolicyContext { | |||
| 68 | let guard = self.local_relay.read().unwrap(); | 72 | let guard = self.local_relay.read().unwrap(); |
| 69 | guard.clone() | 73 | guard.clone() |
| 70 | } | 74 | } |
| 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 | } | ||
| 71 | } | 90 | } |