@serfab/cadre-core 1.21.0 → 1.23.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 (109) hide show
  1. package/README.md +294 -294
  2. package/dist/cadre-node.d.ts +334 -53
  3. package/dist/cadre-node.js +794 -85
  4. package/dist/cadre-node.js.map +1 -1
  5. package/dist/control-authorization.d.ts +32 -2
  6. package/dist/control-authorization.js +19 -0
  7. package/dist/control-authorization.js.map +1 -1
  8. package/dist/control-database.d.ts +236 -23
  9. package/dist/control-database.js +587 -173
  10. package/dist/control-database.js.map +1 -1
  11. package/dist/control-schema.d.ts +3 -3
  12. package/dist/control-schema.js +71 -7
  13. package/dist/control-schema.js.map +1 -1
  14. package/dist/ed25519-key.d.ts +8 -0
  15. package/dist/ed25519-key.js +11 -1
  16. package/dist/ed25519-key.js.map +1 -1
  17. package/dist/index.d.ts +5 -1
  18. package/dist/index.js +13 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/machine-removal.d.ts +51 -1
  21. package/dist/machine-removal.js +42 -1
  22. package/dist/machine-removal.js.map +1 -1
  23. package/dist/membership-connection-gater.d.ts +8 -0
  24. package/dist/membership-connection-gater.js +13 -1
  25. package/dist/membership-connection-gater.js.map +1 -1
  26. package/dist/membership-view.js +4 -1
  27. package/dist/membership-view.js.map +1 -1
  28. package/dist/owner-keys.js +2 -1
  29. package/dist/owner-keys.js.map +1 -1
  30. package/dist/owner-signer.js +3 -4
  31. package/dist/owner-signer.js.map +1 -1
  32. package/dist/peer-authorization.d.ts +14 -2
  33. package/dist/peer-authorization.js +24 -1
  34. package/dist/peer-authorization.js.map +1 -1
  35. package/dist/sealed-party-key.d.ts +32 -0
  36. package/dist/sealed-party-key.js +162 -0
  37. package/dist/sealed-party-key.js.map +1 -0
  38. package/dist/seed-bootstrap.d.ts +10 -3
  39. package/dist/seed-bootstrap.js +12 -0
  40. package/dist/seed-bootstrap.js.map +1 -1
  41. package/dist/strand-addr-protocol.d.ts +56 -6
  42. package/dist/strand-addr-protocol.js +57 -5
  43. package/dist/strand-addr-protocol.js.map +1 -1
  44. package/dist/strand-commit-durability.d.ts +33 -2
  45. package/dist/strand-commit-durability.js +44 -4
  46. package/dist/strand-commit-durability.js.map +1 -1
  47. package/dist/strand-database.d.ts +35 -5
  48. package/dist/strand-database.js +34 -10
  49. package/dist/strand-database.js.map +1 -1
  50. package/dist/strand-instance-manager.d.ts +200 -18
  51. package/dist/strand-instance-manager.js +434 -64
  52. package/dist/strand-instance-manager.js.map +1 -1
  53. package/dist/strand-membership-reconciler.d.ts +250 -51
  54. package/dist/strand-membership-reconciler.js +410 -66
  55. package/dist/strand-membership-reconciler.js.map +1 -1
  56. package/dist/strand-membership-writer.d.ts +7 -0
  57. package/dist/strand-membership-writer.js +9 -0
  58. package/dist/strand-membership-writer.js.map +1 -1
  59. package/dist/strand-party-key-rotation.d.ts +177 -0
  60. package/dist/strand-party-key-rotation.js +340 -0
  61. package/dist/strand-party-key-rotation.js.map +1 -0
  62. package/dist/strand-party-machines.d.ts +111 -0
  63. package/dist/strand-party-machines.js +258 -0
  64. package/dist/strand-party-machines.js.map +1 -0
  65. package/dist/strand-party-peers.d.ts +101 -0
  66. package/dist/strand-party-peers.js +49 -0
  67. package/dist/strand-party-peers.js.map +1 -0
  68. package/dist/strand-peer-redial.d.ts +34 -7
  69. package/dist/strand-peer-redial.js +46 -13
  70. package/dist/strand-peer-redial.js.map +1 -1
  71. package/dist/strand-revocation-enforcer.d.ts +15 -1
  72. package/dist/strand-revocation-enforcer.js +16 -9
  73. package/dist/strand-revocation-enforcer.js.map +1 -1
  74. package/dist/strand-transport-key.js +3 -0
  75. package/dist/strand-transport-key.js.map +1 -1
  76. package/dist/strand-watcher.d.ts +7 -4
  77. package/dist/strand-watcher.js +12 -7
  78. package/dist/strand-watcher.js.map +1 -1
  79. package/dist/types.d.ts +169 -13
  80. package/dist/types.js.map +1 -1
  81. package/package.json +9 -8
  82. package/src/cadre-node.ts +12280 -11528
  83. package/src/control-authorization.ts +41 -1
  84. package/src/control-database.ts +6123 -5603
  85. package/src/control-schema.ts +71 -7
  86. package/src/ed25519-key.ts +12 -1
  87. package/src/index.ts +957 -924
  88. package/src/machine-removal.ts +80 -1
  89. package/src/membership-connection-gater.ts +13 -1
  90. package/src/membership-view.ts +4 -1
  91. package/src/owner-keys.ts +2 -1
  92. package/src/owner-signer.ts +92 -94
  93. package/src/peer-authorization.ts +27 -3
  94. package/src/sealed-party-key.ts +190 -0
  95. package/src/seed-bootstrap.ts +17 -3
  96. package/src/strand-addr-protocol.ts +67 -6
  97. package/src/strand-commit-durability.ts +54 -5
  98. package/src/strand-database.ts +47 -11
  99. package/src/strand-instance-manager.ts +524 -65
  100. package/src/strand-membership-reconciler.ts +1310 -942
  101. package/src/strand-membership-writer.ts +10 -0
  102. package/src/strand-party-key-rotation.ts +436 -0
  103. package/src/strand-party-machines.ts +293 -0
  104. package/src/strand-party-peers.ts +129 -0
  105. package/src/strand-peer-redial.ts +61 -14
  106. package/src/strand-revocation-enforcer.ts +27 -9
  107. package/src/strand-transport-key.ts +3 -0
  108. package/src/strand-watcher.ts +12 -7
  109. package/src/types.ts +3121 -2963
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Party key rotation: the driver that moves a party onto a fresh membership key in one closed
3
+ * strand after a machine was removed from the cadre, so the removed machine is left holding a
4
+ * key that is no longer a member there (docs/architecture.md → "Removing a machine").
5
+ *
6
+ * ## What it rests on
7
+ *
8
+ * - A `Strand.MemberPeer` binding is signed by the member key, which every machine of the
9
+ * party holds, so any party machine can bind any peer id under the party's key. Which peer
10
+ * ids are the party's remaining machines, and which the removed machine's, is the control
11
+ * record's `StrandPeer` rows joined to the live machines (`strand-party-peers.ts`).
12
+ * - The revoked-peer gate (`strand-revocation-enforcer.ts`) denies a peer id only when it has
13
+ * an orphaned binding and no live one. A remaining machine bound under both the old key K and
14
+ * the new key K' stays served when K leaves; the removed machine, bound under K alone, is
15
+ * denied on the rows alone, with no new gate logic.
16
+ * - `leaveStrand` is self-signed by the departing key, and `removeManager`'s resign branch
17
+ * needs another manager standing. So K can remove itself once K' is a manager, and no second
18
+ * party is involved in a strand the party manages.
19
+ * - The founder bootstrap skips `Member` and `Manager` when either table has rows, so a founder
20
+ * restart after a rotation never tries to re-seat K' as a founding row.
21
+ *
22
+ * ## Where the new key lives before it is current
23
+ *
24
+ * The removal transaction writes a `PendingStrandPartyKey` row per closed strand the party holds
25
+ * a key for, in the same owner approval as the machine's tombstone (`ControlDatabase.removeMachine`),
26
+ * so the removal and the intent to rotate are exactly as durable as each other. That same
27
+ * transaction reaches the removed machine, so the row carries K' public half in the clear and its
28
+ * private half sealed to the identity keys of the machines that remain (`sealed-party-key.ts`);
29
+ * `CadreNode` opens it under this machine's identity key before handing it to the driver
30
+ * ({@link StrandPartyKeyRotationDeps.readPending}), and a machine the key was not sealed to
31
+ * cannot drive. That row is the run's input; the `StrandPartyKey` row stays K until the last step.
32
+ *
33
+ * ## One run
34
+ *
35
+ * Runs on an OWNER machine that runs the strand and can open the pending key (an owner signer is
36
+ * enrolled, the instance is live with a database, the key is sealed to this machine's identity);
37
+ * `CadreNode` decides that and never asks any other machine to drive.
38
+ * Each run reads the pending row and the strand's rows and continues from wherever the state
39
+ * says it is. Every step reads before it writes, and a duplicate-row rejection counts as done,
40
+ * so two owner machines driving one strand converge:
41
+ *
42
+ * 1. **Clean up superseded keys.** A second removal while a rotation is pending replaced the
43
+ * pending key, and the replaced key may already hold a seat (a driver seated it before the
44
+ * replacement). For each public key in `Superseded` that holds a `Member` row: `removeManager`
45
+ * by K if it holds a `Manager` row, then `revokeMember` by K. Its bindings become orphans
46
+ * beside K's, harmless to remaining machines, which are bound under K and then K'. A
47
+ * superseded key that IS the current key is skipped: another driver finished the earlier
48
+ * rotation and this one continues from it.
49
+ * 2. **Seat K'.** `addMemberByManager(K, K')`. When K holds no `Manager` row and K' is not yet a
50
+ * member, the run stops here as `needs-another-party` (one event per pending stamp) and the
51
+ * row stays: K' is seated from outside, by the membership reconciler redeeming the host's fresh
52
+ * invitation under K' (`strand-membership-reconciler.ts` → "Redeeming under the pending key")
53
+ * or by the strand's manager admitting K' by hand, and the reconciler kicks this driver when
54
+ * it sees the seat (docs/strands.md → Replacing the party's key). The run then continues from
55
+ * step 3; step 4 is skipped, since K is no manager, and step 5 is K's self-signed leave alone.
56
+ * 3. **Bind under K'**: this machine's own strand peer id and every live sibling's, each
57
+ * `registerMemberPeer(K', id)` (insert-if-absent). Self-signed by K', so this step also runs
58
+ * after K has left.
59
+ * 4. **Promote K'**: `addManager(K, K')`, when K is a manager. After the bindings, so a key that
60
+ * was seated but never bound cannot exist beyond step 2.
61
+ * 5. **K steps down**: `removeManager`'s resign branch signed by K (K' now stands, so the sole
62
+ * manager guard does not fire), then `leaveStrand` signed by K. The removed machine's binding
63
+ * under K is now the orphan; remaining machines are live under K'.
64
+ * 6. **Swap the control row**, one transaction and one owner approval across every strand whose
65
+ * steps 1 to 5 completed in this run ({@link StrandPartyKeyRotationDeps.swapKeys}). Deferred
66
+ * while a control write could fork the party, like every background control write; the
67
+ * strands are reported `pending` and the growth drain re-runs them. After the swap the
68
+ * running instance is re-keyed and `strand:party-key-rotated` is emitted.
69
+ *
70
+ * Crash recovery is the same run: pending row present and K' not a member → step 2; K' a member
71
+ * but K still one → steps 3 to 5 as needed; K gone from the strand, control still K → step 6;
72
+ * no pending row → nothing. A run that finds K' already current (another driver swapped) ends.
73
+ *
74
+ * ## Single flight
75
+ *
76
+ * One run per strand at a time: a call that names a strand already being driven waits for that
77
+ * run's outcome rather than starting a second. Strands in one call are prepared one after
78
+ * another and swapped together.
79
+ */
80
+ import debug from 'debug';
81
+ import { strandMemberKeyPair } from './strand-member-key.js';
82
+ import { addManager, addMemberByManager, isStrandManager, isStrandMember, leaveStrand, listMemberPeers, registerMemberPeer, removeManager, revokeMember, } from './strand-membership-writer.js';
83
+ import { describeThrown } from './describe-thrown.js';
84
+ const log = debug('sereus:cadre:strand-party-key-rotation');
85
+ /** Every strand write here runs in a transaction of its own, never joining one the app has open. */
86
+ const OWN_TRANSACTION = { joinOpenTransaction: false };
87
+ export class StrandPartyKeyRotationDriver {
88
+ constructor(deps) {
89
+ this.deps = deps;
90
+ /** The run in flight per strand; a call naming the strand joins it. */
91
+ this.inFlight = new Map();
92
+ /** The pending stamp each strand's `needs-another-party` was last reported for. */
93
+ this.reportedBlocked = new Map();
94
+ }
95
+ /**
96
+ * Drive every strand in `strandIds` through the steps its state calls for, then swap the
97
+ * control rows of the ones that finished in one transaction. Never rejects: a strand whose
98
+ * step failed is `pending` with a log, and the next trigger re-runs it.
99
+ */
100
+ async drive(strandIds, cause) {
101
+ const ids = [...new Set(strandIds)];
102
+ const joined = ids.filter((strandId) => this.inFlight.has(strandId));
103
+ const fresh = ids.filter((strandId) => !this.inFlight.has(strandId));
104
+ const outcomes = new Map();
105
+ if (fresh.length > 0) {
106
+ for (const [strandId, outcome] of await this.startRun(fresh, cause)) {
107
+ outcomes.set(strandId, outcome);
108
+ }
109
+ }
110
+ if (joined.length > 0) {
111
+ // The run in flight read its pending rows before this call was made, so a row written
112
+ // since (a second removal) would otherwise wait for the next trigger: the joined strands
113
+ // are driven again once it ends. A strand with nothing left costs one pending read.
114
+ await Promise.all(joined.map((strandId) => this.inFlight.get(strandId)));
115
+ for (const outcome of await this.drive(joined, cause)) {
116
+ outcomes.set(outcome.strandId, outcome.outcome);
117
+ }
118
+ }
119
+ return ids.map((strandId) => ({ strandId, outcome: outcomes.get(strandId) ?? 'pending' }));
120
+ }
121
+ /** Start one run and register it as the run in flight for each of its strands until it ends. `run` never rejects, so neither does the registration. */
122
+ startRun(strandIds, cause) {
123
+ const run = this.run(strandIds, cause);
124
+ for (const strandId of strandIds) {
125
+ const own = run.then((result) => result.get(strandId) ?? 'pending');
126
+ this.inFlight.set(strandId, own);
127
+ void own.finally(() => {
128
+ if (this.inFlight.get(strandId) === own) {
129
+ this.inFlight.delete(strandId);
130
+ }
131
+ });
132
+ }
133
+ return run;
134
+ }
135
+ /** Steps 1 to 5 per strand, then one swap over the ready ones. */
136
+ async run(strandIds, cause) {
137
+ log('Party key rotation run over %d strand(s) (%s)', strandIds.length, cause);
138
+ const outcomes = new Map();
139
+ const ready = [];
140
+ for (const strandId of strandIds) {
141
+ const prepared = await this.prepare(strandId);
142
+ switch (prepared.kind) {
143
+ case 'ready':
144
+ ready.push(prepared.entry);
145
+ break;
146
+ case 'blocked':
147
+ outcomes.set(strandId, 'needs-another-party');
148
+ this.reportBlocked(strandId, prepared.stampId);
149
+ break;
150
+ case 'nothing':
151
+ outcomes.set(strandId, 'rotated');
152
+ break;
153
+ case 'failed':
154
+ outcomes.set(strandId, 'pending');
155
+ log('Party key rotation of strand %s left unfinished (retried on the next trigger): %s', strandId, describeThrown(prepared.error));
156
+ break;
157
+ }
158
+ }
159
+ for (const [strandId, outcome] of await this.swap(ready)) {
160
+ outcomes.set(strandId, outcome);
161
+ }
162
+ return outcomes;
163
+ }
164
+ /** Step 6 for every ready strand, then the re-key of each one swapped. */
165
+ async swap(ready) {
166
+ const outcomes = new Map();
167
+ if (ready.length === 0) {
168
+ return outcomes;
169
+ }
170
+ let swapped;
171
+ try {
172
+ const result = await this.deps.swapKeys(ready);
173
+ if (result === 'deferred') {
174
+ log('Party key swap of %d strand(s) deferred: no sibling reachable and the party has other members; re-run on growth', ready.length);
175
+ for (const entry of ready) {
176
+ outcomes.set(entry.strandId, 'pending');
177
+ }
178
+ return outcomes;
179
+ }
180
+ swapped = result;
181
+ }
182
+ catch (error) {
183
+ log('Party key swap of %d strand(s) failed (retried on the next trigger): %s', ready.length, describeThrown(error));
184
+ for (const entry of ready) {
185
+ outcomes.set(entry.strandId, 'pending');
186
+ }
187
+ return outcomes;
188
+ }
189
+ for (const entry of ready) {
190
+ // An entry the swap skipped names a key already current (another driver swapped it), or a
191
+ // row that moved on; either way the strand's rows are on the new key, so it is rotated.
192
+ outcomes.set(entry.strandId, 'rotated');
193
+ if (swapped.includes(entry.strandId)) {
194
+ await this.notifyRotated(entry);
195
+ }
196
+ }
197
+ return outcomes;
198
+ }
199
+ /**
200
+ * The re-key after a committed swap. A failure is logged and the strand stays `rotated`: the
201
+ * control row names the new key, and the party key watch re-keys the instance from it on its
202
+ * next run (`CadreNode.onPartyKeyTablesChanged`).
203
+ */
204
+ async notifyRotated(entry) {
205
+ try {
206
+ await this.deps.onRotated(entry.strandId, entry.newKey);
207
+ }
208
+ catch (error) {
209
+ log('Party key rotation of strand %s: re-keying the running instance after the swap failed (the party key watch retries it): %s', entry.strandId, describeThrown(error));
210
+ }
211
+ }
212
+ /** Steps 1 to 5 for one strand, from the state its rows are in. */
213
+ async prepare(strandId) {
214
+ try {
215
+ const pending = await this.deps.readPending(strandId);
216
+ if (pending === null) {
217
+ return { kind: 'nothing' };
218
+ }
219
+ const current = await this.deps.readCurrentKey(strandId);
220
+ if (current === null) {
221
+ log('Party key rotation of strand %s: the party holds no key there; nothing to rotate', strandId);
222
+ return { kind: 'nothing' };
223
+ }
224
+ if (current === pending.privateKey) {
225
+ return { kind: 'nothing' };
226
+ }
227
+ const db = this.deps.getDatabase(strandId);
228
+ if (db === undefined) {
229
+ return { kind: 'failed', error: new Error('the strand does not run here now') };
230
+ }
231
+ const state = await readRotationState(db, current, pending.privateKey);
232
+ await this.cleanUpSuperseded(db, state, pending.superseded);
233
+ if (!state.newIsMember) {
234
+ if (!state.oldIsManager) {
235
+ return { kind: 'blocked', stampId: pending.stampId };
236
+ }
237
+ await addMemberByManager(db, { managerKeyPair: state.oldKey, memberKey: state.newKey.publicKeyB64 }, OWN_TRANSACTION);
238
+ log('Party key rotation of strand %s: new key seated as member', strandId);
239
+ }
240
+ await this.bindMachines(strandId, db, state.newKey);
241
+ if (state.oldIsManager && !state.newIsManager) {
242
+ await addManager(db, { byManagerKeyPair: state.oldKey, newManagerKey: state.newKey.publicKeyB64 }, OWN_TRANSACTION);
243
+ log('Party key rotation of strand %s: new key promoted to manager', strandId);
244
+ }
245
+ await stepDown(db, state);
246
+ return { kind: 'ready', entry: { strandId, oldKey: current, newKey: pending.privateKey } };
247
+ }
248
+ catch (error) {
249
+ return { kind: 'failed', error };
250
+ }
251
+ }
252
+ /**
253
+ * Step 1: a superseded key holding a seat is revoked by K. Skips the current key itself
254
+ * (another driver finished the rotation it was pending for) and, when K holds no manager seat,
255
+ * leaves the seat with a log for the other party's manager.
256
+ *
257
+ * NOTE: a superseded key that holds a seat in a strand the party does not manage can only be
258
+ * revoked by that strand's manager: the row carries superseded PUBLIC halves only, so this
259
+ * driver cannot `leaveStrand` as that key. Fine now, since reaching it takes a second removal
260
+ * between the host's re-admission of the first pending key and the swap that follows it within
261
+ * seconds on the redeeming owner machine. If it is ever hit, seal the superseded private halves
262
+ * into the row too, so the driver can self-leave them.
263
+ */
264
+ async cleanUpSuperseded(db, state, superseded) {
265
+ for (const key of superseded) {
266
+ if (key === state.oldKey.publicKeyB64 || key === state.newKey.publicKeyB64 || !await isStrandMember(db, key)) {
267
+ continue;
268
+ }
269
+ if (!state.oldIsManager) {
270
+ log('Superseded party key %s still holds a seat and this party has no manager seat to revoke it; left for the other party\'s manager', key);
271
+ continue;
272
+ }
273
+ if (await isStrandManager(db, key)) {
274
+ await removeManager(db, { byManagerKeyPair: state.oldKey, targetManagerKey: key }, OWN_TRANSACTION);
275
+ }
276
+ await revokeMember(db, { managerKeyPair: state.oldKey, memberKey: key }, OWN_TRANSACTION);
277
+ log('Superseded party key %s revoked', key);
278
+ }
279
+ }
280
+ /** Step 3: every remaining machine's peer id bound under the new key; bindings already present are skipped. */
281
+ async bindMachines(strandId, db, newKey) {
282
+ const own = this.deps.getOwnPeerId(strandId);
283
+ const ids = new Set(await this.deps.readSiblingPeerIds(strandId));
284
+ if (own !== undefined) {
285
+ ids.add(own);
286
+ }
287
+ const bound = new Set(await listMemberPeers(db, newKey.publicKeyB64));
288
+ for (const peerId of ids) {
289
+ if (!bound.has(peerId)) {
290
+ await registerMemberPeer(db, { memberKeyPair: newKey, peerId }, OWN_TRANSACTION);
291
+ log('Party key rotation of strand %s: %s bound under the new key', strandId, peerId);
292
+ }
293
+ }
294
+ }
295
+ reportBlocked(strandId, stampId) {
296
+ if (this.reportedBlocked.get(strandId) === stampId) {
297
+ return;
298
+ }
299
+ this.reportedBlocked.set(strandId, stampId);
300
+ log('Party key rotation of strand %s blocked: this party holds no manager seat there, so another party\'s manager has to admit the new key', strandId);
301
+ try {
302
+ this.deps.onBlocked(strandId, 'needs-another-party');
303
+ }
304
+ catch (error) {
305
+ log('Party key rotation of strand %s: the blocked report threw: %s', strandId, describeThrown(error));
306
+ }
307
+ }
308
+ }
309
+ /** The rows steps 1 to 5 decide from, read before any write. */
310
+ async function readRotationState(db, currentKey, pendingKey) {
311
+ const oldKey = strandMemberKeyPair(currentKey);
312
+ const newKey = strandMemberKeyPair(pendingKey);
313
+ return {
314
+ oldKey,
315
+ newKey,
316
+ oldIsMember: await isStrandMember(db, oldKey.publicKeyB64),
317
+ oldIsManager: await isStrandManager(db, oldKey.publicKeyB64),
318
+ newIsMember: await isStrandMember(db, newKey.publicKeyB64),
319
+ newIsManager: await isStrandManager(db, newKey.publicKeyB64),
320
+ };
321
+ }
322
+ /**
323
+ * Step 5: K resigns its manager seat, then leaves. Both writers are no-ops over an absent row,
324
+ * so a run that finds K already gone writes nothing here. The resign runs only when K' holds a
325
+ * manager seat, so the strand never loses its last manager to this step.
326
+ */
327
+ async function stepDown(db, state) {
328
+ if (!state.oldIsMember) {
329
+ return;
330
+ }
331
+ if (state.oldIsManager) {
332
+ if (!await isStrandManager(db, state.newKey.publicKeyB64)) {
333
+ throw new Error('the new party key holds no manager seat, so the old key cannot resign without emptying the strand\'s managers');
334
+ }
335
+ await removeManager(db, { byManagerKeyPair: state.oldKey, targetManagerKey: state.oldKey.publicKeyB64 }, OWN_TRANSACTION);
336
+ }
337
+ await leaveStrand(db, { memberKeyPair: state.oldKey }, OWN_TRANSACTION);
338
+ log('Old party key %s left the strand', state.oldKey.publicKeyB64);
339
+ }
340
+ //# sourceMappingURL=strand-party-key-rotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strand-party-key-rotation.js","sourceRoot":"","sources":["../src/strand-party-key-rotation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,YAAY,GAEb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,GAAG,GAAG,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAE5D,oGAAoG;AACpG,MAAM,eAAe,GAAuB,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC;AA2E3E,MAAM,OAAO,4BAA4B;IAMvC,YAA6B,IAAgC;QAAhC,SAAI,GAAJ,IAAI,CAA4B;QAL7D,uEAAuE;QACtD,aAAQ,GAAG,IAAI,GAAG,EAAoC,CAAC;QACxE,mFAAmF;QAClE,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEG,CAAC;IAEjE;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,SAA4B,EAAE,KAAa;QACrD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrE,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,E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EAAE,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,eAAe,CAAC,CAAC;IAC5H,CAAC;IACD,MAAM,WAAW,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC;IACxE,GAAG,CAAC,kCAAkC,EAAE,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The party's other machines known to hold one strand, and the offline queue's gate that waits
3
+ * for them (`docs/strands.md` → Waiting for the party's own machines).
4
+ *
5
+ * Why. Optimystic's own reachability gate (`KeyNetworkCohortReachability` in db-p2p) knows only
6
+ * the peers this strand node has itself met and seen serve the network. A sibling of the party
7
+ * that this node has never connected to is not among them, so with the sibling's port blocked
8
+ * the gate answers "genuinely alone" and a queued transaction is committed by this machine
9
+ * alone. The party's control database knows better: every machine that runs the strand has
10
+ * written a `CadreControl.StrandPeer` row for it (`strand-party-peers.ts`), so the machines a
11
+ * queued transaction must not be committed without are the live, trusted machines with such a
12
+ * row.
13
+ *
14
+ * What it does. {@link StrandPartyMachines} keeps the last good read of those machines, read
15
+ * through the launch's `PartyStrandPeerSource` at bring-up and again whenever the control
16
+ * database's party tables change (`StrandInstanceManager.notifyPartyPeersChanged`).
17
+ * {@link cohortGateWaitingForMachines} composes the node's gate with it: a block whose cohort
18
+ * names nobody but this node is unreachable while the party has a machine holding the strand.
19
+ * The composed gate is registered with the strand connection's collection factory
20
+ * (`StrandConnectionOptions.cohortReachability`), where the queue and the offline live-read
21
+ * path both ask it. Only a node offering offline mode builds either.
22
+ *
23
+ * Removal. The same read names the machines removed from the cadre. Optimystic's own gate, which
24
+ * runs first, keeps waiting for a machine its strand node remembers or was seeded with, so
25
+ * `StrandInstanceManager` refuses a removed machine's peer id as a member, and
26
+ * {@link watchRemovedMachinesInSeed} asks for a rebuild when one is in the running node's seed.
27
+ */
28
+ import type { ICohortReachability, IKeyNetwork } from '@optimystic/db-core';
29
+ import type { PartyStrandPeer, PartyStrandPeerSource } from './strand-party-peers.js';
30
+ export interface StrandPartyMachinesDeps {
31
+ /** Names the strand in logs. */
32
+ label: string;
33
+ source: Pick<PartyStrandPeerSource, 'read'>;
34
+ }
35
+ /**
36
+ * The party's other machines known to hold one strand, from the last good read of the control
37
+ * database. Built per runtime build, before the strand's node, and stopped with the runtime.
38
+ *
39
+ * NOTE: a machine that stops running the strand but stays in the cadre (its filter changed, its
40
+ * app was removed, `stopStrand`) keeps its `StrandPeer` row, so it keeps counting here until it
41
+ * is removed from the cadre, as a peer that never returns keeps counting in Optimystic's own
42
+ * gate. If operators hit this, add a strand-address reply saying the filter excludes the strand,
43
+ * and drop a machine that answers so.
44
+ *
45
+ * NOTE: {@link settled} waits on the first control read, and the gate waits on it, so a stalled
46
+ * read would stall the queue and offline live reads with it. The read is the local one
47
+ * `connectedSiblingTargets`' NOTE in `cadre-node.ts` measured in milliseconds; if a control read
48
+ * ever can stall, bound this one and answer "no machines" past the bound.
49
+ */
50
+ export declare class StrandPartyMachines {
51
+ private readonly deps;
52
+ private last;
53
+ private lastRemoved;
54
+ private failed;
55
+ private inFlight;
56
+ /** A refresh asked while a read was in flight: one more read follows, so no change is missed. */
57
+ private again;
58
+ private stopped;
59
+ /** One entry per `onChange` call, so a listener subscribed twice is two subscriptions. */
60
+ private readonly listeners;
61
+ private readonly firstRead;
62
+ private settleFirstRead;
63
+ constructor(deps: StrandPartyMachinesDeps);
64
+ /** Read again now: coalesced, one read in flight. A failed read logs and keeps the last answer. */
65
+ refresh(): void;
66
+ /** Settles once the first read has finished, either way. */
67
+ settled(): Promise<void>;
68
+ /** The last good read's live machines; empty before one. */
69
+ machines(): readonly PartyStrandPeer[];
70
+ /** The strand peer ids of machines removed from the cadre, from the last good read; empty before one. */
71
+ removed(): ReadonlySet<string>;
72
+ /** Whether the most recent read failed, so the answer in {@link machines} may be stale. */
73
+ lastReadFailed(): boolean;
74
+ /** Called only when the live machines or the removed ids change. Returns an idempotent unsubscribe. */
75
+ onChange(listener: () => void): () => void;
76
+ /** Drops every listener; a read in flight keeps nothing. */
77
+ stop(): void;
78
+ private read;
79
+ }
80
+ /**
81
+ * Call `onFound` when `machines` names a removed machine that is in `seedPeers`, the peers of the
82
+ * launch seed this runtime's node was built with, so that the node is rebuilt from a fresh seed.
83
+ * A rebuild is the only remedy: the node's seed is frozen, and Optimystic reads a refused seed peer
84
+ * that serves the network as not yet heard from for the node's whole life (`heardFromBootstrapPeer`).
85
+ *
86
+ * `announced` is the strand's memory across its runtimes of the ids a rebuild was asked for, so an
87
+ * id still in the rebuilt node's seed asks once and not on every build. Ids this seed does not name
88
+ * are forgotten, so a machine removed, re-added, seeded again and removed again asks again.
89
+ *
90
+ * NOTE: a fresh seed should never name a removed machine: its sources are the answers of live
91
+ * siblings and a formation's addresses, which are another party's. The exception is a removed
92
+ * machine still configured as this node's relay and still answering the strand-addr RPC. The hold
93
+ * then stays and the log says why; the remedy is to take it out of `network.relayAddrs`.
94
+ */
95
+ export declare function watchRemovedMachinesInSeed(machines: Pick<StrandPartyMachines, 'removed' | 'onChange'>, seedPeers: ReadonlySet<string>, announced: Set<string>, onFound: () => void, label: string): void;
96
+ /** The slice of {@link StrandPartyMachines} the composed gate reads. */
97
+ export type CohortGateMachines = Pick<StrandPartyMachines, 'settled' | 'machines' | 'lastReadFailed' | 'refresh' | 'onChange'>;
98
+ /**
99
+ * `inner` (the node's gate), closed also while this node is alone in a block's cohort and the
100
+ * party has machines holding the strand. In order: `inner` closed answers closed and nothing
101
+ * further is read; then the first machine read is awaited, and a failed last read is asked again
102
+ * (the retry rides the asker's own re-check, so no timer here); no machines answers open;
103
+ * otherwise every distinct block's cohort is read from the key network, and one naming nobody
104
+ * but this node, or one whose lookup throws, answers closed.
105
+ *
106
+ * The test is "alone in the cohort", not "a machine is unconnected": with one sibling connected
107
+ * and another blocked the cohort has two members, the commit runs on it, and nothing is held.
108
+ * The same goes for another party's member being connected. `onChange` forwards both the node
109
+ * gate's wakes and a change of the machines.
110
+ */
111
+ export declare function cohortGateWaitingForMachines(inner: ICohortReachability, keyNetwork: Pick<IKeyNetwork, 'findCluster'>, selfId: string, machines: CohortGateMachines): ICohortReachability;