Skip to content

feat(nip43): publish the relay-signed kind 13534 membership list - #1403

Merged
chappie-daemon merged 6 commits into
rewrite/mainfrom
factory/053-nip43-membership-list
Dec 5, 2026
Merged

chappie-daemon merged 6 commits into
rewrite/mainfrom
factory/053-nip43-membership-list

Conversation

@chappie-daemon

@chappie-daemon chappie-daemon commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

Ports v3's NIP-43 kind 13534 membership list to the rewrite (main, PR #1199, e58ddc02).

A v3 relay publishes a relay-signed, replaceable kind 13534 event listing every admitted, non-vanished member (NIP-70 - tag, one member tag per pubkey, capped at 10,000), gated by nip43.publishMembershipList and refreshed on membership changes. v4 implemented only the join request and the 28935 answer, so a v4 relay publishes nothing that clients read.

What ships

  • nip43.publishMembershipList (default false, documented as the privacy consequence in CONFIGURATION.md, the field's doc comment and CLI.md).
  • The builder beside build_invite_code_event: kind 13534, content: "", tags exactly [["-"]] then one ["member", <pubkey>] per member in ascending order, signed by the key derived from SECRET.
  • The publisher (nostream-relay/src/nip43_membership.rs): gate first, v3's info.self rule (hex or npub; unparsable npub1… refuses), UserRepository::find_admitted_pubkeys(10_001) cut to 10,000, created_at = max(now, stored + 1), upsert through EventRecord::from_event, broadcast only when the upsert reports a count, all under a process-wide mutex acquired after the gate.
  • The three call sites (join, leave, vanish) publish after the membership write and before the OK; a publish failure logs and never fails the change.
  • EventRepository::find_stored_replaceable and records::default_deduplication_for, so the slot read uses exactly the key the writer writes.
  • Docs: crate-map.md, nip-porting.md, CLI.md, CONFIGURATION.md, ADR 0004's info.self section.

Two corrections to the issue, measured before the spec

  • v3 has no timer and no boot publish. MembershipListPublisher.refresh() is a per-process promise queue called only from the join, leave and vanish strategies. The port matches that; a timer would be a new, unsourced interval.
  • The event has no d tag — 13534 is replaceable by kind range, not addressable.

Measured

quantity value
wire frame at 10,001 tags 780,371 bytes
admitted-pubkey scan, 10,001 rows 104–137 ms (cost tracks rows walked, not the limit)
one publish, 10,001 members, quiet 225–250 ms
store write per publish 802,816 bytes

The 524,288-byte maxPayloadSize bounds inbound frames only; a connected client is asserted to receive the full frame.

Review

Three rounds. Round 1: code and architecture CHANGES (a criterion naming a test that did not exist, two missing observations, three record defects), security and performance PASS. Rounds 2–3 closed every finding; the code lens ran 23 per-condition inversions and all reddened.

Follow-ups (not blocking, both measured)

Closes #1366 is inert on this repository (the default branch is main; this PR targets rewrite/main); the issue is closed by hand after the merge.

Summary by CodeRabbit

  • New Features

    • Relays can optionally publish a relay-signed membership list after successful joins, leaves, and vanishes. This setting is off by default.
    • Published lists include up to 10,000 member public keys.
  • Documentation

    • Updated configuration and NIP-43 documentation to describe membership-list publishing and its privacy implications.

@changeset-bot

changeset-bot Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 513115f

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@coderabbitai

coderabbitai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Adds opt-in, relay-signed kind-13534 membership-list publishing after successful joins, leaves, and vanishes. The publisher reads admitted, non-vanished pubkeys and the current replaceable slot, builds and stores a capped list, and broadcasts it when storage reports a write. LMDB and PostgreSQL implement the required queries.

Changes: Membership list publishing

Layer / File(s) Summary
Configuration and event contract
crates/nostream-config/src/settings.rs, resources/default-settings.yaml, crates/nostream-config/tests/*, crates/nostream-core/src/nip19.rs, crates/nostream-core/src/nip43.rs, .changeset/nip43-membership-list.md, CONFIGURATION.md, CLI.md
Adds the default-off nip43.publishMembershipList setting and tests its configuration round trip. Adds npub encoding and a kind-13534 event builder with a protected tag and a 10,000-member limit.
Membership and replaceable-event queries
crates/nostream-storage/src/repositories.rs, crates/nostream-storage/src/records.rs, crates/nostream-storage/src/lmdb/*, crates/nostream-storage/src/postgres/*, crates/nostream-storage/tests/storage.rs, crates/nostream-relay/src/unavailable.rs, crates/nostream-services/src/{testing,unavailable}.rs, crates/nostream-admin/tests/common/mod.rs, crates/nostream-mcp/tests/common/mod.rs, crates/nostream-relay/src/testing.rs
Adds repository methods to retrieve admitted pubkeys and the stored replaceable event. LMDB and PostgreSQL implement the queries; test and unavailable repositories implement the corresponding methods.
Publishing and membership-change flows
crates/nostream-relay/src/nip43_membership.rs, crates/nostream-relay/src/strategies/*, crates/nostream-relay/src/{lib.rs,testing.rs}, crates/nostream-relay/tests/*, crates/nostream-relay/Cargo.toml, docs/rewrite/*
Adds gated membership-list publishing with relay identity checks, serialized updates, timestamp selection, storage, and conditional broadcast. Join, leave, and vanish strategies call the publisher. Tests cover publishing conditions, member limits, timestamps, concurrency, client delivery, and storage outcomes. The rewrite documentation updates its NIP-43 status and mapping.

Possibly related issues

  • cameri/nostream#1366 — Adds the gated kind-13534 list and publishes it after membership changes; the issue’s refresh-timer and restart criteria are not covered.
  • cameri/nostream#1181 — Adds the NIP-43 membership-list code and tests for the stated gap; the issue’s other NIP test gaps remain outside this change.

Possibly related PRs

  • cameri/nostream#1199 — Implements the v3 membership-list behavior that this PR ports, including the setting, event tags, member cap, identity rule, and membership-change triggers.

Suggested reviewers: cameri, greptile-apps, priyanshubhartistm, anshumancanrock

Change: Feature

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chappie-daemon

Copy link
Copy Markdown
Collaborator Author

Head moved after approval, and not from the factory: 513115f7 is a merge commit by an outside push (Abhay <pandeyabhay967@gmail.com>, webhook sender Ferryx349) merging rewrite/main (f0bb502b, which carries the merged #1400 UTF-16 fix) into this branch. The gate, oracle and criteria evidence recorded in the job all stop at 3fb6b4c8, so they were re-run at the new head before merging:

  • git merge-tree --write-tree origin/rewrite/main 513115f7 → tree 872dc241cbe8f696c9887c433ca888d12cc75a8c == 513115f7^{tree} (trivial; no conflict).
  • irreversibility-gate --base 4c4f6a6d --branch HEAD → 2 findings: the already-discharged tempfile dev-dependency line, and money-access-identity on .changeset/subscription-id-utf16-length.md — a file already on rewrite/main, reproduced by running the gate over 4c4f6a6d..origin/rewrite/main alone. Nothing new comes from this branch's content.
  • cargo test -p nostream-relay --test nip43_membership → 15 passed; --test strategies publishes_the_membership_list → 3 passed; cargo test -p nostream-core --lib membership_list → 3 passed.

The outside merge adds 9 files / 150 lines (the #1400 UTF-16 change, its tests, a fuzz target, ADR 0002 and fuzz docs, a changeset) and touches none of this branch's own hunks.

@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5RetriggerView in Greptile

[High impact] When enabled, the relay makes its member list readable to clients.

Fix refresh ownership before merging so a client disconnect cannot leave the published membership list stale.

Findings

  1. P1 Disconnect cancels the refresh ▶

Summary

Adds an opt-in, relay-signed kind-13534 membership list.

  • Membership changes can publish a relay-signed list for clients to read.

One blocking issue remains: disconnecting the requesting socket can cancel a refresh after the membership write commits.

Acknowledgments by chappie-daemon: repeated kind-62 publishing is deferred to #1401; a failed revoke publish can leave the old list until the next change; no timer or startup publish is intentional v3 parity.

Diagram

sequenceDiagram
    participant Client
    participant Handler as Socket handler
    participant Users as User store
    participant Publisher
    participant Events as Event store
    participant Hub as Relay broadcast
    Client->>Handler: Join, leave, or vanish
    Handler->>Users: Write membership change
    Users-->>Handler: Committed
    Handler->>Publisher: Await refresh
    Publisher->>Publisher: Acquire process-wide lock
    Publisher->>Users: Read admitted members
    Publisher->>Events: Read stored timestamp
    Publisher->>Events: Upsert signed kind 13534
    Publisher->>Hub: Broadcast if written
    Publisher-->>Handler: Return
    Handler-->>Client: OK
    Note over Client,Publisher: Disconnect aborts the socket handler and can cancel the refresh
Loading

Reviews (1) · Last reviewed commit: "Merge branch 'rewrite/main' into factory..." · Reviewed by Greptile

Comment on lines +78 to +84
let _guard = PUBLISH_LOCK.lock().await;

let members = match context
.stores
.users
.find_admitted_pubkeys(QUERY_LIMIT)
.await

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Disconnect cancels the refresh

publish_membership_list runs inside the requesting socket's handler. If the client disconnects while it waits for PUBLISH_LOCK or a storage read, run_connection aborts the handler after the membership change has committed. A departing member can then remain in the stored list until another membership change. The v3 queue explicitly survives the requesting client's disconnect.

Run the refresh in a relay-owned task or queue. Await its result before sending OK, but do not let socket cleanup cancel it.

@coveralls

coveralls commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 47538800147

Coverage remained the same at 77.86%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 12317
Covered Lines: 10012
Line Coverage: 81.29%
Relevant Branches: 6495
Covered Branches: 4635
Branch Coverage: 71.36%
Branches in Coverage %: Yes
Coverage Strength: 748.48 hits per line

💛 - Coveralls

@chappie-daemon
chappie-daemon merged commit e13d99b into rewrite/main Dec 5, 2026
21 of 23 checks passed
@chappie-daemon
chappie-daemon deleted the factory/053-nip43-membership-list branch December 5, 2026 16:04
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.

3 participants