@optimystic/db-core 1.9.0 → 1.10.1
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.
- package/dist/src/cohort-topic/addressing.d.ts +46 -6
- package/dist/src/cohort-topic/addressing.d.ts.map +1 -1
- package/dist/src/cohort-topic/addressing.js +58 -18
- package/dist/src/cohort-topic/addressing.js.map +1 -1
- package/dist/src/cohort-topic/member-engine.d.ts +21 -1
- package/dist/src/cohort-topic/member-engine.d.ts.map +1 -1
- package/dist/src/cohort-topic/member-engine.js +39 -9
- package/dist/src/cohort-topic/member-engine.js.map +1 -1
- package/dist/src/cohort-topic/membership/publisher.js +1 -1
- package/dist/src/cohort-topic/membership/publisher.js.map +1 -1
- package/dist/src/cohort-topic/membership/source.d.ts +4 -0
- package/dist/src/cohort-topic/membership/source.d.ts.map +1 -1
- package/dist/src/cohort-topic/membership/source.js +4 -0
- package/dist/src/cohort-topic/membership/source.js.map +1 -1
- package/dist/src/cohort-topic/membership/verifier.d.ts +51 -9
- package/dist/src/cohort-topic/membership/verifier.d.ts.map +1 -1
- package/dist/src/cohort-topic/membership/verifier.js +138 -46
- package/dist/src/cohort-topic/membership/verifier.js.map +1 -1
- package/dist/src/cohort-topic/ports.d.ts +85 -14
- package/dist/src/cohort-topic/ports.d.ts.map +1 -1
- package/dist/src/cohort-topic/ports.js +1 -1
- package/dist/src/cohort-topic/ports.js.map +1 -1
- package/dist/src/cohort-topic/promotion.d.ts +3 -2
- package/dist/src/cohort-topic/promotion.d.ts.map +1 -1
- package/dist/src/cohort-topic/promotion.js +15 -3
- package/dist/src/cohort-topic/promotion.js.map +1 -1
- package/dist/src/cohort-topic/registration/renewal.d.ts +26 -5
- package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -1
- package/dist/src/cohort-topic/registration/renewal.js +71 -21
- package/dist/src/cohort-topic/registration/renewal.js.map +1 -1
- package/dist/src/cohort-topic/service.d.ts +34 -2
- package/dist/src/cohort-topic/service.d.ts.map +1 -1
- package/dist/src/cohort-topic/service.js +86 -28
- package/dist/src/cohort-topic/service.js.map +1 -1
- package/dist/src/cohort-topic/sig/payloads.d.ts +5 -1
- package/dist/src/cohort-topic/sig/payloads.d.ts.map +1 -1
- package/dist/src/cohort-topic/sig/payloads.js +6 -1
- package/dist/src/cohort-topic/sig/payloads.js.map +1 -1
- package/dist/src/cohort-topic/sig/threshold.d.ts +29 -4
- package/dist/src/cohort-topic/sig/threshold.d.ts.map +1 -1
- package/dist/src/cohort-topic/sig/threshold.js +39 -7
- package/dist/src/cohort-topic/sig/threshold.js.map +1 -1
- package/dist/src/cohort-topic/walk.d.ts +19 -4
- package/dist/src/cohort-topic/walk.d.ts.map +1 -1
- package/dist/src/cohort-topic/walk.js +29 -6
- package/dist/src/cohort-topic/walk.js.map +1 -1
- package/dist/src/cohort-topic/willingness.d.ts +17 -1
- package/dist/src/cohort-topic/willingness.d.ts.map +1 -1
- package/dist/src/cohort-topic/willingness.js +18 -3
- package/dist/src/cohort-topic/willingness.js.map +1 -1
- package/dist/src/cohort-topic/wire/index.d.ts +1 -1
- package/dist/src/cohort-topic/wire/index.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/index.js +1 -1
- package/dist/src/cohort-topic/wire/index.js.map +1 -1
- package/dist/src/cohort-topic/wire/payloads.d.ts +14 -0
- package/dist/src/cohort-topic/wire/payloads.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/payloads.js +20 -0
- package/dist/src/cohort-topic/wire/payloads.js.map +1 -1
- package/dist/src/cohort-topic/wire/primitives.d.ts +8 -0
- package/dist/src/cohort-topic/wire/primitives.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/primitives.js +24 -4
- package/dist/src/cohort-topic/wire/primitives.js.map +1 -1
- package/dist/src/cohort-topic/wire/types.d.ts +37 -0
- package/dist/src/cohort-topic/wire/types.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/validate.d.ts +9 -1
- package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/validate.js +23 -4
- package/dist/src/cohort-topic/wire/validate.js.map +1 -1
- package/dist/src/reactivity/config.d.ts +9 -10
- package/dist/src/reactivity/config.d.ts.map +1 -1
- package/dist/src/reactivity/config.js +9 -9
- package/dist/src/reactivity/config.js.map +1 -1
- package/dist/src/reactivity/index.d.ts +4 -3
- package/dist/src/reactivity/index.d.ts.map +1 -1
- package/dist/src/reactivity/index.js +4 -3
- package/dist/src/reactivity/index.js.map +1 -1
- package/dist/src/reactivity/rotation.d.ts +73 -57
- package/dist/src/reactivity/rotation.d.ts.map +1 -1
- package/dist/src/reactivity/rotation.js +54 -54
- package/dist/src/reactivity/rotation.js.map +1 -1
- package/dist/src/reactivity/subscription.d.ts +12 -9
- package/dist/src/reactivity/subscription.d.ts.map +1 -1
- package/dist/src/reactivity/subscription.js +9 -6
- package/dist/src/reactivity/subscription.js.map +1 -1
- package/dist/src/reactivity/topic-anchor.d.ts +36 -31
- package/dist/src/reactivity/topic-anchor.d.ts.map +1 -1
- package/dist/src/reactivity/topic-anchor.js +41 -39
- package/dist/src/reactivity/topic-anchor.js.map +1 -1
- package/dist/src/reactivity/verify.d.ts +26 -9
- package/dist/src/reactivity/verify.d.ts.map +1 -1
- package/dist/src/reactivity/verify.js +26 -11
- package/dist/src/reactivity/verify.js.map +1 -1
- package/dist/src/reactivity/wire.d.ts +1 -1
- package/dist/src/reactivity/wire.d.ts.map +1 -1
- package/dist/src/transactor/change-notifier.d.ts +1 -1
- package/package.json +1 -1
- package/src/cohort-topic/addressing.ts +83 -23
- package/src/cohort-topic/member-engine.ts +77 -8
- package/src/cohort-topic/membership/publisher.ts +1 -1
- package/src/cohort-topic/membership/source.ts +4 -0
- package/src/cohort-topic/membership/verifier.ts +169 -51
- package/src/cohort-topic/ports.ts +87 -15
- package/src/cohort-topic/promotion.ts +15 -3
- package/src/cohort-topic/registration/renewal.ts +87 -24
- package/src/cohort-topic/service.ts +157 -35
- package/src/cohort-topic/sig/payloads.ts +7 -2
- package/src/cohort-topic/sig/threshold.ts +41 -7
- package/src/cohort-topic/walk.ts +46 -9
- package/src/cohort-topic/willingness.ts +34 -3
- package/src/cohort-topic/wire/index.ts +1 -0
- package/src/cohort-topic/wire/payloads.ts +21 -0
- package/src/cohort-topic/wire/primitives.ts +26 -4
- package/src/cohort-topic/wire/types.ts +37 -0
- package/src/cohort-topic/wire/validate.ts +26 -3
- package/src/reactivity/config.ts +10 -10
- package/src/reactivity/index.ts +4 -3
- package/src/reactivity/rotation.ts +86 -78
- package/src/reactivity/subscription.ts +12 -9
- package/src/reactivity/topic-anchor.ts +42 -45
- package/src/reactivity/verify.ts +36 -17
- package/src/reactivity/wire.ts +1 -1
- package/src/transactor/change-notifier.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rotation.d.ts","sourceRoot":"","sources":["../../../src/reactivity/rotation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"rotation.d.ts","sourceRoot":"","sources":["../../../src/reactivity/rotation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAA0B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAKhE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,cAAc,CAE5F;AAED,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IACjC,6HAA6H;IAC7H,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAA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AAM,CAAA;KAAE,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GAC3H,kBAAkB,EAAE,CAItB;AAID,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC/B,yFAAyF;IACzF,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAC;IACvC,8FAA8F;IAC9F,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,GAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,eAAe,GAAG,SAAS,CAiBtI;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI,CAE5F;AAED,8FAA8F;AAC9F,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEtF"}
|
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reactivity — tail rotation lifecycle (`docs/reactivity.md` §
|
|
2
|
+
* Reactivity — tail rotation lifecycle (`docs/reactivity.md` §Anchor, §Tail rotation).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* block fills (`block_fill_size`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* A collection's topic is stable (`reactivityCollectionTopicId`, `topic-anchor.ts`); what rotates is its
|
|
5
|
+
* **root**. When the tail block fills (`block_fill_size` entries, the log's `EntriesPerBlock`) a new tail
|
|
6
|
+
* block is born and the root — the tail's storage group at `H(tailId)` — moves to the new tail's group. The
|
|
7
|
+
* tiers below the root sit at `coord_d(P, topicId)` and never move, so a rotation is "same topic, the root
|
|
8
|
+
* moved": a registration at the root re-registers under the new root key; one below the root keeps its place
|
|
9
|
+
* and only updates the root key a later re-walk would use (`CohortTopicService.moveRoot`). This module owns
|
|
10
|
+
* the subscriber- and root-side lifecycle around that move:
|
|
9
11
|
*
|
|
10
12
|
* - **Pre-announce** — the block-filling commit's notification carries {@link RotationHintV1}; built here
|
|
11
13
|
* by {@link buildRotationHint} and detected subscriber-side by {@link detectRotation}.
|
|
12
14
|
* - **Block-fill tracking** — {@link BlockFillTracker} counts transactions in the current tail block and
|
|
13
15
|
* fires anticipatory **warm-up** at `block_fill_size − warm_threshold` and the **filling** signal at
|
|
14
16
|
* `block_fill_size` (the commit that carries the hint).
|
|
15
|
-
* - **Drain** — {@link TailDrainGate} keeps the outgoing
|
|
16
|
-
* bouncing *new* subscriptions with a `Promoted`-shaped {@link RotationRedirectV1}
|
|
17
|
+
* - **Drain** — {@link TailDrainGate} keeps the outgoing root serving renewals/replays for `T_drain` while
|
|
18
|
+
* bouncing *new* subscriptions with a `Promoted`-shaped {@link RotationRedirectV1} naming the new tail.
|
|
17
19
|
* - **Jittered re-registration** — {@link planReRegistration} / {@link planReRegistrationWave} schedule a
|
|
18
|
-
* subscriber's
|
|
20
|
+
* subscriber's follow of the new tail over `T_rejoin_jitter` (the cohort-topic {@link RejoinJitter}),
|
|
19
21
|
* carrying its existing `lastRevision` (revisions are continuous across rotations).
|
|
20
|
-
* - **Buffer-to-checkpoint handoff** — {@link buildRotationHandoffCheckpoint} folds the outgoing
|
|
22
|
+
* - **Buffer-to-checkpoint handoff** — {@link buildRotationHandoffCheckpoint} folds the outgoing root's
|
|
21
23
|
* replay buffer into a final {@link CheckpointSummary} covering `[lastCheckpoint.toRevision + 1,
|
|
22
24
|
* rotationRevision]`, the **only** state migrated across a rotation; {@link applyRotationHandoff} lands it
|
|
23
|
-
* at the new
|
|
25
|
+
* at the new root so a `ResumeV1` spanning the rotation is recoverable.
|
|
24
26
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* state migrates; the new tree rebuilds via re-registration). It needs no code here.
|
|
27
|
+
* Tiers below the root do not drain on a rotation: only the old root stops receiving commits and releases its
|
|
28
|
+
* state after `T_drain`. It needs no code here.
|
|
28
29
|
*
|
|
29
30
|
* Coordination with [reactivity-backfill-resume-checkpoints]: that ticket owns the `ResumeReplyV1.TailRotated`
|
|
30
|
-
* variant and the `latestKnownTailId`-staleness classification; this
|
|
31
|
-
* and the rotation *condition*. The new
|
|
31
|
+
* variant and the `latestKnownTailId`-staleness classification; this module produces the handoff checkpoint
|
|
32
|
+
* and the rotation *condition*. The new root's {@link PushState.inheritedCheckpoint} (set by
|
|
32
33
|
* {@link applyRotationHandoff}) is the seam the resume classifier consults to answer a checkpoint-window
|
|
33
|
-
* resume whose span crosses the rotation: `classifyResume`/`serveResume`
|
|
34
|
+
* resume whose span crosses the rotation: `classifyResume`/`serveResume` read it (after the rolling
|
|
34
35
|
* `checkpoint` misses) and serve the inherited summary, so a cross-rotation resume no longer falls to
|
|
35
36
|
* `out_of_window` (`docs/reactivity.md` §Resume, §Tail rotation step 5). The drain-window redirect a new
|
|
36
37
|
* subscription receives, {@link RotationRedirectV1}, is serialized by {@link validateRotationRedirectV1} and
|
|
37
38
|
* rides the recover reply envelope as `kind: "rotated"` ({@link import("./recover.js").RecoverReplyV1}).
|
|
38
39
|
*/
|
|
39
|
-
import {
|
|
40
|
-
import { createRingHash } from "../cohort-topic/ring-hash.js";
|
|
40
|
+
import { b64urlToBytes } from "../cohort-topic/wire/codec.js";
|
|
41
41
|
import { BLOCK_FILL_SIZE_DEFAULT, T_DRAIN_MS, WARM_THRESHOLD_DEFAULT } from "./config.js";
|
|
42
42
|
import { buildCheckpointSummary } from "./checkpoint.js";
|
|
43
|
-
import { reactivityTopicId } from "./topic-anchor.js";
|
|
44
43
|
import { asObject, b64urlField, failWire, reqIntInRange, reqString, requireV1 } from "./wire-validate.js";
|
|
45
44
|
// --- pre-announce + subscriber-side detection --------------------------------
|
|
46
45
|
/**
|
|
@@ -53,17 +52,26 @@ export function buildRotationHint(newTailId, fillingRevision) {
|
|
|
53
52
|
return { newTailId, effectiveAtRevision: fillingRevision + 1 };
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
|
-
* Detect tail rotation for a subscriber
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
55
|
+
* Detect tail rotation for a subscriber following `followed.tailId` from a delivered notification. Rotation
|
|
56
|
+
* is signaled when the delivered `tailId` **or** the `rotationHint.newTailId` differs from it
|
|
57
|
+
* (`docs/reactivity.md` §Tail rotation). An already-rotated delivery (different `tailId`) takes precedence
|
|
58
|
+
* over a pre-announce.
|
|
59
|
+
*
|
|
60
|
+
* A differing `tailId` at a revision at or below `followed.newestRevision` is **not** a rotation: the
|
|
61
|
+
* notification was announced at a tail the subscriber has already moved past. The old and the new root are
|
|
62
|
+
* different machines delivering independently, so the last notification announced at the old tail can arrive
|
|
63
|
+
* after the subscriber followed the new one; without the revision check it would read as a rotation back to
|
|
64
|
+
* the old tail and cost a registration at a root that announces nothing further.
|
|
60
65
|
*/
|
|
61
|
-
export function detectRotation(
|
|
62
|
-
if (n.tailId !==
|
|
63
|
-
|
|
66
|
+
export function detectRotation(followed, n) {
|
|
67
|
+
if (n.tailId !== followed.tailId) {
|
|
68
|
+
if (n.revision <= followed.newestRevision) {
|
|
69
|
+
return { rotated: false, preAnnounced: false };
|
|
70
|
+
}
|
|
71
|
+
// The delivered notification was announced at the *new* root already — a hard rotation, not a pre-announce.
|
|
64
72
|
return { rotated: true, newTailId: n.tailId, preAnnounced: false };
|
|
65
73
|
}
|
|
66
|
-
if (n.rotationHint !== undefined && n.rotationHint.newTailId !==
|
|
74
|
+
if (n.rotationHint !== undefined && n.rotationHint.newTailId !== followed.tailId) {
|
|
67
75
|
return { rotated: true, newTailId: n.rotationHint.newTailId, preAnnounced: true };
|
|
68
76
|
}
|
|
69
77
|
return { rotated: false, preAnnounced: false };
|
|
@@ -142,8 +150,8 @@ export function validateRotationRedirectV1(value) {
|
|
|
142
150
|
};
|
|
143
151
|
}
|
|
144
152
|
/**
|
|
145
|
-
* The outgoing
|
|
146
|
-
* serves **replays**, but bounces **new subscriptions** with a {@link RotationRedirectV1} to the new
|
|
153
|
+
* The outgoing root's drain state machine. For `T_drain` after a rotation it accepts **renewals** and
|
|
154
|
+
* serves **replays**, but bounces **new subscriptions** with a {@link RotationRedirectV1} to the new root;
|
|
147
155
|
* after `T_drain` it reports `drained` for everything (the subscriber re-registers from `d_max`).
|
|
148
156
|
*/
|
|
149
157
|
export class TailDrainGate {
|
|
@@ -157,13 +165,11 @@ export class TailDrainGate {
|
|
|
157
165
|
}
|
|
158
166
|
this.rotatedAt = init.rotatedAt;
|
|
159
167
|
this.tDrainMs = tDrainMs;
|
|
160
|
-
const hash = init.hash ?? createRingHash();
|
|
161
|
-
const newTopicId = bytesToB64url(reactivityTopicId(b64urlToBytes(init.newTailId), hash));
|
|
162
168
|
this.redirect = {
|
|
163
169
|
v: 1,
|
|
164
170
|
result: "rotated",
|
|
165
171
|
newTailId: init.newTailId,
|
|
166
|
-
newTopicId,
|
|
172
|
+
newTopicId: init.topicId,
|
|
167
173
|
effectiveAtRevision: init.effectiveAtRevision,
|
|
168
174
|
};
|
|
169
175
|
}
|
|
@@ -181,7 +187,7 @@ export class TailDrainGate {
|
|
|
181
187
|
}
|
|
182
188
|
/**
|
|
183
189
|
* Classify an inbound request. Within the drain window: `new_subscribe` → redirect, `renew`/`replay` →
|
|
184
|
-
* serve. After the window: `drained` (the old
|
|
190
|
+
* serve. After the window: `drained` (the old root has released its forwarder state).
|
|
185
191
|
*/
|
|
186
192
|
classify(op, now) {
|
|
187
193
|
if (!this.isDraining(now)) {
|
|
@@ -190,26 +196,20 @@ export class TailDrainGate {
|
|
|
190
196
|
return op === "new_subscribe" ? { kind: "redirect", redirect: this.redirect } : { kind: "serve" };
|
|
191
197
|
}
|
|
192
198
|
}
|
|
193
|
-
/** Resolve `(newTailId, newTopicId)` raw bytes for a rotation target. */
|
|
194
|
-
function resolveRotationTarget(target) {
|
|
195
|
-
const newTailId = b64urlToBytes(target.hint.newTailId);
|
|
196
|
-
const newTopicId = reactivityTopicId(newTailId, target.hash ?? createRingHash());
|
|
197
|
-
return { newTailId, newTopicId };
|
|
198
|
-
}
|
|
199
199
|
/**
|
|
200
|
-
* Plan **one** subscriber's
|
|
201
|
-
* `
|
|
202
|
-
*
|
|
203
|
-
*
|
|
200
|
+
* Plan **one** subscriber's follow of the moved root: carry the hint's `newTailId` and the subscriber's
|
|
201
|
+
* `lastRevision`, and draw a jittered `fireAt` over `T_rejoin_jitter` via the cohort-topic
|
|
202
|
+
* {@link RejoinJitter} (`scheduleRejoin` — a uniform offset, decorrelating this subscriber's re-join from
|
|
203
|
+
* its peers). Only a registration at the root sends anything when the plan fires; one below the root
|
|
204
|
+
* updates its root key locally.
|
|
204
205
|
*/
|
|
205
206
|
export function planReRegistration(opts) {
|
|
206
|
-
|
|
207
|
-
return { newTailId, newTopicId, lastRevision: opts.lastRevision, fireAt: opts.jitter.scheduleRejoin(opts.now) };
|
|
207
|
+
return { newTailId: b64urlToBytes(opts.hint.newTailId), lastRevision: opts.lastRevision, fireAt: opts.jitter.scheduleRejoin(opts.now) };
|
|
208
208
|
}
|
|
209
209
|
/**
|
|
210
|
-
* Plan a **whole wave** of subscribers'
|
|
210
|
+
* Plan a **whole wave** of subscribers' follows of the moved root. Uses the
|
|
211
211
|
* {@link RejoinJitter.scheduleWave} hard-bound staggering so any `T_rejoin_jitter`-long window holds at
|
|
212
|
-
* most the injected jitter's `capPromote` arrivals — the new
|
|
212
|
+
* most the injected jitter's `capPromote` arrivals — the new root never sees more than
|
|
213
213
|
* `capPromote / T_rejoin_jitter` re-registrations per second.
|
|
214
214
|
*
|
|
215
215
|
* **Caller contract:** rotation is governed by the *fast-promote* bound, so the host MUST build this `jitter`
|
|
@@ -219,12 +219,12 @@ export function planReRegistration(opts) {
|
|
|
219
219
|
* (`docs/reactivity.md` §Tail rotation rotation-cost). Returns one plan per subscriber, ascending by `fireAt`.
|
|
220
220
|
*/
|
|
221
221
|
export function planReRegistrationWave(opts) {
|
|
222
|
-
const
|
|
222
|
+
const newTailId = b64urlToBytes(opts.hint.newTailId);
|
|
223
223
|
const fireAts = opts.jitter.scheduleWave(opts.subscribers.length, opts.now);
|
|
224
|
-
return opts.subscribers.map((s, i) => ({ newTailId,
|
|
224
|
+
return opts.subscribers.map((s, i) => ({ newTailId, lastRevision: s.lastRevision, fireAt: fireAts[i] }));
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
|
-
* Fold the outgoing
|
|
227
|
+
* Fold the outgoing root's replay buffer into the final {@link CheckpointSummary} handed to the new root
|
|
228
228
|
* (`docs/reactivity.md` §Tail rotation step 5 — the **only** state migration across a rotation). The
|
|
229
229
|
* handoff covers `[lastCheckpoint.toRevision + 1, rotationRevision]`: the revisions still live in the
|
|
230
230
|
* replay ring (above the rolling checkpoint's high edge) up to the rotation revision. Returns `undefined`
|
|
@@ -250,10 +250,10 @@ export function buildRotationHandoffCheckpoint(state, opts = {}) {
|
|
|
250
250
|
return { checkpoint, rotationRevision };
|
|
251
251
|
}
|
|
252
252
|
/**
|
|
253
|
-
* Land a {@link RotationHandoff} at the new
|
|
254
|
-
* `ResumeV1` whose span crosses the rotation is recoverable from the new
|
|
253
|
+
* Land a {@link RotationHandoff} at the new root's {@link PushState}: record the inherited checkpoint so a
|
|
254
|
+
* `ResumeV1` whose span crosses the rotation is recoverable from the new root (the new root "holds the old
|
|
255
255
|
* checkpoint", `docs/reactivity.md` §Tail rotation step 5). The handoff is a one-time migration — it does
|
|
256
|
-
* not feed the new
|
|
256
|
+
* not feed the new root's rolling checkpoint (that rolls from the new root's own replay-ring eviction).
|
|
257
257
|
*/
|
|
258
258
|
export function applyRotationHandoff(newTailState, handoff) {
|
|
259
259
|
newTailState.adoptRotationCheckpoint(handoff.checkpoint);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rotation.js","sourceRoot":"","sources":["../../../src/reactivity/rotation.ts"],"names":[],"mappings":"A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AAI,CAAC,gBAAgB,IAAI,QAAQ,CAAC;IAC3D,qGAAqG;IACrG,oGAAoG;IACpG,MAAM,iBAAiB,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC;IACtD,MAAM,IAAI,GAAG,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/E,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,sBAAsB,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACjF,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAAuB,EAAE,OAAwB;IACrF,YAAY,CAAC,uBAAuB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC1D,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,gBAAgB,CAAC,OAA0B,EAAE,QAAgB;IAC5E,OAAO,QAAQ,IAAI,OAAO,CAAC,YAAY,IAAI,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;AAC3E,CAAC"}
|
|
@@ -2,23 +2,26 @@
|
|
|
2
2
|
* Reactivity — subscriber-side subscription state (`docs/reactivity.md` §Subscription).
|
|
3
3
|
*
|
|
4
4
|
* Subscribing to a collection is an **ordinary cohort-topic registration** at tier T3 with a reactivity
|
|
5
|
-
* `appPayload`: `topicId = H(
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* `appPayload`: `topicId = H(collectionId ‖ "reactivity")` (stable for the collection's life), the tail
|
|
6
|
+
* block's routing key as the topic's `rootKey`, the configured TTL (Edge 60 s / Core 90 s), and the
|
|
7
|
+
* cohort-topic walk-toward-root / willingness / promotion / TTL-renewal all reused unchanged. This module
|
|
8
|
+
* owns only the subscriber-side bookkeeping struct and the `appPayload` builder; the db-p2p subscription
|
|
9
|
+
* manager drives the cohort-topic `RegisterV1`.
|
|
9
10
|
*
|
|
10
|
-
* `tailIdAtAttach` is the
|
|
11
|
-
*
|
|
11
|
+
* The payload's `tailIdAtAttach` is the tail at *that registration*; the subscriber itself keeps the latest
|
|
12
|
+
* tail it has followed (`tail` below), which is what detects a rotation (a delivered `tailId` or a
|
|
13
|
+
* `rotationHint` naming another tail) and what a resume names as `latestKnownTailId`. `cohortEpoch` detects
|
|
14
|
+
* membership drift within the topic.
|
|
12
15
|
*/
|
|
13
16
|
import { type SubscribeAppPayloadV1 } from "./wire.js";
|
|
14
17
|
/** Subscriber-side live state for one active subscription (`docs/reactivity.md` §Subscriber-side state). */
|
|
15
18
|
export interface ActiveSubscription {
|
|
16
19
|
/** Stable collection identity. */
|
|
17
20
|
readonly collectionId: Uint8Array;
|
|
18
|
-
/**
|
|
21
|
+
/** The collection's topic id — `H(collectionId ‖ "reactivity")`, stable for the collection's life. */
|
|
19
22
|
readonly topicId: Uint8Array;
|
|
20
|
-
/**
|
|
21
|
-
|
|
23
|
+
/** The latest tail block the subscription has followed: the topic's current root key, and what detects a rotation. */
|
|
24
|
+
tail: Uint8Array;
|
|
22
25
|
/** Serving cohort member. */
|
|
23
26
|
primary: Uint8Array;
|
|
24
27
|
/** Warm-failover cohort members. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../../src/reactivity/subscription.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../../src/reactivity/subscription.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAA6B,KAAK,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElF,4GAA4G;AAC5G,MAAM,WAAW,kBAAkB;IAClC,kCAAkC;IAClC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,sGAAsG;IACtG,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,sHAAsH;IACtH,IAAI,EAAE,UAAU,CAAC;IACjB,6BAA6B;IAC7B,OAAO,EAAE,UAAU,CAAC;IACpB,oCAAoC;IACpC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,iDAAiD;IACjD,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,mDAAmD;IACnD,WAAW,EAAE,UAAU,CAAC;IACxB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC/B,gCAAgC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,+CAA+C;IAC/C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAC/B;AAED,4EAA4E;AAC5E,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe,GAAG,qBAAqB,CAQvF;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe,GAAG,UAAU,CAE5E"}
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* Reactivity — subscriber-side subscription state (`docs/reactivity.md` §Subscription).
|
|
3
3
|
*
|
|
4
4
|
* Subscribing to a collection is an **ordinary cohort-topic registration** at tier T3 with a reactivity
|
|
5
|
-
* `appPayload`: `topicId = H(
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* `appPayload`: `topicId = H(collectionId ‖ "reactivity")` (stable for the collection's life), the tail
|
|
6
|
+
* block's routing key as the topic's `rootKey`, the configured TTL (Edge 60 s / Core 90 s), and the
|
|
7
|
+
* cohort-topic walk-toward-root / willingness / promotion / TTL-renewal all reused unchanged. This module
|
|
8
|
+
* owns only the subscriber-side bookkeeping struct and the `appPayload` builder; the db-p2p subscription
|
|
9
|
+
* manager drives the cohort-topic `RegisterV1`.
|
|
9
10
|
*
|
|
10
|
-
* `tailIdAtAttach` is the
|
|
11
|
-
*
|
|
11
|
+
* The payload's `tailIdAtAttach` is the tail at *that registration*; the subscriber itself keeps the latest
|
|
12
|
+
* tail it has followed (`tail` below), which is what detects a rotation (a delivered `tailId` or a
|
|
13
|
+
* `rotationHint` naming another tail) and what a resume names as `latestKnownTailId`. `cohortEpoch` detects
|
|
14
|
+
* membership drift within the topic.
|
|
12
15
|
*/
|
|
13
16
|
import { encodeSubscribeAppPayload } from "./wire.js";
|
|
14
17
|
/** Build the validated {@link SubscribeAppPayloadV1} for a subscription. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../src/reactivity/subscription.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../src/reactivity/subscription.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,yBAAyB,EAA8B,MAAM,WAAW,CAAC;AAsClF,4EAA4E;AAC5E,MAAM,UAAU,wBAAwB,CAAC,MAAuB;IAC/D,OAAO;QACN,IAAI,EAAE,YAAY;QAClB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC;QACtC,aAAa,EAAE,MAAM,CAAC,aAAa;KACnC,CAAC;AACH,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,wBAAwB,CAAC,MAAuB;IAC/D,OAAO,yBAAyB,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -1,46 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reactivity —
|
|
2
|
+
* Reactivity — the collection anchor: one topic per collection, a root that follows the tail.
|
|
3
3
|
*
|
|
4
4
|
* Transcribed from `docs/reactivity.md` §Anchor:
|
|
5
5
|
*
|
|
6
6
|
* ```
|
|
7
|
-
* topicId(
|
|
7
|
+
* topicId(C) = H(utf8(C.collectionId) ‖ "reactivity") (stable for the collection's life)
|
|
8
|
+
* coord_0 = H(tailId) (the root: the tail block's storage group; moves on rotation)
|
|
9
|
+
* coord_d(P) = H(d ‖ prefix(H(P), d·log₂F) ‖ topicId) (d ≥ 1; never moves)
|
|
8
10
|
* ```
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* the
|
|
13
|
-
* the
|
|
12
|
+
* Like matchmaking's `(kind, label)` anchor, the reactivity topic is **stable**: it is a function of the
|
|
13
|
+
* collection id alone, so the tiers below the root sit at fixed positions for the collection's life. What
|
|
14
|
+
* moves is the **root**. The root (announcing) group is the tail block's own storage group — the machines
|
|
15
|
+
* that apply, and so announce, the collection's commits — at `H(tailId)`, the ring position the key network
|
|
16
|
+
* places the tail by. When the tail block fills and a new one is born, the root moves to the new tail's
|
|
17
|
+
* storage group and nothing else does: a rotation is "same topic, the root moved"
|
|
18
|
+
* (`docs/reactivity.md` §Tail rotation).
|
|
14
19
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* Both derivations use the **same** {@link IRingHash} primitive cohort-topic uses for `coord_d` input —
|
|
21
|
+
* db-core's own SHA-256 truncated to the ring width, **not** a FRET import — because the topic id is fed
|
|
22
|
+
* verbatim into cohort-topic tier addressing (`coord_d(self, topicId)`) and the root coordinate must equal the
|
|
23
|
+
* key network's placement of the tail block byte for byte. The trailing `"reactivity"` literal domain-separates
|
|
24
|
+
* the topic from any other application anchoring on the same collection id, and from the root coordinate,
|
|
25
|
+
* which hashes the bare tail bytes. Concatenation is delimiter-free, exactly as the spec writes it; the
|
|
26
|
+
* constant suffix is unambiguous because no collection-id byte string can alias a `(collectionId, "reactivity")`
|
|
27
|
+
* pair of a different length.
|
|
19
28
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* ([reactivity-rotation-backpressure-policy]) reuses per-emission — define it here, not at the call site.
|
|
29
|
+
* `collectionId` is the UTF-8 of the id exactly as blocks carry it (`header.collectionId`, e.g. `app/users`) —
|
|
30
|
+
* the same bytes a notification's `collectionId` encodes (`reactivityCollectionIdBytes` in db-p2p's
|
|
31
|
+
* `reactivity/topic-bytes.ts`). Origination and every subscriber derive the topic from those bytes, so a
|
|
32
|
+
* notification routes to exactly the managers watching its collection.
|
|
25
33
|
*/
|
|
26
|
-
import type { IRingHash } from "../cohort-topic/ports.js";
|
|
34
|
+
import type { IRingHash, RingCoord } from "../cohort-topic/ports.js";
|
|
27
35
|
/**
|
|
28
|
-
* `H(
|
|
29
|
-
* reactivity tree
|
|
30
|
-
*
|
|
31
|
-
* The shared helper consumed by subscriber attachment, origination, and (per-emission) the rotation
|
|
32
|
-
* ticket. `hash` defaults to db-core's own 256-bit SHA-256, byte-identical to the cohort-topic host's.
|
|
36
|
+
* `H(collectionId ‖ "reactivity")` over the injected ring hash — the cohort-topic `topicId` of a collection's
|
|
37
|
+
* reactivity tree, stable for the collection's life. `collectionId` is the UTF-8 of the id as blocks carry it.
|
|
38
|
+
* `hash` defaults to db-core's own 256-bit SHA-256, byte-identical to the cohort-topic host's.
|
|
33
39
|
*/
|
|
34
|
-
export declare function
|
|
35
|
-
/** Derives the rotating `topicId` for a collection's current tail. */
|
|
36
|
-
export interface ReactivityTopicAnchor {
|
|
37
|
-
/** `H(tailId ‖ "reactivity")` for the given tail block id (bytes). */
|
|
38
|
-
topicId(tailId: Uint8Array): Uint8Array;
|
|
39
|
-
}
|
|
40
|
+
export declare function reactivityCollectionTopicId(collectionId: Uint8Array, hash?: IRingHash): Uint8Array;
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* The reactivity root coordinate for a tail: `H(tailId)` over the injected ring hash — the tail block's
|
|
43
|
+
* own ring position, where its storage group sits. `tailId` is the tail's routing key bytes (the raw utf8
|
|
44
|
+
* of the block id, `reactivityTailBytes` on a node), so at the default 256-bit ring width this equals the
|
|
45
|
+
* key network's `hashKey(routingKeyForBlock(tail))` byte for byte; the `topic-bytes-encoding` spec in
|
|
46
|
+
* db-p2p pins that equality. Every party that derives the root group — the notification verifier, the
|
|
47
|
+
* subscriber walk's root step, the forwarder's gossip and recover reads — must start from this one value.
|
|
48
|
+
* It is the one coordinate of a collection's tree that changes when the tail rotates.
|
|
44
49
|
*/
|
|
45
|
-
export declare function
|
|
50
|
+
export declare function reactivityRootCoord(tailId: Uint8Array, hash?: IRingHash): RingCoord;
|
|
46
51
|
//# sourceMappingURL=topic-anchor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic-anchor.d.ts","sourceRoot":"","sources":["../../../src/reactivity/topic-anchor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"topic-anchor.d.ts","sourceRoot":"","sources":["../../../src/reactivity/topic-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAOrE;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,UAAU,EAAE,IAAI,GAAE,SAA4B,GAAG,UAAU,CAMpH;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE,SAA4B,GAAG,SAAS,CAErG"}
|
|
@@ -1,61 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reactivity —
|
|
2
|
+
* Reactivity — the collection anchor: one topic per collection, a root that follows the tail.
|
|
3
3
|
*
|
|
4
4
|
* Transcribed from `docs/reactivity.md` §Anchor:
|
|
5
5
|
*
|
|
6
6
|
* ```
|
|
7
|
-
* topicId(
|
|
7
|
+
* topicId(C) = H(utf8(C.collectionId) ‖ "reactivity") (stable for the collection's life)
|
|
8
|
+
* coord_0 = H(tailId) (the root: the tail block's storage group; moves on rotation)
|
|
9
|
+
* coord_d(P) = H(d ‖ prefix(H(P), d·log₂F) ‖ topicId) (d ≥ 1; never moves)
|
|
8
10
|
* ```
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* the
|
|
13
|
-
* the
|
|
12
|
+
* Like matchmaking's `(kind, label)` anchor, the reactivity topic is **stable**: it is a function of the
|
|
13
|
+
* collection id alone, so the tiers below the root sit at fixed positions for the collection's life. What
|
|
14
|
+
* moves is the **root**. The root (announcing) group is the tail block's own storage group — the machines
|
|
15
|
+
* that apply, and so announce, the collection's commits — at `H(tailId)`, the ring position the key network
|
|
16
|
+
* places the tail by. When the tail block fills and a new one is born, the root moves to the new tail's
|
|
17
|
+
* storage group and nothing else does: a rotation is "same topic, the root moved"
|
|
18
|
+
* (`docs/reactivity.md` §Tail rotation).
|
|
14
19
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* Both derivations use the **same** {@link IRingHash} primitive cohort-topic uses for `coord_d` input —
|
|
21
|
+
* db-core's own SHA-256 truncated to the ring width, **not** a FRET import — because the topic id is fed
|
|
22
|
+
* verbatim into cohort-topic tier addressing (`coord_d(self, topicId)`) and the root coordinate must equal the
|
|
23
|
+
* key network's placement of the tail block byte for byte. The trailing `"reactivity"` literal domain-separates
|
|
24
|
+
* the topic from any other application anchoring on the same collection id, and from the root coordinate,
|
|
25
|
+
* which hashes the bare tail bytes. Concatenation is delimiter-free, exactly as the spec writes it; the
|
|
26
|
+
* constant suffix is unambiguous because no collection-id byte string can alias a `(collectionId, "reactivity")`
|
|
27
|
+
* pair of a different length.
|
|
19
28
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* ([reactivity-rotation-backpressure-policy]) reuses per-emission — define it here, not at the call site.
|
|
29
|
+
* `collectionId` is the UTF-8 of the id exactly as blocks carry it (`header.collectionId`, e.g. `app/users`) —
|
|
30
|
+
* the same bytes a notification's `collectionId` encodes (`reactivityCollectionIdBytes` in db-p2p's
|
|
31
|
+
* `reactivity/topic-bytes.ts`). Origination and every subscriber derive the topic from those bytes, so a
|
|
32
|
+
* notification routes to exactly the managers watching its collection.
|
|
25
33
|
*/
|
|
26
34
|
import { createRingHash } from "../cohort-topic/ring-hash.js";
|
|
27
|
-
|
|
35
|
+
import { createTierAddressing } from "../cohort-topic/addressing.js";
|
|
36
|
+
/** Domain-separation suffix mixed into the reactivity topic. */
|
|
28
37
|
const REACTIVITY_SUFFIX = "reactivity";
|
|
29
38
|
const utf8 = new TextEncoder();
|
|
30
39
|
/**
|
|
31
|
-
* `H(
|
|
32
|
-
* reactivity tree
|
|
33
|
-
*
|
|
34
|
-
* The shared helper consumed by subscriber attachment, origination, and (per-emission) the rotation
|
|
35
|
-
* ticket. `hash` defaults to db-core's own 256-bit SHA-256, byte-identical to the cohort-topic host's.
|
|
40
|
+
* `H(collectionId ‖ "reactivity")` over the injected ring hash — the cohort-topic `topicId` of a collection's
|
|
41
|
+
* reactivity tree, stable for the collection's life. `collectionId` is the UTF-8 of the id as blocks carry it.
|
|
42
|
+
* `hash` defaults to db-core's own 256-bit SHA-256, byte-identical to the cohort-topic host's.
|
|
36
43
|
*/
|
|
37
|
-
export function
|
|
44
|
+
export function reactivityCollectionTopicId(collectionId, hash = createRingHash()) {
|
|
38
45
|
const suffixBytes = utf8.encode(REACTIVITY_SUFFIX);
|
|
39
|
-
const input = new Uint8Array(
|
|
40
|
-
input.set(
|
|
41
|
-
input.set(suffixBytes,
|
|
46
|
+
const input = new Uint8Array(collectionId.length + suffixBytes.length);
|
|
47
|
+
input.set(collectionId, 0);
|
|
48
|
+
input.set(suffixBytes, collectionId.length);
|
|
42
49
|
return hash.H(input);
|
|
43
50
|
}
|
|
44
|
-
class HashReactivityTopicAnchor {
|
|
45
|
-
hash;
|
|
46
|
-
constructor(hash) {
|
|
47
|
-
this.hash = hash;
|
|
48
|
-
}
|
|
49
|
-
topicId(tailId) {
|
|
50
|
-
return reactivityTopicId(tailId, this.hash);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
51
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
52
|
+
* The reactivity root coordinate for a tail: `H(tailId)` over the injected ring hash — the tail block's
|
|
53
|
+
* own ring position, where its storage group sits. `tailId` is the tail's routing key bytes (the raw utf8
|
|
54
|
+
* of the block id, `reactivityTailBytes` on a node), so at the default 256-bit ring width this equals the
|
|
55
|
+
* key network's `hashKey(routingKeyForBlock(tail))` byte for byte; the `topic-bytes-encoding` spec in
|
|
56
|
+
* db-p2p pins that equality. Every party that derives the root group — the notification verifier, the
|
|
57
|
+
* subscriber walk's root step, the forwarder's gossip and recover reads — must start from this one value.
|
|
58
|
+
* It is the one coordinate of a collection's tree that changes when the tail rotates.
|
|
57
59
|
*/
|
|
58
|
-
export function
|
|
59
|
-
return
|
|
60
|
+
export function reactivityRootCoord(tailId, hash = createRingHash()) {
|
|
61
|
+
return createTierAddressing(hash).rootCoord(tailId);
|
|
60
62
|
}
|
|
61
63
|
//# sourceMappingURL=topic-anchor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic-anchor.js","sourceRoot":"","sources":["../../../src/reactivity/topic-anchor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"topic-anchor.js","sourceRoot":"","sources":["../../../src/reactivity/topic-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAGrE,gEAAgE;AAChE,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAEvC,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,YAAwB,EAAE,OAAkB,cAAc,EAAE;IACvG,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACvE,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IAC3B,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAkB,EAAE,OAAkB,cAAc,EAAE;IACzF,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC"}
|