-
Notifications
You must be signed in to change notification settings - Fork 297
Add native NIP-77 negentropy sync for efficient timeline updates #3444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alltheseas
wants to merge
5
commits into
damus-io:master
Choose a base branch
from
alltheseas:nip77-negentropy-native
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native negentropy set reconciliation for NostrDB, implementing the NIP-77 protocol for efficient event synchronization with relays. Features: - MSB-first varint encoding/decoding - Range encoding/decoding (SKIP, FINGERPRINT, IDLIST, IDLIST_RESPONSE) - Storage management with sorted (timestamp, id) pairs - Reconciliation state machine with have/need ID tracking - Support for relay.damus.io (MAX_RANGES=8192 for large messages) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
Swift implementation of NIP-77 set reconciliation for efficient event synchronization with relays. Components: - NdbNegentropy.swift: Swift bindings for ndb_negentropy C API - NegentropySync.swift: Sync coordinator with NIP-11 detection - NostrResponse: NEG-MSG, NEG-ERR, CLOSED message parsing - RelayConnection/Pool: Negentropy message handling Configuration tuned for relay.damus.io: - 1MB response buffer (responses can exceed 590KB) - splitCount=4 for smaller response sizes - frameSizeLimit=32KB 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
14 tests covering: - Storage initialization, sealing, item addition - Reconciliation context setup - Initial message generation (protocol version 0x61) - Invalid message handling - Memory management (storage deallocation, reference counting) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
Improvements to negentropy sync performance and reliability: Startup optimization: - Cache relay NIP-77 support status to avoid NIP-11 checks on every startup - Sync known-supported relays immediately, check unknown relays in background - Add settling delay (1.5s) before sync to let connections stabilize Timeout handling: - Two-phase timeout: 10s for first response, 30s inactivity between messages - Per-relay sync tracking instead of global lock (allows concurrent syncs) - Add debug logging for reconciliation failures Reliability fixes: - Detect "negentropy disabled" NOTICE and mark relay unsupported immediately - Fix NOTICE parsing to capture message text - Fix duplicate sync race condition - Only trigger sync on reconnect (initial connects use background NIP-11 check) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas Closes: damus-io#3269
Collaborator
Author
3 tasks
9 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
pr-in-queue
This PR is waiting in a queue behind their other PRs marked with the label `pr-active-review`.
technical
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Summary
Implements NIP-77 negentropy set reconciliation for efficient timeline sync. Instead of re-fetching thousands of events on app foreground, negentropy efficiently identifies only the events we're missing by comparing fingerprints of our local event set against the relay's set.
Key features:
Performance: Reduces network traffic from 5000+ events to ~50-200 missing events on typical foreground sync.
Checklist
Standard PR Checklist
Closes:orFixes:tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patchesTest report
Device: iPhone 16 Pro Simulator
iOS: 18.3.1
Damus: f7d3c8c
Setup: Account with ~50,000 events in local nostrdb, connected to relay.damus.io and pyramid.fiatjaf.com
Steps:
Results:
Other notes
Closes: #3269
Builds off damus-io/nostrdb#103
🤖 Generated with Claude Code