diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 17:12:17 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 17:12:17 +0000 |
| commit | d76003b629a4a03dba23a8a1c41da6e4ac4c30cf (patch) | |
| tree | 38412fdeed3e7996923603fe1964db4e5ce94bdc /src/git | |
| parent | 806936e7d1aab5dfd0c2ad6b98a115122dc1785c (diff) | |
feat: upgrade repo to Full sync and trigger PR event subscription after announcement promotion
When git data arrives for a purgatory announcement and promotes it to the
database, the relay now:
1. Upgrades the announcement's sync level in RepoSyncIndex from StateOnly
to Full (git/sync.rs: process_purgatory_announcements)
2. Sends AddFilters actions to SyncManager for all connected relays, using
Full sync filters (Layer 2 #a/#A/#q) to subscribe to PR events
(purgatory/sync/context.rs: RealSyncContext.process_newly_available_git_data)
3. For user-submitted purgatory announcements, registers the repo in
RepoSyncIndex with StateOnly level and sends AddFilters to SyncManager
so it discovers and connects to relays listed in the announcement tags
(nostr/builder.rs: handle_announcement AcceptPurgatory path)
The RealSyncContext now accepts optional repo_sync_index and sync_action_tx
parameters. main.rs wires these up from SyncManager. PolicyContext gains
repo_sync_index and sync_action_tx fields for the write policy path.
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/handlers.rs | 1 | ||||
| -rw-r--r-- | src/git/sync.rs | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/git/handlers.rs b/src/git/handlers.rs index 017eee4..129ca2c 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs | |||
| @@ -307,6 +307,7 @@ pub async fn handle_receive_pack( | |||
| 307 | Some(&relay), | 307 | Some(&relay), |
| 308 | &purgatory, | 308 | &purgatory, |
| 309 | git_data_path_buf, | 309 | git_data_path_buf, |
| 310 | None, | ||
| 310 | ) | 311 | ) |
| 311 | .await | 312 | .await |
| 312 | { | 313 | { |
diff --git a/src/git/sync.rs b/src/git/sync.rs index 4b35023..b3fa11a 100644 --- a/src/git/sync.rs +++ b/src/git/sync.rs | |||
| @@ -44,6 +44,7 @@ use crate::git::{self, oid_exists}; | |||
| 44 | use crate::nostr::builder::SharedDatabase; | 44 | use crate::nostr::builder::SharedDatabase; |
| 45 | use crate::nostr::events::RepositoryState; | 45 | use crate::nostr::events::RepositoryState; |
| 46 | use crate::purgatory::{can_apply_state, Purgatory}; | 46 | use crate::purgatory::{can_apply_state, Purgatory}; |
| 47 | use crate::sync::{RepoSyncIndex, SyncLevel}; | ||
| 47 | 48 | ||
| 48 | /// Result of processing newly available git data. | 49 | /// Result of processing newly available git data. |
| 49 | /// | 50 | /// |
| @@ -809,6 +810,7 @@ pub fn extract_identifier_from_pr_event(event: &Event) -> Option<String> { | |||
| 809 | /// * `local_relay` - Local relay for notifying WebSocket subscribers (optional) | 810 | /// * `local_relay` - Local relay for notifying WebSocket subscribers (optional) |
| 810 | /// * `purgatory` - Purgatory instance to check for satisfiable events | 811 | /// * `purgatory` - Purgatory instance to check for satisfiable events |
| 811 | /// * `git_data_path` - Base path for git repositories | 812 | /// * `git_data_path` - Base path for git repositories |
| 813 | /// * `repo_sync_index` - Optional repo sync index for upgrading sync level on promotion | ||
| 812 | /// | 814 | /// |
| 813 | /// # Returns | 815 | /// # Returns |
| 814 | /// A `ProcessResult` describing what was processed | 816 | /// A `ProcessResult` describing what was processed |
| @@ -819,6 +821,7 @@ pub async fn process_newly_available_git_data( | |||
| 819 | local_relay: Option<&nostr_relay_builder::LocalRelay>, | 821 | local_relay: Option<&nostr_relay_builder::LocalRelay>, |
| 820 | purgatory: &Purgatory, | 822 | purgatory: &Purgatory, |
| 821 | git_data_path: &Path, | 823 | git_data_path: &Path, |
| 824 | repo_sync_index: Option<RepoSyncIndex>, | ||
| 822 | ) -> anyhow::Result<ProcessResult> { | 825 | ) -> anyhow::Result<ProcessResult> { |
| 823 | let mut result = ProcessResult::default(); | 826 | let mut result = ProcessResult::default(); |
| 824 | 827 | ||
| @@ -848,6 +851,7 @@ pub async fn process_newly_available_git_data( | |||
| 848 | local_relay, | 851 | local_relay, |
| 849 | purgatory, | 852 | purgatory, |
| 850 | git_data_path, | 853 | git_data_path, |
| 854 | repo_sync_index.as_ref(), | ||
| 851 | ) | 855 | ) |
| 852 | .await; | 856 | .await; |
| 853 | result.merge(announcement_result); | 857 | result.merge(announcement_result); |
| @@ -1284,6 +1288,7 @@ async fn process_purgatory_announcements( | |||
| 1284 | local_relay: Option<&nostr_relay_builder::LocalRelay>, | 1288 | local_relay: Option<&nostr_relay_builder::LocalRelay>, |
| 1285 | purgatory: &Purgatory, | 1289 | purgatory: &Purgatory, |
| 1286 | git_data_path: &Path, | 1290 | git_data_path: &Path, |
| 1291 | repo_sync_index: Option<&RepoSyncIndex>, | ||
| 1287 | ) -> ProcessResult { | 1292 | ) -> ProcessResult { |
| 1288 | let mut result = ProcessResult::default(); | 1293 | let mut result = ProcessResult::default(); |
| 1289 | 1294 | ||
| @@ -1338,6 +1343,22 @@ async fn process_purgatory_announcements( | |||
| 1338 | } | 1343 | } |
| 1339 | } | 1344 | } |
| 1340 | 1345 | ||
| 1346 | // Upgrade sync level to Full in repo_sync_index | ||
| 1347 | if let Some(index) = repo_sync_index { | ||
| 1348 | let mut index = index.write().await; | ||
| 1349 | // Use hex pubkey format to match how repo_sync_index keys are built | ||
| 1350 | // (sync/mod.rs uses event.pubkey which is hex, not bech32) | ||
| 1351 | let repo_id = format!("30617:{}:{}", owner.to_hex(), identifier); | ||
| 1352 | if let Some(entry) = index.get_mut(&repo_id) { | ||
| 1353 | entry.sync_level = SyncLevel::Full; | ||
| 1354 | debug!( | ||
| 1355 | identifier = %identifier, | ||
| 1356 | repo_id = %repo_id, | ||
| 1357 | "Upgraded sync level to Full after announcement promotion" | ||
| 1358 | ); | ||
| 1359 | } | ||
| 1360 | } | ||
| 1361 | |||
| 1341 | result.announcements_released += 1; | 1362 | result.announcements_released += 1; |
| 1342 | } | 1363 | } |
| 1343 | Err(e) => { | 1364 | Err(e) => { |