@optimystic/db-core 1.8.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/src/cohort-topic/addressing.d.ts +46 -6
  2. package/dist/src/cohort-topic/addressing.d.ts.map +1 -1
  3. package/dist/src/cohort-topic/addressing.js +58 -18
  4. package/dist/src/cohort-topic/addressing.js.map +1 -1
  5. package/dist/src/cohort-topic/member-engine.d.ts +21 -1
  6. package/dist/src/cohort-topic/member-engine.d.ts.map +1 -1
  7. package/dist/src/cohort-topic/member-engine.js +39 -9
  8. package/dist/src/cohort-topic/member-engine.js.map +1 -1
  9. package/dist/src/cohort-topic/membership/publisher.js +1 -1
  10. package/dist/src/cohort-topic/membership/publisher.js.map +1 -1
  11. package/dist/src/cohort-topic/membership/source.d.ts +4 -0
  12. package/dist/src/cohort-topic/membership/source.d.ts.map +1 -1
  13. package/dist/src/cohort-topic/membership/source.js +4 -0
  14. package/dist/src/cohort-topic/membership/source.js.map +1 -1
  15. package/dist/src/cohort-topic/membership/verifier.d.ts +51 -9
  16. package/dist/src/cohort-topic/membership/verifier.d.ts.map +1 -1
  17. package/dist/src/cohort-topic/membership/verifier.js +138 -46
  18. package/dist/src/cohort-topic/membership/verifier.js.map +1 -1
  19. package/dist/src/cohort-topic/ports.d.ts +85 -14
  20. package/dist/src/cohort-topic/ports.d.ts.map +1 -1
  21. package/dist/src/cohort-topic/ports.js +1 -1
  22. package/dist/src/cohort-topic/ports.js.map +1 -1
  23. package/dist/src/cohort-topic/registration/renewal.d.ts +26 -5
  24. package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -1
  25. package/dist/src/cohort-topic/registration/renewal.js +71 -21
  26. package/dist/src/cohort-topic/registration/renewal.js.map +1 -1
  27. package/dist/src/cohort-topic/service.d.ts +34 -2
  28. package/dist/src/cohort-topic/service.d.ts.map +1 -1
  29. package/dist/src/cohort-topic/service.js +86 -28
  30. package/dist/src/cohort-topic/service.js.map +1 -1
  31. package/dist/src/cohort-topic/sig/payloads.d.ts +5 -1
  32. package/dist/src/cohort-topic/sig/payloads.d.ts.map +1 -1
  33. package/dist/src/cohort-topic/sig/payloads.js +6 -1
  34. package/dist/src/cohort-topic/sig/payloads.js.map +1 -1
  35. package/dist/src/cohort-topic/sig/threshold.d.ts +29 -4
  36. package/dist/src/cohort-topic/sig/threshold.d.ts.map +1 -1
  37. package/dist/src/cohort-topic/sig/threshold.js +39 -7
  38. package/dist/src/cohort-topic/sig/threshold.js.map +1 -1
  39. package/dist/src/cohort-topic/walk.d.ts +19 -4
  40. package/dist/src/cohort-topic/walk.d.ts.map +1 -1
  41. package/dist/src/cohort-topic/walk.js +29 -6
  42. package/dist/src/cohort-topic/walk.js.map +1 -1
  43. package/dist/src/cohort-topic/willingness.d.ts +17 -1
  44. package/dist/src/cohort-topic/willingness.d.ts.map +1 -1
  45. package/dist/src/cohort-topic/willingness.js +18 -3
  46. package/dist/src/cohort-topic/willingness.js.map +1 -1
  47. package/dist/src/cohort-topic/wire/index.d.ts +1 -1
  48. package/dist/src/cohort-topic/wire/index.d.ts.map +1 -1
  49. package/dist/src/cohort-topic/wire/index.js +1 -1
  50. package/dist/src/cohort-topic/wire/index.js.map +1 -1
  51. package/dist/src/cohort-topic/wire/payloads.d.ts +14 -0
  52. package/dist/src/cohort-topic/wire/payloads.d.ts.map +1 -1
  53. package/dist/src/cohort-topic/wire/payloads.js +20 -0
  54. package/dist/src/cohort-topic/wire/payloads.js.map +1 -1
  55. package/dist/src/cohort-topic/wire/primitives.d.ts +8 -0
  56. package/dist/src/cohort-topic/wire/primitives.d.ts.map +1 -1
  57. package/dist/src/cohort-topic/wire/primitives.js +24 -4
  58. package/dist/src/cohort-topic/wire/primitives.js.map +1 -1
  59. package/dist/src/cohort-topic/wire/types.d.ts +37 -0
  60. package/dist/src/cohort-topic/wire/types.d.ts.map +1 -1
  61. package/dist/src/cohort-topic/wire/validate.d.ts +9 -1
  62. package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -1
  63. package/dist/src/cohort-topic/wire/validate.js +23 -4
  64. package/dist/src/cohort-topic/wire/validate.js.map +1 -1
  65. package/dist/src/collection/collection.d.ts +17 -0
  66. package/dist/src/collection/collection.d.ts.map +1 -1
  67. package/dist/src/collection/collection.js +19 -0
  68. package/dist/src/collection/collection.js.map +1 -1
  69. package/dist/src/reactivity/config.d.ts +9 -5
  70. package/dist/src/reactivity/config.d.ts.map +1 -1
  71. package/dist/src/reactivity/config.js +9 -4
  72. package/dist/src/reactivity/config.js.map +1 -1
  73. package/dist/src/reactivity/index.d.ts +4 -3
  74. package/dist/src/reactivity/index.d.ts.map +1 -1
  75. package/dist/src/reactivity/index.js +4 -3
  76. package/dist/src/reactivity/index.js.map +1 -1
  77. package/dist/src/reactivity/notification.d.ts +7 -0
  78. package/dist/src/reactivity/notification.d.ts.map +1 -1
  79. package/dist/src/reactivity/notification.js +1 -1
  80. package/dist/src/reactivity/notification.js.map +1 -1
  81. package/dist/src/reactivity/rotation.d.ts +73 -57
  82. package/dist/src/reactivity/rotation.d.ts.map +1 -1
  83. package/dist/src/reactivity/rotation.js +54 -54
  84. package/dist/src/reactivity/rotation.js.map +1 -1
  85. package/dist/src/reactivity/subscription.d.ts +12 -9
  86. package/dist/src/reactivity/subscription.d.ts.map +1 -1
  87. package/dist/src/reactivity/subscription.js +9 -6
  88. package/dist/src/reactivity/subscription.js.map +1 -1
  89. package/dist/src/reactivity/topic-anchor.d.ts +36 -31
  90. package/dist/src/reactivity/topic-anchor.d.ts.map +1 -1
  91. package/dist/src/reactivity/topic-anchor.js +41 -39
  92. package/dist/src/reactivity/topic-anchor.js.map +1 -1
  93. package/dist/src/reactivity/verify.d.ts +26 -9
  94. package/dist/src/reactivity/verify.d.ts.map +1 -1
  95. package/dist/src/reactivity/verify.js +26 -11
  96. package/dist/src/reactivity/verify.js.map +1 -1
  97. package/dist/src/reactivity/wire.d.ts +1 -1
  98. package/dist/src/reactivity/wire.d.ts.map +1 -1
  99. package/dist/src/transactor/change-notifier.d.ts +1 -1
  100. package/package.json +5 -5
  101. package/src/cohort-topic/addressing.ts +83 -23
  102. package/src/cohort-topic/member-engine.ts +77 -8
  103. package/src/cohort-topic/membership/publisher.ts +1 -1
  104. package/src/cohort-topic/membership/source.ts +4 -0
  105. package/src/cohort-topic/membership/verifier.ts +169 -51
  106. package/src/cohort-topic/ports.ts +87 -15
  107. package/src/cohort-topic/registration/renewal.ts +87 -24
  108. package/src/cohort-topic/service.ts +157 -35
  109. package/src/cohort-topic/sig/payloads.ts +7 -2
  110. package/src/cohort-topic/sig/threshold.ts +41 -7
  111. package/src/cohort-topic/walk.ts +46 -9
  112. package/src/cohort-topic/willingness.ts +34 -3
  113. package/src/cohort-topic/wire/index.ts +1 -0
  114. package/src/cohort-topic/wire/payloads.ts +21 -0
  115. package/src/cohort-topic/wire/primitives.ts +26 -4
  116. package/src/cohort-topic/wire/types.ts +37 -0
  117. package/src/cohort-topic/wire/validate.ts +26 -3
  118. package/src/collection/collection.ts +20 -0
  119. package/src/reactivity/config.ts +10 -5
  120. package/src/reactivity/index.ts +4 -3
  121. package/src/reactivity/notification.ts +8 -1
  122. package/src/reactivity/rotation.ts +86 -78
  123. package/src/reactivity/subscription.ts +12 -9
  124. package/src/reactivity/topic-anchor.ts +42 -45
  125. package/src/reactivity/verify.ts +36 -17
  126. package/src/reactivity/wire.ts +1 -1
  127. package/src/transactor/change-notifier.ts +1 -1
@@ -5,7 +5,10 @@
5
5
  * a threshold-signed message:
6
6
  *
7
7
  * 1. takes the message's `signers`, the cohort `coord` the signers should belong to, and the tier;
8
- * 2. looks up the cached `MembershipCertV1` for that coord (or pulls the source's `current`);
8
+ * 2. looks up the cached `MembershipCertV1` for that coord (or pulls the source's `current`); a
9
+ * fetched cert is considered only if its own `cohortCoord` names that coord — a cert for any other
10
+ * coord is treated as no cert, since the trust gate and the cache would otherwise be consulted for
11
+ * the coord the cert names rather than the one being verified;
9
12
  * 3. checks the signers are a `≥ minSigs` subset of the cert's members and the signature verifies;
10
13
  * 4. **on failure against a cached/stale cert, re-fetches the cert from any cohort member exactly
11
14
  * once and retries**; still failing → the message is untrusted.
@@ -14,7 +17,8 @@
14
17
  * is a `≥ minSigs` quorum over its own `members`) proves only internal well-formedness — *not* that the
15
18
  * attesting key set is the legitimate cohort for the coord. An adversary controlling `k − x` keys could
16
19
  * mint a self-consistent cert over a coord it does not own. So before a (re)fetched cert is believed,
17
- * {@link CachingMembershipVerifier.certIsTrusted} requires it to be self-consistent **AND** anchored by
20
+ * the gate ({@link CachingMembershipVerifier.directVerdict}, then
21
+ * {@link CachingMembershipVerifier.certIsTrusted}) requires it to be self-consistent **AND** anchored by
18
22
  * at least one of:
19
23
  *
20
24
  * - **Trust root** — `(coord, epoch, member-set)` is in the out-of-band-seeded {@link TrustRoot} set
@@ -33,20 +37,42 @@
33
37
  * behavior, so there is strictly no regression on coords no node can verify today (distant T2/T3, and
34
38
  * T0/T1 until the committed-index binding lands). Once a coord *does* hold a trusted cert, the chain
35
39
  * governs successors: an un-anchored cert for an already-trusted coord is rejected (no TOFU downgrade),
36
- * which is what gives the rotation chain its teeth. The FRET / tx-log direct-anchor bindings that close
37
- * the remaining TOFU gap are tracked in `cohort-topic-trust-anchor-fret-binding` and the backlog
38
- * `...-fret-stabilization-proof` / `...-txlog-committed-binding` tickets.
40
+ * which is what gives the rotation chain its teeth. Two direct-anchor bindings in db-p2p close parts of
41
+ * the gap: `FretTrustAnchor` judges a coord this node serves against its own ring view, and
42
+ * `CommitLogTrustAnchor` judges a reactivity root — a root-placed coord whose placement names its key —
43
+ * against the tail block's commit proof, fetched from the tail's storage group, so a distant subscriber
44
+ * is anchored too. What remains TOFU is a distant coord under neither (other T2/T3 coords a node does
45
+ * not serve, tracked in the backlog `...-fret-stabilization-proof`, and T0/T1 until
46
+ * `...-txlog-committed-binding`).
47
+ *
48
+ * **The gate waits only for the direct verdict.** `directAnchor` may return a promise (the commit-log
49
+ * anchor asks the network), so the gate is in two steps: {@link CachingMembershipVerifier.directVerdict}
50
+ * (self-consistency, trust roots, the direct anchor — nothing that reads per-coord state) is awaited by
51
+ * `loadFrom`, and {@link CachingMembershipVerifier.certIsTrusted} then decides synchronously. Everything
52
+ * that reads or writes the per-coord maps runs after that one `await`, in one synchronous turn with the
53
+ * cache write — see the comment at the `await`.
39
54
  *
40
55
  * **Deviation from the ticket sketch (documented):** `verifyMessage` takes the cohort `tier`. A coord
41
56
  * is an opaque hash, so the T0/T1-vs-T2/T3 source dispatch the same ticket mandates cannot be derived
42
57
  * from the coord alone; the caller already knows the tier (it computed the coord from the message's
43
58
  * claimed tier/topic). The `tier` is threaded into the gate so the direct anchor is consulted with the
44
59
  * same tier the router used (the binding is tier-scoped).
60
+ *
61
+ * **Root-placed coords (§Tier addressing → Root placement at a routing key).** Everything above says
62
+ * "`≥ minSigs`" for the node-wide threshold. The root of a root-placed topic is a different kind of
63
+ * cohort — the group responsible for a routing key, typically smaller than `minSigs` — so a caller that
64
+ * knows the coord is root-placed passes a {@link RootPlacement}, and the verifier then uses
65
+ * `ceil(members × quorumRatio)` of the cert being checked against for **every** threshold it applies at
66
+ * that coord: the cert's self-consistency, the rotation-chain quorum (over the predecessor's members),
67
+ * and the message itself. The ratio is the caller's own configuration, never read off a message or cert.
68
+ * The placement is also handed to the membership source and the direct anchor, which need it to find
69
+ * and judge the root group. A cached cert remembers the rule it was validated under, and a call under a
70
+ * different rule does not see it — see {@link CachingMembershipVerifier.heldUnder}.
45
71
  */
46
72
  import { noAuthorityTrustAnchor } from "../ports.js";
47
73
  import { b64urlToBytes, bytesToB64url, decodeMembershipCertV1 } from "../wire/codec.js";
48
74
  import { CohortWireError } from "../wire/validate.js";
49
- import { DEFAULT_MIN_SIGS } from "../sig/threshold.js";
75
+ import { DEFAULT_MIN_SIGS, rootPlacedMinSigs } from "../sig/threshold.js";
50
76
  import { membershipCertSigningPayload } from "../sig/payloads.js";
51
77
  import { LruMap } from "../../utility/lru-map.js";
52
78
  /**
@@ -93,10 +119,10 @@ class CachingMembershipVerifier {
93
119
  this.lastFetchAt = new LruMap(maxCoords);
94
120
  this.staleGapStrikes = new LruMap(maxCoords);
95
121
  }
96
- cache(cert) {
122
+ cache(cert, placement) {
97
123
  // The public cache feeds this node its OWN freshly-published cert — a node trusts a cert it itself
98
124
  // published, so it is marked trusted and may anchor the next rotation in the attestation chain.
99
- this.byCoord.set(cert.cohortCoord, { cert, trusted: true });
125
+ this.byCoord.set(cert.cohortCoord, { cert, trusted: true, quorumRatio: placement?.quorumRatio });
100
126
  }
101
127
  forget(cohortCoord) {
102
128
  // Drop the cached cert (the trust lock, when the entry was trusted) and the strike counter — the
@@ -118,13 +144,16 @@ class CachingMembershipVerifier {
118
144
  async verifyMessage(signers, expectedCoord, tier, payload, sig, opts) {
119
145
  const coordKey = bytesToB64url(expectedCoord);
120
146
  const source = this.deps.router.for(tier);
147
+ const placement = opts?.placement;
148
+ const lookup = lookupOptionsFor(placement);
121
149
  // Seed from the cheap cached view if we hold nothing yet. A cached cert already passed the gate when
122
- // it was loaded (or was self-published via `cache`), so it is used directly for message verification.
123
- let cert = this.byCoord.get(coordKey)?.cert;
150
+ // it was loaded (or was self-published via `cache`), so it is used directly for message verification
151
+ // — provided it passed under the rule this call applies (see `heldUnder`).
152
+ let cert = this.heldUnder(coordKey, placement)?.cert;
124
153
  if (cert === undefined) {
125
- cert = await this.loadFrom(source.current(expectedCoord), tier);
154
+ cert = await this.loadFrom(source.current(expectedCoord, lookup), coordKey, tier, placement);
126
155
  }
127
- if (cert !== undefined && this.messageVerifies(cert, signers, payload, sig)) {
156
+ if (cert !== undefined && this.messageVerifies(cert, signers, payload, sig, placement)) {
128
157
  this.staleGapStrikes.delete(coordKey); // a verify resets the consecutive stale-gap strike count
129
158
  return "verified";
130
159
  }
@@ -136,13 +165,28 @@ class CachingMembershipVerifier {
136
165
  if (!this.refetchAllowed(coordKey, opts)) {
137
166
  return "untrusted";
138
167
  }
139
- const refreshed = await this.loadFrom(source.fetch(expectedCoord), tier);
140
- if (refreshed !== undefined && this.messageVerifies(refreshed, signers, payload, sig)) {
168
+ const refreshed = await this.loadFrom(source.fetch(expectedCoord, lookup), coordKey, tier, placement);
169
+ if (refreshed !== undefined && this.messageVerifies(refreshed, signers, payload, sig, placement)) {
141
170
  this.staleGapStrikes.delete(coordKey); // a verify resets the consecutive stale-gap strike count
142
171
  return "verified";
143
172
  }
144
173
  return "untrusted";
145
174
  }
175
+ /**
176
+ * The cached entry for `coordKey`, **only if it was validated under the rule this call applies** — the
177
+ * same root-placement ratio, or both the default rule. An entry held under any other rule reads as
178
+ * absent, for every purpose: message verification, the attestation-chain predecessor, and the trust
179
+ * lock. So a cert that passed one threshold is never taken as having passed another, and the call
180
+ * re-validates from the source under its own rule instead.
181
+ */
182
+ heldUnder(coordKey, placement) {
183
+ const held = this.byCoord.get(coordKey);
184
+ return held !== undefined && held.quorumRatio === placement?.quorumRatio ? held : undefined;
185
+ }
186
+ /** The signature threshold over `cert`'s members: `ceil(members × quorumRatio)` for a root-placed coord, else the node-wide `minSigs`. */
187
+ minSigsFor(cert, placement) {
188
+ return placement === undefined ? this.minSigs : rootPlacedMinSigs(cert.members.length, placement);
189
+ }
146
190
  /**
147
191
  * Whether a `source.fetch()` refetch is permitted for `coordKey` now. Unbounded (always `true`) unless
148
192
  * the caller supplies both `minRefetchIntervalMs` and `now`, in which case at most one refetch per coord
@@ -164,11 +208,14 @@ class CachingMembershipVerifier {
164
208
  }
165
209
  /**
166
210
  * Decode an encoded cert, run it through the trust gate, cache it (with its trusted status), and return
167
- * it for message verification; `undefined` if absent, malformed, or rejected by the gate. A rejected
168
- * cert (failed self-consistency, a `"rejected"` direct anchor, or an un-anchored cert for an
169
- * already-trusted coord) is treated exactly like an absent cert, so the single refetch still fires.
211
+ * it for message verification; `undefined` if absent, malformed, for a coord other than `coordKey`, or
212
+ * rejected by the gate. A rejected cert (failed self-consistency, a `"rejected"` direct anchor, or an
213
+ * un-anchored cert for an already-trusted coord) is treated exactly like an absent cert, so the single
214
+ * refetch still fires. The coord check runs before the gate: the gate, the direct anchor and the cache
215
+ * are all keyed on the cert's own `cohortCoord`, so a self-consistent cert for an unrelated coord would
216
+ * otherwise pass as trust-on-first-use there and then verify a message for `coordKey`.
170
217
  */
171
- async loadFrom(pending, tier) {
218
+ async loadFrom(pending, coordKey, tier, placement) {
172
219
  const encoded = await pending;
173
220
  if (encoded === undefined) {
174
221
  return undefined;
@@ -177,7 +224,17 @@ class CachingMembershipVerifier {
177
224
  let trust;
178
225
  try {
179
226
  cert = decodeMembershipCertV1(encoded, this.deps.maxMessageBytes);
180
- trust = this.certIsTrusted(cert, tier);
227
+ if (cert.cohortCoord !== coordKey) {
228
+ return undefined;
229
+ }
230
+ // The last `await` on the load path, and it has to be in this function. Two loads of one coord can
231
+ // be in flight across it, so everything that reads or writes `byCoord` / `staleGapStrikes` — the
232
+ // gate's chain, fallback and stale-gap recovery, then the `lockedUnderAnotherRule` read and the
233
+ // cache write below — runs after it in one synchronous turn. Awaiting an async gate here instead
234
+ // puts a microtask between the gate's reads and the write, and a second load's first-use check
235
+ // then misses the lock this load is about to write.
236
+ const direct = await this.directVerdict(cert, tier, placement);
237
+ trust = this.certIsTrusted(cert, direct, placement);
181
238
  }
182
239
  catch (err) {
183
240
  if (err instanceof CohortWireError) {
@@ -188,36 +245,65 @@ class CachingMembershipVerifier {
188
245
  if (trust === "reject") {
189
246
  return undefined;
190
247
  }
248
+ if (this.lockedUnderAnotherRule(cert.cohortCoord, placement)) {
249
+ return cert; // usable for this call's message check, but it must not displace the lock
250
+ }
191
251
  // Only a `"trusted"` cert may anchor a successor in the attestation chain; a `"tofu"` cert is cached
192
252
  // for message verification but must never launder trust into a rotation.
193
- this.byCoord.set(cert.cohortCoord, { cert, trusted: trust === "trusted" });
253
+ this.byCoord.set(cert.cohortCoord, { cert, trusted: trust === "trusted", quorumRatio: placement?.quorumRatio });
194
254
  return cert;
195
255
  }
196
256
  /**
197
- * The trust gate (see the module header). A cert is accepted iff it is self-consistent **and** anchored
198
- * by a trust root, the direct anchor, or the attestation chain; otherwise it falls to the interim TOFU
199
- * fallback (first-use only). Returns whether the cert is a trusted anchor (`"trusted"`), an interim
200
- * TOFU acceptance (`"tofu"`), or rejected (`"reject"`).
257
+ * Whether the coord holds a **trusted** cert validated under a rule other than this call's. Such an entry
258
+ * is invisible to this call ({@link heldUnder}), so the trust gate ran as if the coord were cold and may
259
+ * have accepted the cert on first use. Caching that result would erase the trust lock through a side
260
+ * door — a call under one rule downgrading what another rule established — so it is used for the
261
+ * current message only.
262
+ *
263
+ * NOTE: a coord has one rule by construction (it follows from how the coord was derived), so two rules
264
+ * meeting at one coord is an anomaly, and the cost here — a source read on every call under the second
265
+ * rule — is not paid in normal operation. If it ever is, key the cache by `(coord, rule)` instead.
266
+ */
267
+ lockedUnderAnotherRule(coordKey, placement) {
268
+ const held = this.byCoord.get(coordKey);
269
+ return held !== undefined && held.trusted && held.quorumRatio !== placement?.quorumRatio;
270
+ }
271
+ /**
272
+ * The first step of the trust gate: what can be said of a cert without reading per-coord state. A cert
273
+ * that is not self-consistent is `"rejected"` (internal well-formedness is the precondition for any trust
274
+ * path), one matching a configured genesis root is `"anchored"` (authoritative, checked before the direct
275
+ * anchor), and otherwise the direct anchor decides. This is the only step that may wait — the anchor may
276
+ * ask the network — which is why it reads none of the per-coord maps: self-consistency is pure and the
277
+ * trust roots are fixed at construction. Keep it that way.
201
278
  */
202
- certIsTrusted(cert, tier) {
203
- if (!this.certIsSelfConsistent(cert)) {
204
- return "reject"; // internal well-formedness is the precondition for any trust path
279
+ async directVerdict(cert, tier, placement) {
280
+ if (!this.certIsSelfConsistent(cert, placement)) {
281
+ return "rejected";
205
282
  }
206
283
  if (this.matchesTrustRoot(cert)) {
207
- return "trusted"; // a configured genesis root is authoritative, checked before the direct anchor
284
+ return "anchored";
208
285
  }
209
- const verdict = this.anchor.directAnchor(cert, tier);
210
- if (verdict === "anchored") {
286
+ return this.anchor.directAnchor(cert, tier, placement);
287
+ }
288
+ /**
289
+ * The trust gate (see the module header), given the cert's {@link directVerdict}. A cert is accepted iff
290
+ * it is self-consistent **and** anchored by a trust root, the direct anchor, or the attestation chain;
291
+ * otherwise it falls to the interim TOFU fallback (first-use only). Returns whether the cert is a trusted
292
+ * anchor (`"trusted"`), an interim TOFU acceptance (`"tofu"`), or rejected (`"reject"`). Synchronous on
293
+ * purpose: it reads the per-coord maps, and `loadFrom` runs it in the same turn as its cache write.
294
+ */
295
+ certIsTrusted(cert, direct, placement) {
296
+ if (direct === "anchored") {
211
297
  return "trusted";
212
298
  }
213
- if (verdict === "rejected") {
299
+ if (direct === "rejected") {
214
300
  return "reject"; // a contradicted binding is a forgery — fatal, overrides the TOFU fallback
215
301
  }
216
- // verdict === "unknown": no local authority for this coord. Try the attestation chain, else fall back.
217
- if (this.hasRotationAttestation(cert) && this.chainGrantsTrust(cert)) {
302
+ // direct === "unknown": no local authority for this coord. Try the attestation chain, else fall back.
303
+ if (this.hasRotationAttestation(cert) && this.chainGrantsTrust(cert, placement)) {
218
304
  return "trusted";
219
305
  }
220
- const fallback = this.fallbackTrust(cert);
306
+ const fallback = this.fallbackTrust(cert, placement);
221
307
  if (fallback !== "reject") {
222
308
  return fallback; // first-use TOFU (coord not locked): no stale lock to recover from
223
309
  }
@@ -225,7 +311,7 @@ class CachingMembershipVerifier {
225
311
  // did not chain-verify — the state that strands a former cohort member forever. Consult the stale-gap
226
312
  // recovery counter, which releases the lock only on a demonstrated chain gap (never a forged rotation
227
313
  // off the current predecessor). See {@link staleGapRecovery}.
228
- return this.staleGapRecovery(cert);
314
+ return this.staleGapRecovery(cert, placement);
229
315
  }
230
316
  /**
231
317
  * Bounded re-TOFU recovery for a coord that is **trust-locked at a stale epoch it can no longer anchor**.
@@ -247,9 +333,9 @@ class CachingMembershipVerifier {
247
333
  * reach the source, so a {@link RefetchBound}-suppressed refetch observes no cert and recovery paces itself
248
334
  * with the (bounded) refetch rate — intended, do not "fix" that pacing.
249
335
  */
250
- staleGapRecovery(cert) {
336
+ staleGapRecovery(cert, placement) {
251
337
  const coordKey = cert.cohortCoord;
252
- const locked = this.byCoord.get(coordKey);
338
+ const locked = this.heldUnder(coordKey, placement);
253
339
  // Recovery-eligible only on an explicit rotation gap: a full attestation whose prevEpoch is neither the
254
340
  // cert's own epoch (a self-referential rotation) nor the cached trusted epoch (a forgery off the current
255
341
  // predecessor — the case the lock exists to reject).
@@ -278,8 +364,8 @@ class CachingMembershipVerifier {
278
364
  * cert (a failed/absent rotation, including a forged rotation off a trusted predecessor) is **rejected**
279
365
  * — no silent TOFU downgrade — which is what gives the attestation chain its teeth.
280
366
  */
281
- fallbackTrust(cert) {
282
- return this.byCoord.get(cert.cohortCoord)?.trusted ? "reject" : "tofu";
367
+ fallbackTrust(cert, placement) {
368
+ return this.heldUnder(cert.cohortCoord, placement)?.trusted ? "reject" : "tofu";
283
369
  }
284
370
  /** Whether a cert carries a full rotation attestation (all three fields; validated all-or-nothing on the wire). */
285
371
  hasRotationAttestation(cert) {
@@ -291,18 +377,20 @@ class CachingMembershipVerifier {
291
377
  * quorum over this cert's signing payload via `rotationSig`. A predecessor that only reached the cache via
292
378
  * TOFU (not trusted) must not anchor the successor — the trusted-cache invariant.
293
379
  */
294
- chainGrantsTrust(cert) {
380
+ chainGrantsTrust(cert, placement) {
295
381
  const prevEpoch = cert.prevEpoch;
296
382
  if (prevEpoch === cert.cohortEpoch) {
297
383
  return false; // a cert cannot rotate from itself
298
384
  }
299
- const predecessor = this.byCoord.get(cert.cohortCoord);
385
+ const predecessor = this.heldUnder(cert.cohortCoord, placement);
300
386
  if (predecessor === undefined || !predecessor.trusted || predecessor.cert.cohortEpoch !== prevEpoch) {
301
387
  return false;
302
388
  }
303
389
  // `rotationSigners` is validated only as a string array, so `b64urlToBytes` may throw `CohortWireError`
304
390
  // on a malformed signer — `loadFrom`'s try/catch turns that into "no cert", as for `certIsSelfConsistent`.
305
- return this.deps.signer.verifyThreshold(membershipCertSigningPayload(cert), b64urlToBytes(cert.rotationSig), cert.rotationSigners.map((s) => b64urlToBytes(s)), predecessor.cert, this.minSigs);
391
+ return this.deps.signer.verifyThreshold(membershipCertSigningPayload(cert), b64urlToBytes(cert.rotationSig), cert.rotationSigners.map((s) => b64urlToBytes(s)), predecessor.cert,
392
+ // The rotation is signed by the PREDECESSOR cohort, so the quorum is counted over its members.
393
+ this.minSigsFor(predecessor.cert, placement));
306
394
  }
307
395
  /** Whether `cert` matches a configured trust root by `(coord, epoch)` and an order-independent member set. */
308
396
  matchesTrustRoot(cert) {
@@ -314,16 +402,20 @@ class CachingMembershipVerifier {
314
402
  return false;
315
403
  }
316
404
  /** A cert is self-consistent only if its own threshold signature is a valid quorum of its members. */
317
- certIsSelfConsistent(cert) {
405
+ certIsSelfConsistent(cert, placement) {
318
406
  // `signers` is validated only as a string array (not per-element base64url), so `b64urlToBytes`
319
407
  // below may throw `CohortWireError` on a malformed signer — `loadFrom`'s try/catch turns that
320
408
  // into "no cert" rather than letting it escape.
321
- return this.deps.signer.verifyThreshold(membershipCertSigningPayload(cert), b64urlToBytes(cert.thresholdSig), cert.signers.map((s) => b64urlToBytes(s)), cert, this.minSigs);
409
+ return this.deps.signer.verifyThreshold(membershipCertSigningPayload(cert), b64urlToBytes(cert.thresholdSig), cert.signers.map((s) => b64urlToBytes(s)), cert, this.minSigsFor(cert, placement));
322
410
  }
323
- messageVerifies(cert, signers, payload, sig) {
324
- return this.deps.signer.verifyThreshold(payload, sig, signers, cert, this.minSigs);
411
+ messageVerifies(cert, signers, payload, sig, placement) {
412
+ return this.deps.signer.verifyThreshold(payload, sig, signers, cert, this.minSigsFor(cert, placement));
325
413
  }
326
414
  }
415
+ /** The membership-source options for a call: `{ rootPlaced: true }` under a placement, none otherwise. */
416
+ function lookupOptionsFor(placement) {
417
+ return placement === undefined ? undefined : { rootPlaced: true };
418
+ }
327
419
  /** Pre-normalize a {@link TrustRoot} (raw bytes) to the cert's base64url form for cheap matching. */
328
420
  function normalizeTrustRoot(root) {
329
421
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../../src/cohort-topic/membership/verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,OAAO,CAAC;AAuG9D,MAAM,yBAAyB;IAuBD;IAtB7B,uGAAuG;IACvG,sGAAsG;IACtG,qGAAqG;IACrG,4EAA4E;IAC5E,yGAAyG;IACzG,0GAA0G;IAC1G,wGAAwG;IACxG,2FAA2F;IAC1E,OAAO,CAA6B;IACrD,gHAAgH;IAC/F,WAAW,CAAyB;IACrD;;;;OAIG;IACc,eAAe,CAAyB;IACxC,OAAO,CAAS;IAChB,MAAM,CAAyB;IAC/B,UAAU,CAAiC;IAC3C,uBAAuB,CAAS;IAEjD,YAA6B,IAA4B;QAA5B,SAAI,GAAJ,IAAI,CAAwB;QACxD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,sBAAsB,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAClE,IAAI,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AAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AACnE,CAAC;AAED,qGAAqG;AACrG,SAAS,kBAAkB,CAAC,IAAe;IAC1C,OAAO;QACN,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;QAChC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;QAChC,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;KACjD,CAAC;AACH,CAAC;AAED,iHAAiH;AACjH,SAAS,cAAc,CAAC,GAAwB,EAAE,OAA0B;IAC3E,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,CAAC,8CAA8C;QAC7D,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACb,CAAC;IACD,qGAAqG;IACrG,6EAA6E;IAC7E,OAAO,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC;AAC/B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,wBAAwB,CAAC,IAA4B;IACpE,OAAO,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC"}
@@ -19,6 +19,21 @@ import type { MembershipCertV1 } from "./wire/types.js";
19
19
  * matches FRET's ring width so routing keys line up on the wire.
20
20
  */
21
21
  export type RingCoord = Uint8Array;
22
+ declare const topicRouteKeyBrand: unique symbol;
23
+ /**
24
+ * The bytes a cohort-topic frame is routed on: FRET hashes them exactly once into the cohort's ring
25
+ * coordinate. FRET's `routeAct` hashes the key it is handed — at the origin and again at every forwarding
26
+ * hop — so handing it a coordinate lands the frame at the hash of that coordinate, a ring position no
27
+ * cohort serves. Branded so the only way to obtain one is `TierAddressing.routeKey`, which builds the
28
+ * preimage of `TierAddressing.coord` for the same inputs; a {@link RingCoord} does not type-check where a
29
+ * route key belongs.
30
+ *
31
+ * A separate brand from `RoutingKey` (`network/routing-key.ts`): that one is obtainable only from a block
32
+ * id, and these preimages are not block keys.
33
+ */
34
+ export type TopicRouteKey = Uint8Array & {
35
+ readonly [topicRouteKeyBrand]: true;
36
+ };
22
37
  /** A peer, referenced only by its opaque byte-array id. No multiaddr, no libp2p PeerId here. */
23
38
  export interface PeerRef {
24
39
  readonly id: Uint8Array;
@@ -29,16 +44,58 @@ export interface PeerRef {
29
44
  */
30
45
  export interface ITopicRouter {
31
46
  /**
32
- * Route `activity` to the cohort owning `key` and run the cohort's activity callback,
33
- * collecting up to `wantK` participants and at least `minSigs` signatures.
47
+ * Route `activity` to the cohort at `H(key)` and run the cohort's activity callback,
48
+ * collecting up to `wantK` participants and at least `minSigs` signatures. The router hashes `key`
49
+ * once; build it with `TierAddressing.routeKey` so that hash is the tier's coordinate.
34
50
  * @returns the encoded cohort reply.
35
51
  */
36
- routeAndAct(key: RingCoord, activity: Uint8Array, opts: {
52
+ routeAndAct(key: TopicRouteKey, activity: Uint8Array, opts: {
37
53
  wantK: number;
38
54
  minSigs: number;
39
55
  }): Promise<Uint8Array>;
40
56
  /** Direct dial to a cached primary; falls back to {@link routeAndAct} on failure (caller decides). */
41
57
  dialMember(member: PeerRef, activity: Uint8Array): Promise<Uint8Array>;
58
+ /**
59
+ * Deliver `activity` to the **root group** of a root-placed topic — the peers responsible for
60
+ * `rootKey` — and return the encoded reply. Optional: the walk uses it for the tier-0 step of a
61
+ * root-placed topic when the router has it, and otherwise falls back to ring routing on the root key,
62
+ * which reaches the root coordinate `H(rootKey)`.
63
+ *
64
+ * It exists because the two can disagree: `routeAndAct` lands on the ring's nearest peer to the
65
+ * coordinate, which on a ring shared with another network may be a peer of that other network, whereas
66
+ * the root group is chosen by the rule storage placement uses. db-p2p binds this to the key network.
67
+ */
68
+ routeToRoot?(rootKey: Uint8Array, activity: Uint8Array): Promise<Uint8Array>;
69
+ }
70
+ /**
71
+ * The per-coord rule for a **root-placed** cohort — the root of a topic whose tier-0 coordinate is
72
+ * `H(rootKey)` (see `addressing.ts`). Such a cohort is the group of peers responsible for the root key
73
+ * rather than the FRET cohort of `wantK`, so the node-wide `minSigs` does not describe it: its signature
74
+ * threshold is `ceil(memberCount × quorumRatio)`.
75
+ *
76
+ * `quorumRatio` is always the **verifying node's own** configuration, never a value read off a message or
77
+ * a certificate. Build one with `createRootPlacement` (`sig/threshold.ts`), which rejects a ratio outside
78
+ * `(0, 1]`.
79
+ */
80
+ export interface RootPlacement {
81
+ /** Fraction of a root-placed cohort's members whose signatures make a quorum, in `(0, 1]`. */
82
+ readonly quorumRatio: number;
83
+ /**
84
+ * The routing key whose ring position is the root coordinate, when the caller knows it — for a reactivity
85
+ * root, the tail block's routing key (`routingKeyForBlock(tailId)`, the raw UTF-8 of the id). A direct
86
+ * anchor that can locate the group's own commit record from the key (db-p2p's commit-log anchor) needs it;
87
+ * one that cannot ignores it. It takes no part in cache identity: a coordinate is the hash of its key, so
88
+ * one coordinate has one key, and the verifier keys its cache by `quorumRatio` alone.
89
+ */
90
+ readonly rootKey?: Uint8Array;
91
+ }
92
+ /** Options for a membership-cert lookup ({@link IMembershipSource}). */
93
+ export interface MembershipLookupOptions {
94
+ /**
95
+ * The coord is the root of a root-placed topic, so its cert is held by (and must be fetched from) the
96
+ * root group rather than the FRET cohort around the coord.
97
+ */
98
+ readonly rootPlaced?: true;
42
99
  }
43
100
  /** Intra-cohort gossip transport (FRET cohort gossip underneath). */
44
101
  export interface ICohortGossipTransport {
@@ -50,9 +107,9 @@ export interface ICohortGossipTransport {
50
107
  /** Authoritative cohort membership snapshots (FRET `MembershipCertV1` / stabilization underneath). */
51
108
  export interface IMembershipSource {
52
109
  /** Current cached membership cert for `coord`, encoded; `undefined` if none is cached. */
53
- current(coord: RingCoord): Promise<Uint8Array | undefined>;
110
+ current(coord: RingCoord, opts?: MembershipLookupOptions): Promise<Uint8Array | undefined>;
54
111
  /** Force one refresh of `coord`'s membership cert (stale-cache retry); encoded, or `undefined`. */
55
- fetch(coord: RingCoord): Promise<Uint8Array | undefined>;
112
+ fetch(coord: RingCoord, opts?: MembershipLookupOptions): Promise<Uint8Array | undefined>;
56
113
  }
57
114
  /**
58
115
  * Cohort threshold-signature primitive (FRET's `minSigs = k − x` cohort-signature assembly
@@ -75,10 +132,11 @@ export interface ICohortThresholdCrypto {
75
132
  /**
76
133
  * Sink the cohort uses to publish a `MembershipCertV1` (over FRET's `/membership` protocol).
77
134
  * db-core's publisher builds + threshold-signs the cert and hands it here; db-p2p serves it.
135
+ * A node serves one cohort per coordinate it is in, so a cert is published under its coordinate.
78
136
  */
79
137
  export interface IMembershipPublishSink {
80
- /** Publish (advertise/serve) an already-signed membership certificate, encoded. */
81
- publish(encodedCert: Uint8Array): void;
138
+ /** Publish (advertise/serve) an already-signed membership certificate, encoded, for cohort coord `coord`. */
139
+ publish(coord: RingCoord, encodedCert: Uint8Array): void;
82
140
  }
83
141
  /** Network-size estimate feeding `d_max`. */
84
142
  export interface ISizeEstimator {
@@ -104,15 +162,27 @@ export type TrustAnchorVerdict = "anchored" | "rejected" | "unknown";
104
162
  * Direct (base-case) trust anchor for a {@link MembershipCertV1}'s `coord → keyset` binding.
105
163
  *
106
164
  * db-core owns the chain-of-attestations and trust-root logic; the **direct** anchor is
107
- * tier/transport-specific (FRET ring agreement for T2/T3, tx-log commit certificate for T0/T1) and
108
- * is therefore delegated through this port. db-p2p binds it; **db-core never imports FRET**. A node
109
- * with no local authority for the coord returns `"unknown"` so the verifier falls through to the
110
- * chain / interim fallback instead of breaking distant verification. See {@link noAuthorityTrustAnchor}
111
- * for the db-core default (every coord `"unknown"`).
165
+ * tier/transport-specific and is therefore delegated through this port. db-p2p binds two: the FRET ring
166
+ * agreement for a coord this node serves (`FretTrustAnchor`), and, for a reactivity root — a root-placed
167
+ * coord whose placement names its key — the tail block's own commit proof, fetched from the tail's storage
168
+ * group (`CommitLogTrustAnchor`); the host asks the first and falls through to the second on `"unknown"`.
169
+ * **db-core never imports FRET.** A node with no authority for the coord returns `"unknown"` so the
170
+ * verifier falls through to the chain / interim fallback instead of breaking distant verification. See
171
+ * {@link noAuthorityTrustAnchor} for the db-core default (every coord `"unknown"`).
172
+ *
173
+ * **The verdict may be asynchronous.** An anchor that judges from local state answers synchronously; one
174
+ * that has to ask the network (the commit-log anchor) returns a promise, and the verifier's trust gate
175
+ * awaits either. An anchor is total: it never throws or rejects, and answers `"unknown"` for anything it
176
+ * cannot decode or reach.
112
177
  */
113
178
  export interface IMembershipTrustAnchor {
114
- /** Judge, from a directly-trusted source, whether `cert.members` is authoritative for `cert.cohortCoord` at `tier`. */
115
- directAnchor(cert: MembershipCertV1, tier: number): TrustAnchorVerdict;
179
+ /**
180
+ * Judge, from a directly-trusted source, whether `cert.members` is authoritative for `cert.cohortCoord`
181
+ * at `tier`. `placement` is present when the verifier was told the coord is root-placed, so the anchor
182
+ * compares against the root group (and its threshold) rather than the FRET cohort around the coord; its
183
+ * `rootKey`, when the caller knew it, is what lets an anchor locate that group's own records.
184
+ */
185
+ directAnchor(cert: MembershipCertV1, tier: number, placement?: RootPlacement): TrustAnchorVerdict | Promise<TrustAnchorVerdict>;
116
186
  }
117
187
  /**
118
188
  * An out-of-band-seeded trust root: the genesis-block-related cohorts a joining participant is told
@@ -146,4 +216,5 @@ export interface IRingHash {
146
216
  /** Ring width in bits. */
147
217
  readonly ringBits: number;
148
218
  }
219
+ export {};
149
220
  //# sourceMappingURL=ports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../../src/cohort-topic/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC;A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AI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChI;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,gHAAgH;IAChH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CACxC;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAIpC,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACzB,8EAA8E;IAC9E,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B"}
@@ -18,7 +18,7 @@
18
18
  * the interim TOFU behavior (no regression) until db-p2p binds a real anchor.
19
19
  */
20
20
  export const noAuthorityTrustAnchor = {
21
- directAnchor(_cert, _tier) {
21
+ directAnchor(_cert, _tier, _placement) {
22
22
  return "unknown";
23
23
  },
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/cohort-topic/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA0HH;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA2B;IAC7D,YAAY,CAAC,KAAuB,EAAE,KAAa;QAClD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD,CAAC"}
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/cohort-topic/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAkMH;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA2B;IAC7D,YAAY,CAAC,KAAuB,EAAE,KAAa,EAAE,UAA0B;QAC9E,OAAO,SAAS,CAAC;IAClB,CAAC;CACD,CAAC"}
@@ -3,7 +3,13 @@
3
3
  *
4
4
  * Per `docs/cohort-topic.md` §TTL and renewal and §Failure modes:
5
5
  *
6
- * - Participant pings `primary` every `ttl/3`. Success → primary touches `lastPing` and gossips it.
6
+ * - Participant pings `primary` every `ttl/3`. The four replies:
7
+ * - `ok` — the primary touched `lastPing` and gossips it; the failure count resets.
8
+ * - `primary_moved` — a rotation moved the slot; the participant adopts the named primary/backups/epoch
9
+ * and the failure count resets.
10
+ * - `unknown_registration` / `withdrawn` — the member holds no record for this participant (it restarted,
11
+ * the record expired, a stale withdraw removed it, or gossip has not reached it yet). Counted as a failed
12
+ * ping, exactly like no answer: an answer from a member that does not hold the record keeps nothing alive.
7
13
  * - Three consecutive ping failures → participant promotes `backups[0]` via a re-attach RPC: a renew
8
14
  * carrying a **signed `reattach` flag** (no full re-registration). The backup accepts when it holds
9
15
  * the record locally *and* is a computed backup under the current epoch — re-stamping `primary` to
@@ -13,7 +19,11 @@
13
19
  * payload instead of promoting the contacted backup (ignoring a reply that points back at the dead
14
20
  * primary). **Resolved (GROUNDING):** the participant's `cohortEpoch` hint refreshes lazily — on the
15
21
  * *next* ping/renewal after failover, not eagerly at failover time.
16
- * - All of primary + backups fail → participant re-runs lookup from `d_max` (walk ticket, injected).
22
+ * - All of primary + backups fail → participant re-runs lookup from `d_max` (injected) and adopts where the
23
+ * re-walk landed — primary, backups, epoch hint and the accepted register's correlation id. A walk that is
24
+ * not accepted keeps the old assignment. Either way the failure count resets, so the next re-walk is at
25
+ * least {@link MAX_PING_FAILURES} pings away: at most one per TTL, under the cohort's per-peer register
26
+ * rate limit, and a one-off `unknown_registration` from replication lag clears on the next ping.
17
27
  * - Cohort-side: evict where `now − lastPing > ttl`; eviction is gossiped so members converge.
18
28
  *
19
29
  * Both sides take their transport/gossip by injection so storage + sharding + TTL stay unit-testable
@@ -47,12 +57,23 @@ export interface RenewalParticipant {
47
57
  }
48
58
  /** The unsigned body of a renew/re-attach RPC; the injected signer turns it into a {@link RenewV1}. */
49
59
  export type UnsignedRenew = Omit<RenewV1, "signature">;
60
+ /** Where a re-run register walk placed the registration; the participant adopts it in place of its own. */
61
+ export interface RenewalAssignment {
62
+ readonly primary: Uint8Array;
63
+ readonly backups: readonly Uint8Array[];
64
+ readonly cohortEpoch: Uint8Array;
65
+ /** The accepted register's correlation id, base64url — echoed on every later renew. */
66
+ readonly correlationId: string;
67
+ }
50
68
  /** Transport the participant drives; supplied by db-p2p (FRET dial / RouteAndMaybeAct underneath). */
51
69
  export interface RenewalParticipantTransport {
52
70
  /** Send a renew/re-attach to `target`; resolves with the reply, rejects on RPC failure. */
53
71
  send(target: Uint8Array, msg: RenewV1): Promise<RenewReplyV1>;
54
- /** Primary + all backups unreachable: re-run lookup from `d_max` (walk ticket owns the body). */
55
- relookup(): Promise<void>;
72
+ /**
73
+ * Primary + all backups failed: re-run the register walk from `d_max`. Resolves the accepted walk's
74
+ * assignment, or `undefined` when the walk was not accepted (a back-off or redirect it could not finish).
75
+ */
76
+ relookup(): Promise<RenewalAssignment | undefined>;
56
77
  }
57
78
  export interface RenewalParticipantDeps {
58
79
  transport: RenewalParticipantTransport;
@@ -60,7 +81,7 @@ export interface RenewalParticipantDeps {
60
81
  clock: () => number;
61
82
  /** Signs the renew body; db-p2p supplies the (async) peer-key signature. */
62
83
  sign: (body: UnsignedRenew) => Promise<string>;
63
- /** Correlation id matching the original RegisterV1, base64url. */
84
+ /** Correlation id matching the original RegisterV1, base64url; replaced when a relookup lands. */
64
85
  correlationId: string;
65
86
  /** Initial cohort-epoch hint from the registration reply (refreshed lazily thereafter). */
66
87
  initialCohortEpoch?: Uint8Array;