Repository navigation
Description
Parent: builds on cameri/nostream #931 (phase 1, configured trust).
Design: 2026-11-15, sim-verified the same day (~/workspace/nostream-peering-sim/sim.py — discovery 100 seeds; economics + H1/H2/H3, 10 seeds each).
Boundary: phase 1 is frozen
Phase 1 (#931 and sub-issues #932–#940) is configured trust — operators who
already know each other. It is not changed by this issue. Nothing here
re-scopes, re-prioritises, or adds requirements to any phase-1 ticket, so
the engineer on phase 1 sees no shifting ground. Phase 2 is a separate
container for work that starts after phase 1 lands.
Motivation
Phase 1 lets two relays peer once their operators know each other. It does
not help a freshly spun-up relay find peering relays, or know which ones
are worth peering with. Discovery is the adoption bottleneck, and growth
is the second one: a new relay with one user cannot bootstrap (it dies
broke in 10/10 sim seeds), and the network concentrates (top relay holds
median 54% of users). Phase 2 is discovery plus growth, for relays that
don't know each other yet.
Proposal
1. Discovery via signed announcements (new — no phase-1 ticket covers it)
Relays discover each other through signed announcements carried by
ordinary public relays — no dedicated bootstrap relay, no direct
connection needed first. Public relays are dumb carriers; trust comes
from signatures and verification, not from the carrier.
- A signed, parameterized-replaceable event (kind 30111 placeholder).
dtag is the relay's own pubkey — one announcement per relay identity.
Carries: relay URL, role (archive/backbone/cache/edge),
optionally the owner attestation from Peering: owner-attested peering requests — the operator co-signs, staking their reputation #940. - Terms are not inline. The announcement points at NIP-11; the
relay's NIP-11 document is the source of truth for peering terms. The
announcement is a claim; the NIP-11 fetch is the check. - Routing: NIP-65
rtags inside the announcement (write= outbox,
read= inbox, no marker = both; 2–4 relays per category). A
discoverer who sees the announcement anywhere now knows where to find
this relay's future announcements. Transitive via outbox subscriptions. - Expiry and renewal: NIP-40
expiration, 1 day out. Staying
discoverable requires a fresh NIP-13 PoW every day. The relay starts
mining the next announcement in advance of expiry (lead time from its
own measured hashrate, safety factor ~3× expected mining time). Each
mining attempt re-stampscreated_at; publish the moment the PoW
lands. No commit-then-hold. - Verification (two layers): signature (claimant's identity is known),
then NIP-11 fetch (confirm it actually advertises peering with
matching terms). A fake announcement pointing at a dead or
non-peering relay dies on this cheap, cacheable HTTPS fetch. - Gossip: peers exchange announcement sets, so a relay joining with no
public relays learns the mesh from one peer, and is itself discovered
by the mesh.
2. Suggestions panel — rank discovery candidates (extends #939)
#939 as written covers visibility for peers you already have. Phase 2
adds suggesting peers you don't have yet: each candidate, why it's
suggested, estimated cost at advertised flat terms, estimated benefit
(events/day fetchable, share of users' follows covered). One click sends
the owner-attested request with PoW at the receiver's minimum.
Ranking signals (overlap first): overlap — what fraction of the relay's
users' follows publish to relay X; role; terms; health (NIP-66 probes);
trust (owner attestation from #940).
3. Attestation in announcements (uses #940)
Owner attestation is an optional announcement field and a ranking
signal. Consistent with #940 (owner co-signs the peering request); the
announcement carrying attestation is a new surface, not a change to
#940.
4. Growth package — referral + cheap feeds + size grace (sim-validated)
From the economics sim (H1, validated): a relay above the mean user
count refers each newly arriving user to its least-loaded peer; cheap
feeds (price 20→10) + size-tied grace (operating-cost holiday while a
relay has ≤2 users) let the small relay serve the referred user so they
stay. Package result: alignment 0.92, user-gini 0.08, new relays grow
D 1→6, E 1→5, F 1→5, no deaths, volume ~4,155. Referral alone is
disproved (alignment 0.28, new relays end at 0 users). Fee 3 is the
best compromise under linear costs (referrer at 1195 vs 700 at fee 0,
vs 1525 whole at fee 5); fee 5 breaks spread (0.69).
Open before this is complete: the production mechanism for "cheap
feeds" (PRICE is set by sellers — this means tiered/discounted terms
for small buyers or a first-feed-free rule, not a constant); whether
real relay operating costs are actually superlinear (H3: if so, the fee
can drop to 0 — needs real operating data, the sim cannot answer it).
5. Cost estimates (depends on #937/#938)
The suggestions panel's cost estimates are fiction until settlement
lands. Discovery can suggest, but cannot settle. Discovery comes
first, not after — you can't settle with someone you haven't found —
but the money column stays estimated until #937/#938 land.
Out of scope
- Per-event payments of any kind — same rule as phase 1. Terms are flat
(per period), never per event. - Any change to a phase-1 ticket (Peering: advertise peering terms and scopes in the NIP-11 document #932–Peering: owner-attested peering requests — the operator co-signs, staking their reputation #940). Phase 1 is frozen.
- The NIP itself — that comes after at least two independent operators
are peering with this implementation (same bar as phase 1). - Price competition as a growth lever (H2, disproved): small relays
undercutting to 5 lose users, they don't gain them — a feed serving 1
user is worth 5 but costs 10, so coverage collapses and users leave
despite the price advantage.
Dependencies (phase-1 legs this waits on)
- Peering: Lightning invoices for paid peering — issue, settle, renew, lapse #937/Peering: auto-pay peer invoices within periodic budgets, with held-invoice approval #938 (settlement) — for the cost estimates in the suggestions
panel. In progress (paid-peering branches, PR feat(peering): renew, lapse and expose paid peering access #1089). - Peering: admin console visibility for peers, feeds, spend and held invoices #939 (admin console) — the suggestions panel surface. Outstanding.
- Peering: owner-attested peering requests — the operator co-signs, staking their reputation #940 (owner attestation) — the attestation signal. Outstanding.
- Peering: advertise peering terms and scopes in the NIP-11 document #932 (NIP-11 ads) and Peering: authenticate peer relays with NIP-42 using the relay's own keypair #933 (NIP-42 identity) — already landed;
phase 2 builds on them.
Open design decisions (need a call before implementation)
- Ranking gate: whether overlap may override missing attestation. The
sim shows the attestation gate stops a popular sybil extracting
payment but not gaining users — the gate stops money, not users. - Cheap-feeds mechanism (see §4).
- Whether real operating costs are superlinear (decides fee 0 vs fee 3).
Verification: discrete-event simulation (done, before implementation)
Same sim as the discovery draft (sim.py, stdlib only, virtual clock).
Discovery: 100 seeds, all passing — discovery median ~0.35 s, gossip
discovery ~29.5 s, observed lapses in ~30% of runs but <1.1 s at
SAFETY=5, zero fakes accepted, verification multiplicity ~10× overall /
~27× accepted per published. Economics: settlement works (fraud always
held, budgets never breached, killing the biggest relay does not kill
the network); H1 package validated (alignment 0.92); H2 disproved;
H3 validated narrowly and fragilely. Thesis verdict: inconclusive —
core mechanism supported, not proven; scale, real graphs, adaptive
adversaries, real implementation, real costs all untested.
Acceptance criteria
- A fresh relay with no prior knowledge of any peer discovers peering
relays through public relays alone. - A relay joining with no public relays learns the mesh through gossip
from one peer, and is itself discovered by the mesh. - Forged and dead-end announcements are rejected by verification; a
real-but-malicious relay is never peered on ranking alone. - A relay renewing daily announcements is never undiscoverable for
longer than the agreed tolerance: observed coverage lapse ≤ 5 s after
first sighting, and discovery within the latency bounds (sim;
production tolerance TBD). - Suggestions in the console rank by overlap first, with role, terms,
health, and attestation visible as the reason. - A new relay with one user can bootstrap (survives with its user) and
grow under the referral + cheap + grace package; the network does not
concentrate into a single hub.
Suggested order of work (easy part first)
- Local half, zero protocol work: crawl NIP-11, compute overlap
from the relay's own data, show suggestions in the console (Peering: admin console visibility for peers, feeds, spend and held invoices #939).
Proves the value before any announcement kind exists. - Announcement kind + subscribe–verify–rank loop in the relay
and console. - Gossip of announcement sets between peers (public relays only
needed for the first connection). - Settlement legs Peering: Lightning invoices for paid peering — issue, settle, renew, lapse #937/Peering: auto-pay peer invoices within periodic budgets, with held-invoice approval #938 make the cost estimates real; growth
package (referral + cheap + grace) once the cheap-feeds mechanism
is decided. - Formal model later, only for the invariants that earn it: TLA+ is
the lighter option for the state machine; Lean for full proofs of
e.g. "auto-pay never exceeds budget".
Activity
cameri commentedon Nov 19, 2026
Ranking gate: hard gate (sim-verified)
This settles the open question in the ranking section above — whether overlap should be able to override a missing attestation. No: use a hard attestation gate. Overlap must not override missing attestation.
Sim results (10 seeds each, alignment package: referral + cheap feeds + size grace, fee 3, popular sybil with 10 users):
Why the gate works better than the settlement gate: it stops money and users. An unattested relay never enters honest relays' peer sets, so honest users can't migrate to it (migration candidates are home's peers only) — sybil users stay frozen at 10, vs 10→13 under the settlement gate.
Why the override fails: at 0.4 it's worse than doing nothing (admits the sybil to all 6 honest relays, bypassing the weighted score that was marginally keeping A and B out). At 0.6 it's a lottery — the sybil's decision-time overlap varies 0.00–0.80 by receiver, so no threshold cleanly excludes it.
Second finding: the alignment package itself collapses against a popular sybil without the gate. The 0.92 alignment was measured with a 2-user sybil; with 10 users under weighted ranking it falls to 0.27, honest relays die, and one survivor holds 92% of users. The gate is what makes the package hold.
Honest limit: the sim has no legit unattested relay, so the override's good side — letting a real new relay in before attestation — is untested. That needs a different mechanism (provisional/cache-only tier, or operator approval), not an overlap threshold.
Design decision: hard attestation gate on peering (unattested relays stay visible as suggestions only, never auto-peer).