upleb.uk

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

summaryrefslogtreecommitdiff
path: root/docs/explanation/architecture.md
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-24 08:02:12 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-24 11:54:18 +0000
commit70d0197e85ae4ef85202781f6d2dc9e76bd508b3 (patch)
tree45efb6565e81ba755acc5955e68d5b7119d1e122 /docs/explanation/architecture.md
parentf8c3e3920ed2a1bdaab30be912276993449a5476 (diff)
feat(purgatory): add broken purgatory implementation
Diffstat (limited to 'docs/explanation/architecture.md')
-rw-r--r--docs/explanation/architecture.md71
1 files changed, 70 insertions, 1 deletions
diff --git a/docs/explanation/architecture.md b/docs/explanation/architecture.md
index efa3423..6da2295 100644
--- a/docs/explanation/architecture.md
+++ b/docs/explanation/architecture.md
@@ -239,7 +239,76 @@ pub struct RepositoryAnnouncement { ... }
239pub struct RepositoryState { ... } 239pub struct RepositoryState { ... }
240``` 240```
241 241
242### 5. Configuration ([`src/config.rs`](src/config.rs)) 242### 5. Purgatory System ([`src/purgatory/`](../../src/purgatory/))
243
244The purgatory system solves the "which arrives first?" problem where either nostr events or git pushes can arrive in any order. It provides an in-memory holding area for events and git data awaiting their counterparts.
245
246**Design Document**: See [`purgatory-design.md`](purgatory-design.md) for complete design specifications.
247
248#### Architecture
249
250```rust
251/// Main purgatory structure with two separate stores
252pub struct Purgatory {
253 /// State events (kind 30618) indexed by repository identifier
254 state_events: Arc<DashMap<String, Vec<StatePurgatoryEntry>>>,
255
256 /// PR events (kind 1617/1618) or placeholders indexed by event ID
257 pr_events: Arc<DashMap<String, PrPurgatoryEntry>>,
258}
259```
260
261**Key Design Principles:**
262
2631. **Separate Storage**: State events and PR events use different indexing strategies
264 - State events: Indexed by `identifier` (multiple events can wait for same repo)
265 - PR events: Indexed by `event_id` (one-to-one mapping)
266
2672. **Late Binding**: State event refs are extracted at git push time, not event arrival
268 - Enables flexible matching when pushes arrive out-of-order
269 - Helper functions in [`helpers.rs`](../../src/purgatory/helpers.rs) handle ref extraction
270
2713. **Bidirectional Waiting**: Either side can arrive first
272 - **Event-first**: Event waits for git push
273 - **Git-first**: Placeholder created, waits for event
274
2754. **Automatic Expiry**: 30-minute default expiry, extensible during processing
276 - Background cleanup task runs every 60 seconds
277 - Removes expired entries from both stores
278
279#### Data Types
280
281See [`types.rs`](../../src/purgatory/types.rs) for complete definitions:
282
283- **[`RefPair`](../../src/purgatory/types.rs:16)**: Ref name + object SHA pair
284- **[`StatePurgatoryEntry`](../../src/purgatory/types.rs:29)**: State event with metadata
285- **[`PrPurgatoryEntry`](../../src/purgatory/types.rs:52)**: PR event or placeholder with metadata
286
287#### Integration Points
288
289**Write Policy** ([`src/nostr/policy/`](../../src/nostr/policy/)):
290- State policy checks git data existence before adding to purgatory
291- PR policy checks for placeholders before adding to purgatory
292- Events return "purgatory: will not be served until git data arrives" message
293
294**Git Handlers** ([`src/git/handlers.rs`](../../src/git/handlers.rs)):
295- On git push: Check purgatory for matching state events
296- On refs/nostr/* push: Check purgatory for PR events or create placeholders
297- Release events from purgatory when git data arrives
298- Save released events to database
299
300**Main.rs** ([`src/main.rs`](../../src/main.rs)):
301- Creates `Arc<Purgatory>` at startup
302- Passes to both write policy and git handlers
303- Spawns background cleanup task (60-second interval)
304
305#### Thread Safety
306
307- Uses `Arc<DashMap>` for lock-free concurrent access
308- Safe to share between HTTP handlers, WebSocket handlers, and background tasks
309- No blocking locks in hot paths
310
311### 6. Configuration ([`src/config.rs`](src/config.rs))
243 312
244```rust 313```rust
245pub struct Config { 314pub struct Config {