@serfab/cadre-core 1.17.0 → 1.19.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 (148) hide show
  1. package/README.md +3 -2
  2. package/dist/cadre-invite-protocol.d.ts +35 -13
  3. package/dist/cadre-invite-protocol.js +90 -25
  4. package/dist/cadre-invite-protocol.js.map +1 -1
  5. package/dist/cadre-node.d.ts +586 -255
  6. package/dist/cadre-node.js +1182 -566
  7. package/dist/cadre-node.js.map +1 -1
  8. package/dist/control-cohort.d.ts +66 -9
  9. package/dist/control-cohort.js +67 -9
  10. package/dist/control-cohort.js.map +1 -1
  11. package/dist/control-database.d.ts +451 -193
  12. package/dist/control-database.js +701 -359
  13. package/dist/control-database.js.map +1 -1
  14. package/dist/control-formation-recorder.d.ts +46 -43
  15. package/dist/control-formation-recorder.js +77 -78
  16. package/dist/control-formation-recorder.js.map +1 -1
  17. package/dist/control-protocol-guard.d.ts +6 -0
  18. package/dist/control-protocol-guard.js +14 -2
  19. package/dist/control-protocol-guard.js.map +1 -1
  20. package/dist/control-schema-version.d.ts +48 -31
  21. package/dist/control-schema-version.js +67 -45
  22. package/dist/control-schema-version.js.map +1 -1
  23. package/dist/control-schema.d.ts +8 -8
  24. package/dist/control-schema.js +16 -16
  25. package/dist/control-schema.js.map +1 -1
  26. package/dist/control-write-retry.d.ts +42 -7
  27. package/dist/control-write-retry.js +87 -19
  28. package/dist/control-write-retry.js.map +1 -1
  29. package/dist/enrolled-machine-store.d.ts +3 -3
  30. package/dist/enrolled-machine-store.js +3 -3
  31. package/dist/formation-token.d.ts +48 -0
  32. package/dist/formation-token.js +26 -0
  33. package/dist/formation-token.js.map +1 -0
  34. package/dist/index.d.ts +15 -14
  35. package/dist/index.js +17 -14
  36. package/dist/index.js.map +1 -1
  37. package/dist/joined-strand-store.d.ts +26 -9
  38. package/dist/joined-strand-store.js +63 -24
  39. package/dist/joined-strand-store.js.map +1 -1
  40. package/dist/link-budget.d.ts +9 -7
  41. package/dist/link-budget.js +9 -7
  42. package/dist/link-budget.js.map +1 -1
  43. package/dist/member-redemption.d.ts +15 -9
  44. package/dist/member-redemption.js +13 -8
  45. package/dist/member-redemption.js.map +1 -1
  46. package/dist/membership-view.d.ts +91 -0
  47. package/dist/membership-view.js +110 -0
  48. package/dist/membership-view.js.map +1 -0
  49. package/dist/owner-grant-protocol.d.ts +11 -7
  50. package/dist/owner-grant-protocol.js +31 -17
  51. package/dist/owner-grant-protocol.js.map +1 -1
  52. package/dist/peer-addr-book.d.ts +10 -1
  53. package/dist/peer-addr-book.js +4 -3
  54. package/dist/peer-addr-book.js.map +1 -1
  55. package/dist/peer-join-backfill.d.ts +96 -30
  56. package/dist/peer-join-backfill.js +272 -128
  57. package/dist/peer-join-backfill.js.map +1 -1
  58. package/dist/pending-join-runner.d.ts +48 -18
  59. package/dist/pending-join-runner.js +74 -56
  60. package/dist/pending-join-runner.js.map +1 -1
  61. package/dist/seed-bootstrap.d.ts +47 -40
  62. package/dist/seed-bootstrap.js +66 -61
  63. package/dist/seed-bootstrap.js.map +1 -1
  64. package/dist/self-address-update.d.ts +13 -0
  65. package/dist/self-address-update.js +19 -0
  66. package/dist/self-address-update.js.map +1 -0
  67. package/dist/strand-database.d.ts +23 -2
  68. package/dist/strand-database.js +26 -6
  69. package/dist/strand-database.js.map +1 -1
  70. package/dist/strand-first-sync-gate.d.ts +176 -89
  71. package/dist/strand-first-sync-gate.js +288 -122
  72. package/dist/strand-first-sync-gate.js.map +1 -1
  73. package/dist/strand-formation-deadlines.d.ts +9 -9
  74. package/dist/strand-formation-deadlines.js +9 -9
  75. package/dist/strand-formation-manager.d.ts +23 -17
  76. package/dist/strand-formation-manager.js +46 -44
  77. package/dist/strand-formation-manager.js.map +1 -1
  78. package/dist/strand-formation-protocol.d.ts +5 -8
  79. package/dist/strand-formation-protocol.js +101 -16
  80. package/dist/strand-formation-protocol.js.map +1 -1
  81. package/dist/strand-instance-manager.d.ts +26 -17
  82. package/dist/strand-instance-manager.js +119 -50
  83. package/dist/strand-instance-manager.js.map +1 -1
  84. package/dist/strand-membership-reconciler.d.ts +16 -13
  85. package/dist/strand-membership-reconciler.js +28 -22
  86. package/dist/strand-membership-reconciler.js.map +1 -1
  87. package/dist/strand-membership-writer.d.ts +40 -28
  88. package/dist/strand-membership-writer.js +212 -153
  89. package/dist/strand-membership-writer.js.map +1 -1
  90. package/dist/strand-move.js +5 -2
  91. package/dist/strand-move.js.map +1 -1
  92. package/dist/strand-revocation-enforcer.d.ts +134 -60
  93. package/dist/strand-revocation-enforcer.js +144 -71
  94. package/dist/strand-revocation-enforcer.js.map +1 -1
  95. package/dist/strand-solicitation.d.ts +50 -39
  96. package/dist/strand-solicitation.js +10 -3
  97. package/dist/strand-solicitation.js.map +1 -1
  98. package/dist/strand-watcher.d.ts +80 -13
  99. package/dist/strand-watcher.js +152 -48
  100. package/dist/strand-watcher.js.map +1 -1
  101. package/dist/table-change-watch.d.ts +63 -0
  102. package/dist/table-change-watch.js +209 -0
  103. package/dist/table-change-watch.js.map +1 -0
  104. package/dist/timeout-scheduler.d.ts +4 -3
  105. package/dist/timeout-scheduler.js +4 -3
  106. package/dist/timeout-scheduler.js.map +1 -1
  107. package/dist/types.d.ts +90 -49
  108. package/dist/types.js +4 -4
  109. package/dist/types.js.map +1 -1
  110. package/package.json +8 -8
  111. package/src/cadre-invite-protocol.ts +119 -31
  112. package/src/cadre-node.ts +1289 -588
  113. package/src/control-cohort.ts +86 -9
  114. package/src/control-database.ts +848 -403
  115. package/src/control-formation-recorder.ts +359 -353
  116. package/src/control-protocol-guard.ts +16 -2
  117. package/src/control-schema-version.ts +101 -51
  118. package/src/control-schema.ts +16 -16
  119. package/src/control-write-retry.ts +91 -19
  120. package/src/delegate-admission.ts +351 -351
  121. package/src/enrolled-machine-store.ts +3 -3
  122. package/src/formation-token.ts +63 -0
  123. package/src/index.ts +30 -18
  124. package/src/joined-strand-store.ts +69 -24
  125. package/src/link-budget.ts +9 -7
  126. package/src/member-redemption.ts +20 -13
  127. package/src/membership-view.ts +144 -0
  128. package/src/owner-grant-protocol.ts +33 -18
  129. package/src/peer-addr-book.ts +4 -3
  130. package/src/peer-join-backfill.ts +961 -761
  131. package/src/pending-join-runner.ts +76 -53
  132. package/src/seed-bootstrap.ts +72 -67
  133. package/src/self-address-update.ts +19 -0
  134. package/src/strand-database.ts +352 -322
  135. package/src/strand-first-sync-gate.ts +334 -134
  136. package/src/strand-formation-deadlines.ts +227 -227
  137. package/src/strand-formation-manager.ts +731 -725
  138. package/src/strand-formation-protocol.ts +122 -24
  139. package/src/strand-instance-manager.ts +2092 -2026
  140. package/src/strand-membership-reconciler.ts +31 -25
  141. package/src/strand-membership-writer.ts +2093 -2019
  142. package/src/strand-move.ts +5 -2
  143. package/src/strand-revocation-enforcer.ts +740 -654
  144. package/src/strand-solicitation.ts +61 -34
  145. package/src/strand-watcher.ts +175 -56
  146. package/src/table-change-watch.ts +285 -0
  147. package/src/timeout-scheduler.ts +29 -28
  148. package/src/types.ts +89 -51
@@ -24,17 +24,46 @@
24
24
  import type { CohortPeerRow } from './strand-cohort.js';
25
25
 
26
26
  /**
27
- * Default recurring cadence for {@link CadreNode.reconcileControlCohort} (ms).
28
- * In the same spirit as the 5s strand-watch poll but lighter, since a control
29
- * cohort changes far less often than strand activity.
27
+ * Default backstop for {@link CadreNode.reconcileControlCohort} (ms): a pass runs this long
28
+ * after the last one settled whether or not anything woke it. Passes normally run on a
29
+ * change — a membership table changing, a sibling connecting or disconnecting, an address
30
+ * change — and on the retries a pass arms for itself ({@link nextReconcileWakeMs}); the
31
+ * backstop bounds how stale this node can be after a change it hears nothing of: one that
32
+ * reaches it with no storage event, which happens to a machine outside the block's cohort
33
+ * (a cadre larger than `CONTROL_REPLICATION_BREADTH`) and to one in the cohort that the
34
+ * writer could not reach when it committed. The membership rows view's maximum age
35
+ * (`MEMBERSHIP_VIEW_MAX_AGE_MS`, 15 s) is shorter than this, so the backstop pass reads
36
+ * storage and starts the cohort consult that brings such a change in.
30
37
  *
31
- * An interval between pass starts, not a deadline on a pass. Passes are
32
- * single-flight, so a pass that runs longer than this is joined rather than
33
- * stacked, and the effective cadence becomes the pass length: one unreachable
34
- * sibling's dial alone can take the whole per-peer dial budget (86 s at the
35
- * default declared link).
38
+ * `network.controlCohort.reconcileMs` overrides it. An interval between a pass settling and
39
+ * the next start, not a deadline on a pass: passes are single-flight, and one unreachable
40
+ * sibling's dial alone can take the whole per-peer dial budget (86 s at the default
41
+ * declared link).
42
+ *
43
+ * NOTE: a machine whose storage takes no event for a change — one outside the block's cohort
44
+ * in a cadre larger than `CONTROL_REPLICATION_BREADTH` (16 machines), or one the writer could
45
+ * not reach when it committed — sees it only at this backstop, where the change-driven path
46
+ * serves a machine the commit reached within the 50 ms coalescing window. If a party ever
47
+ * needs a tighter bound, lower the backstop for its nodes or give the plugin's change bridge
48
+ * a path for outside-the-cohort reads.
49
+ */
50
+ export const DEFAULT_CONTROL_COHORT_RECONCILE_MS = 120_000;
51
+
52
+ /**
53
+ * First redial delay after a pass's dial of a selected sibling, or a cold-start bootstrap peer,
54
+ * fails (ms). Doubles per consecutive such pass and is capped at the backstop, so a
55
+ * sibling that is offline costs one dial per backstop once the ladder saturates, and a
56
+ * stranded cold-start node keeps trying forever (15 s, 30 s, 60 s, then every backstop).
36
57
  */
37
- export const DEFAULT_CONTROL_COHORT_RECONCILE_MS = 15_000;
58
+ export const CONTROL_COHORT_REDIAL_MS = 15_000;
59
+
60
+ /**
61
+ * How often an owner retries a node it has just claimed while that node restarts into the
62
+ * owner's party (ms; `CadreNode.claimNode`). A poll step, not a deadline: the retries run for
63
+ * {@link CONTROL_COHORT_REDIAL_MS} after the node accepts the claim, the delay of the reconcile
64
+ * pass's first redial, which would otherwise be the owner's next dial of the node.
65
+ */
66
+ export const CLAIM_RESTART_REDIAL_STEP_MS = 1_000;
38
67
 
39
68
  /**
40
69
  * Default cap on the number of **non-backbone** members a single reconcile pass
@@ -125,3 +154,51 @@ export function selectControlCohortDials(
125
154
  cappedNonBackbone: rest.length - fill.length,
126
155
  };
127
156
  }
157
+
158
+ /** What {@link nextReconcileWakeMs} decides from, all times epoch milliseconds. */
159
+ export interface ReconcileWakeInput {
160
+ /**
161
+ * Consecutive passes, this one included, whose dial of a selected sibling or a cold-start
162
+ * bootstrap peer failed; 0 when none of this pass's dials did.
163
+ */
164
+ redialStreak: number;
165
+ /** When the pass that just ended began. */
166
+ passStartedAt: number;
167
+ /** Every (sibling, strand) strand-address due time this node holds. */
168
+ strandAddrDueAt: Iterable<number>;
169
+ now: number;
170
+ /** The scheduler's backstop (ms); no wake is later than it. */
171
+ backstopMs: number;
172
+ }
173
+
174
+ /**
175
+ * How long after a pass the next one should run for the pass's own reasons, or `undefined`
176
+ * when the backstop covers everything:
177
+ *
178
+ * - **Redial.** A streak of unconnected passes wakes after
179
+ * `min(CONTROL_COHORT_REDIAL_MS × 2^(streak − 1), backstop)`.
180
+ * - **Strand addresses.** The earliest strand-address due time LATER THAN the pass's start,
181
+ * when it is sooner than the backstop, wakes when it falls due (now at the latest). A due
182
+ * time at or before the start belongs to a (sibling, strand) the pass skipped for another
183
+ * reason — the strand stopped, the sibling disconnected — and waking for it would spin; the
184
+ * strand watcher's launch retry keeps the same rule.
185
+ *
186
+ * The smaller wins.
187
+ */
188
+ export function nextReconcileWakeMs(input: ReconcileWakeInput): number | undefined {
189
+ const { redialStreak, passStartedAt, strandAddrDueAt, now, backstopMs } = input;
190
+ let wake: number | undefined;
191
+ if (redialStreak > 0) {
192
+ wake = Math.min(CONTROL_COHORT_REDIAL_MS * 2 ** (redialStreak - 1), backstopMs);
193
+ }
194
+ for (const dueAt of strandAddrDueAt) {
195
+ if (dueAt <= passStartedAt) {
196
+ continue;
197
+ }
198
+ const delay = Math.max(0, dueAt - now);
199
+ if (delay < backstopMs && (wake === undefined || delay < wake)) {
200
+ wake = delay;
201
+ }
202
+ }
203
+ return wake;
204
+ }