Skip to content

Add NIP-77 (Negentropy) sync support - #144

Merged
mattn merged 1 commit into
fiatjaf:masterfrom
mattn:add-nip77
Sep 10, 2026
Merged

mattn merged 1 commit into
fiatjaf:masterfrom
mattn:add-nip77

Conversation

@mattn

@mattn mattn commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

Implements server-side handling for NEG-OPEN, NEG-MSG, and NEG-CLOSE so clients can reconcile event sets with the relay without redownloading events they already have. Each session keeps per-subscription negentropy state on the WebSocket, snapshots events matching the filter into a sealed vector storage, and drives Reconcile per incoming frame. Access is gated by the same validateFilterAccess and ReqAccepter checks as REQ, so NIP-42 and NIP-59 restrictions still apply. NIP-77 is also advertised in the default NIP-11 document.

Implement server-side handling for NEG-OPEN, NEG-MSG and NEG-CLOSE so
clients can reconcile event sets with the relay without redownloading
events they already have. Each session keeps per-subscription negentropy
state on the WebSocket, snapshots events matching the filter into a
sealed vector storage, and drives Reconcile per incoming frame. Access
is gated by the same validateFilterAccess and ReqAccepter checks as REQ,
so NIP-42 and NIP-59 restrictions still apply.

NEG-* frames are dispatched in receive order rather than on worker
goroutines. Negentropy is lock-step and Reconcile carries state between
frames, so a worker could apply a NEG-CLOSE before the NEG-OPEN it
followed; the close then found no session to remove and the one the open
went on to create was never freed.

The error envelope is written by hand as NEG-ERR. go-nostr's
nip77.ErrorEnvelope marshals the label as NEG-ERROR, which the spec does
not define; its parser matches on the NEG-ERR prefix, so clients built on
go-nostr still decode ours. Reasons use the NIP-01 "word: message" form.

A NEG-OPEN for a subscription id that is already open closes the existing
session first, on the error paths too.

Advertise NIP-77 in the default NIP-11 document.
@mattn
mattn merged commit d49d84b into fiatjaf:master Sep 10, 2026
1 check 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.

1 participant