mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 16:14:40 +00:00
A NIP-77 server session rebuilt its reconciliation structure from scratch on every NEG-OPEN: full id+created_at scan, per-entry hex decode into a fresh StorageVector, O(n log n) seal. That cost grows with the corpus and is paid even when nothing changed — the exact shape of a periodic mirror's heartbeat, where N peers reconcile the same broad filter over and over. relayBench measured 342 ms per identical-set reconcile at 50k events vs strfry's 26 ms off its always-current LMDB tree. Reconciliation only *reads* the sealed storage, so one instance can back any number of concurrent sessions: - NegentropyServerSession now accepts a pre-sealed IStorage (the List<IdAndTime> constructor remains and delegates). - SessionBackend.sealedNegentropyStorage() builds + seals (null when the set exceeds maxSyncEvents); LiveEventStore overrides it with a single-slot cache keyed by (filter set, write generation) plus a 30s TTL. The generation bumps on every accepted ingest; the TTL bounds staleness from delete paths the counter can't see (expiration sweeps, admin purges) — negentropy snapshots are point-in-time sets, so seconds of staleness only means a peer briefly re-offers ids. - NegSessionRegistry.open consumes the shared sealed storage; over-cap NEG-ERR behavior unchanged (strfry parity). relayBench gains a 'heartbeat' measurement — the identical-set reconcile repeated immediately with no writes in between. At 50k events: geode 342 ms -> 27.8 ms vs strfry 21.1 ms (near parity; was 13x). Cold reconciles (first open after a write) are unchanged. Also fixes the GeodeVsStrfryNegentropySyncTest fixture to write 'nofiles = 0' so the opt-in interop test can boot strfry inside containers with a low RLIMIT_NOFILE hard cap; the interop suite passes against strfry v1-b80cda3 with the cache in place. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NeoCvXnTxsKzqurkmjdC46