Skip to content

feat(nip77): add negentropy reconciliation core - #809

Merged
Priyanshubhartistm merged 5 commits into
cameri:mainfrom
Priyanshubhartistm:feat/nip77-negentropy-core
Oct 11, 2026
Merged

Priyanshubhartistm merged 5 commits into
cameri:mainfrom
Priyanshubhartistm:feat/nip77-negentropy-core

Conversation

@Priyanshubhartistm

Copy link
Copy Markdown
Collaborator

Description

Adds the protocol-independent core of NIP-77 (Negentropy) set reconciliation for the PostgreSQL backend:

  • src/utils/negentropy.ts: a TypeScript port of the reference implementation (hoytech/negentropy, MIT) producing the same wire format. It is synchronous and bounds-checks all input read from the network (varint length, id list sizes, bound lengths).
  • EventRepository.findReconciliationItems(filter): returns (created_at, id) for matching events, oldest first. It reuses the shared filter conditions (so NIP-56 hidden events are excluded), additionally skips deleted and expired events, and ignores the filter's limit since reconciliation needs the whole set.
  • src/utils/negentropy.ts is added to the check:deps ignore list until the wire protocol PR imports it.

No wire protocol, settings or NIP-11 changes yet; those follow in separate PRs.

Related Issue

Closes #801

Motivation and Context

Clients and relay-to-relay syncers currently catch up with wide REQ filters and receive every matching event. NIP-77 lets both sides exchange fingerprints and transfer only the difference.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0c7b0a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coveralls

coveralls commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 73.905% (+0.7%) from 73.244% — Priyanshubhartistm:feat/nip77-negentropy-core into cameri:main

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] No new blocking issue was found in the changes since the previous review.

Summary

Adds the NIP-77 reconciliation core and a query for matching event IDs.

  • Negentropy compares event sets and reports the IDs each peer is missing.
  • Reconciliation queries return every matching live event in oldest-first order.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Matching live events] --> B[Sorted timestamp and ID pairs]
  B --> C[Sealed reconciliation storage]
  C --> D[Exchange fingerprints]
  D --> E{Ranges match?}
  E -->|Yes| F[Skip matching range]
  E -->|No| G[Split range or exchange IDs]
  G --> H[Report missing IDs]
Loading

Reviews (2) · Last reviewed commit: "fix(nip77): address review findings in n..." · Reviewed by Greptile

Comment thread src/utils/negentropy.ts
Comment thread src/utils/negentropy.ts Outdated
Comment thread src/utils/negentropy.ts
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@Priyanshubhartistm
Priyanshubhartistm merged commit 4cf419f into cameri:main Oct 11, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(nip77): negentropy reconciliation core for the PostgreSQL backend

3 participants