@serfab/cadre-core 1.23.0 → 1.24.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.
- package/README.md +216 -294
- package/dist/arachnode-stub.d.ts +12 -4
- package/dist/arachnode-stub.js +15 -8
- package/dist/arachnode-stub.js.map +1 -1
- package/dist/cadre-invite-protocol.js +5 -4
- package/dist/cadre-invite-protocol.js.map +1 -1
- package/dist/cadre-node.d.ts +145 -44
- package/dist/cadre-node.js +239 -79
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +14 -2
- package/dist/control-authorization.js +8 -3
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-cohort.d.ts +27 -13
- package/dist/control-cohort.js +21 -14
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +18 -16
- package/dist/control-database.js +57 -22
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.d.ts +1 -1
- package/dist/control-protocol-guard.js +7 -3
- package/dist/control-protocol-guard.js.map +1 -1
- package/dist/control-read-retry.d.ts +49 -11
- package/dist/control-read-retry.js +56 -15
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-retry.d.ts +32 -3
- package/dist/control-retry.js +35 -4
- package/dist/control-retry.js.map +1 -1
- package/dist/control-schema-version.d.ts +5 -5
- package/dist/control-schema-version.js +5 -5
- package/dist/control-schema-version.js.map +1 -1
- package/dist/control-schema.d.ts +5 -5
- package/dist/control-schema.js +1032 -1011
- package/dist/control-schema.js.map +1 -1
- package/dist/control-write-retry.d.ts +54 -65
- package/dist/control-write-retry.js +134 -158
- package/dist/control-write-retry.js.map +1 -1
- package/dist/delegate-admission.d.ts +1 -1
- package/dist/delegate-admission.js +1 -1
- package/dist/edge-node/config.d.ts +4 -3
- package/dist/edge-node/config.js +11 -9
- package/dist/edge-node/config.js.map +1 -1
- package/dist/edge-node/dissolve.d.ts +4 -4
- package/dist/edge-node/dissolve.js +4 -4
- package/dist/edge-node/edge-join.d.ts +1 -1
- package/dist/edge-node/edge-join.js +1 -1
- package/dist/edge-node/edge-node.js +2 -2
- package/dist/edge-node/edge-node.js.map +1 -1
- package/dist/edge-node/index.d.ts +1 -0
- package/dist/edge-node/index.js +1 -0
- package/dist/edge-node/index.js.map +1 -1
- package/dist/edge-node/join-credential.d.ts +1 -1
- package/dist/edge-node/join-credential.js +1 -1
- package/dist/edge-node/lazy-raw-storage.js +12 -0
- package/dist/edge-node/lazy-raw-storage.js.map +1 -1
- package/dist/edge-node/listen-addrs.d.ts +21 -0
- package/dist/edge-node/listen-addrs.js +25 -0
- package/dist/edge-node/listen-addrs.js.map +1 -0
- package/dist/edge-node/owner-grant.d.ts +1 -1
- package/dist/edge-node/owner-grant.js +1 -1
- package/dist/edge-node/platform.d.ts +5 -4
- package/dist/edge-node/platform.js.map +1 -1
- package/dist/edge-node/strand-move.d.ts +1 -1
- package/dist/edge-node/strand-move.js +1 -1
- package/dist/edge-node/strands.js +27 -11
- package/dist/edge-node/strands.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/invitation-bootstrap.d.ts +28 -5
- package/dist/invitation-bootstrap.js +41 -8
- package/dist/invitation-bootstrap.js.map +1 -1
- package/dist/link-budget.d.ts +53 -4
- package/dist/link-budget.js +58 -5
- package/dist/link-budget.js.map +1 -1
- package/dist/machine-removal.d.ts +2 -2
- package/dist/machine-removal.js +4 -3
- package/dist/machine-removal.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +2 -2
- package/dist/membership-connection-gater.js +2 -2
- package/dist/membership-view.d.ts +2 -2
- package/dist/membership-view.js +2 -2
- package/dist/node-claim-payload.d.ts +15 -7
- package/dist/node-claim-payload.js +25 -9
- package/dist/node-claim-payload.js.map +1 -1
- package/dist/node-class.d.ts +36 -0
- package/dist/node-class.js +26 -0
- package/dist/node-class.js.map +1 -0
- package/dist/node-default-transports.d.ts +50 -3
- package/dist/node-default-transports.js +48 -3
- package/dist/node-default-transports.js.map +1 -1
- package/dist/node-roles.d.ts +118 -0
- package/dist/node-roles.js +142 -0
- package/dist/node-roles.js.map +1 -0
- package/dist/node-transports.d.ts +6 -2
- package/dist/node-transports.js +39 -7
- package/dist/node-transports.js.map +1 -1
- package/dist/owner-anchor-sync.js +1 -1
- package/dist/owner-key-export.js +1 -1
- package/dist/owner-key-flows.d.ts +1 -1
- package/dist/owner-key-store.js +1 -1
- package/dist/owner-signer.js +1 -1
- package/dist/peer-authorization.d.ts +3 -1
- package/dist/peer-authorization.js +3 -1
- package/dist/peer-authorization.js.map +1 -1
- package/dist/peer-dial.d.ts +74 -10
- package/dist/peer-dial.js +89 -17
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.js +4 -4
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +34 -9
- package/dist/peer-record.js +66 -13
- package/dist/peer-record.js.map +1 -1
- package/dist/pending-join-runner.d.ts +1 -1
- package/dist/pending-join-runner.js +1 -1
- package/dist/provider/client.d.ts +6 -5
- package/dist/provider/client.js +3 -3
- package/dist/provider/client.js.map +1 -1
- package/dist/provider/descriptor.d.ts +1 -1
- package/dist/provider/descriptor.js +1 -1
- package/dist/provider/oauth.d.ts +1 -1
- package/dist/provider/oauth.js +1 -1
- package/dist/provider/rent-node.d.ts +4 -3
- package/dist/provider/rent-node.js +3 -3
- package/dist/provider/rent-node.js.map +1 -1
- package/dist/relay-addrs.d.ts +62 -7
- package/dist/relay-addrs.js +74 -11
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +1 -1
- package/dist/relay-reservation.js +1 -1
- package/dist/relay-server.d.ts +6 -5
- package/dist/relay-server.js +5 -5
- package/dist/relay-server.js.map +1 -1
- package/dist/schema-verification.d.ts +13 -10
- package/dist/schema-verification.js +32 -24
- package/dist/schema-verification.js.map +1 -1
- package/dist/sealed-party-key.js +1 -1
- package/dist/seed-bootstrap.d.ts +4 -3
- package/dist/seed-bootstrap.js +6 -7
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +8 -6
- package/dist/strand-addr-protocol.js +12 -10
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-app-schema-report.d.ts +16 -2
- package/dist/strand-app-schema-report.js +15 -0
- package/dist/strand-app-schema-report.js.map +1 -1
- package/dist/strand-cohort.d.ts +1 -4
- package/dist/strand-cohort.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +1 -1
- package/dist/strand-database.d.ts +13 -6
- package/dist/strand-database.js +17 -9
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +3 -2
- package/dist/strand-first-sync-gate.js +3 -2
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-deadlines.d.ts +2 -2
- package/dist/strand-formation-deadlines.js +2 -2
- package/dist/strand-formation-protocol.d.ts +1 -1
- package/dist/strand-formation-protocol.js +51 -16
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +67 -33
- package/dist/strand-instance-manager.js +164 -55
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +8 -3
- package/dist/strand-membership-reconciler.js +8 -3
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +2 -2
- package/dist/strand-membership-writer.js +41 -39
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-move.js +1 -1
- package/dist/strand-network-config.d.ts +15 -5
- package/dist/strand-network-config.js +7 -6
- package/dist/strand-network-config.js.map +1 -1
- package/dist/strand-party-key-rotation.d.ts +7 -3
- package/dist/strand-party-key-rotation.js +7 -3
- package/dist/strand-party-key-rotation.js.map +1 -1
- package/dist/strand-party-machines.d.ts +19 -8
- package/dist/strand-party-machines.js +26 -11
- package/dist/strand-party-machines.js.map +1 -1
- package/dist/strand-party-peers.d.ts +36 -14
- package/dist/strand-party-peers.js +24 -15
- package/dist/strand-party-peers.js.map +1 -1
- package/dist/strand-peer-redial.d.ts +1 -1
- package/dist/strand-peer-redial.js +1 -1
- package/dist/strand-reactivity.d.ts +20 -17
- package/dist/strand-reactivity.js +31 -18
- package/dist/strand-reactivity.js.map +1 -1
- package/dist/strand-revocation-enforcer.d.ts +3 -3
- package/dist/strand-revocation-enforcer.js +3 -3
- package/dist/strand-wake-protocol.d.ts +19 -7
- package/dist/strand-wake-protocol.js +22 -10
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/strand-watcher.d.ts +1 -1
- package/dist/strand-watcher.js +1 -1
- package/dist/table-change-watch.js +1 -1
- package/dist/types.d.ts +116 -55
- package/dist/types.js.map +1 -1
- package/dist/webrtc-upgrade.d.ts +254 -0
- package/dist/webrtc-upgrade.js +355 -0
- package/dist/webrtc-upgrade.js.map +1 -0
- package/package.json +9 -9
- package/src/announce-addrs.ts +93 -93
- package/src/arachnode-stub.ts +18 -10
- package/src/bootstrap-peer-store-file.ts +44 -44
- package/src/bootstrap-peer-store.ts +214 -214
- package/src/cadre-invite-protocol.ts +741 -740
- package/src/cadre-node.ts +12462 -12280
- package/src/claim-proof.ts +147 -147
- package/src/control-authorization.ts +290 -276
- package/src/control-cohort.ts +223 -204
- package/src/control-database.ts +72 -28
- package/src/control-formation-recorder.ts +359 -359
- package/src/control-protocol-guard.ts +370 -366
- package/src/control-read-retry.ts +222 -180
- package/src/control-retry.ts +36 -4
- package/src/control-schema-version.ts +301 -301
- package/src/control-schema.ts +1108 -1087
- package/src/control-write-retry.ts +639 -669
- package/src/delegate-admission.ts +351 -351
- package/src/describe-thrown.ts +60 -60
- package/src/ed25519-key.ts +185 -185
- package/src/edge-node/config.ts +13 -10
- package/src/edge-node/dissolve.ts +252 -252
- package/src/edge-node/edge-join.ts +320 -320
- package/src/edge-node/edge-node.ts +1095 -1095
- package/src/edge-node/index.ts +60 -59
- package/src/edge-node/join-credential.ts +16 -16
- package/src/edge-node/lazy-raw-storage.ts +194 -178
- package/src/edge-node/listen-addrs.ts +26 -0
- package/src/edge-node/node-local.ts +84 -84
- package/src/edge-node/options.ts +195 -195
- package/src/edge-node/owner-grant.ts +63 -63
- package/src/edge-node/platform.ts +5 -4
- package/src/edge-node/strand-move.ts +266 -266
- package/src/edge-node/strands.ts +27 -12
- package/src/enrolled-machine-store-file.ts +43 -43
- package/src/enrolled-machine-store.ts +280 -280
- package/src/fetch-impl.ts +23 -23
- package/src/file-durable-slot.ts +64 -64
- package/src/file-safe-name.ts +32 -32
- package/src/formation-approval.ts +604 -604
- package/src/formation-token.ts +63 -63
- package/src/fs-atomic.ts +92 -92
- package/src/index.ts +987 -957
- package/src/invitation-bootstrap.ts +152 -118
- package/src/joined-strand-store.ts +553 -553
- package/src/key-store-file.ts +142 -142
- package/src/link-budget.ts +61 -5
- package/src/machine-removal.ts +211 -210
- package/src/member-redemption.ts +643 -643
- package/src/membership-connection-gater.ts +650 -650
- package/src/membership-view.ts +147 -147
- package/src/node-claim-payload.ts +34 -12
- package/src/node-class.ts +47 -0
- package/src/node-default-transports.ts +65 -3
- package/src/node-roles.ts +220 -0
- package/src/node-transports.ts +86 -49
- package/src/owner-anchor-sync.ts +172 -172
- package/src/owner-grant-protocol.ts +547 -547
- package/src/owner-key-export.ts +348 -348
- package/src/owner-key-flows.ts +109 -109
- package/src/owner-key-store.ts +1 -1
- package/src/owner-keys.ts +179 -179
- package/src/owner-signer.ts +92 -92
- package/src/peer-addr-book.ts +252 -252
- package/src/peer-authorization.ts +584 -582
- package/src/peer-dial.ts +698 -605
- package/src/peer-join-backfill.ts +961 -961
- package/src/peer-record.ts +71 -16
- package/src/pending-join-runner.ts +798 -798
- package/src/primary-lan-address.ts +47 -47
- package/src/provider/client.ts +327 -326
- package/src/provider/descriptor.ts +129 -129
- package/src/provider/index.ts +59 -59
- package/src/provider/oauth.ts +285 -285
- package/src/provider/rent-node.ts +276 -275
- package/src/relay-addrs.ts +90 -12
- package/src/relay-reservation.ts +1 -1
- package/src/relay-server.ts +99 -98
- package/src/schema-verification.ts +38 -23
- package/src/sealed-party-key.ts +190 -190
- package/src/seed-bootstrap.ts +8 -11
- package/src/seed-trust-policy.ts +353 -353
- package/src/self-address-update.ts +19 -19
- package/src/strand-addr-protocol.ts +17 -14
- package/src/strand-app-schema-report.ts +147 -122
- package/src/strand-cohort.ts +1 -5
- package/src/strand-commit-durability.ts +165 -165
- package/src/strand-database.ts +522 -510
- package/src/strand-first-sync-gate.ts +3 -2
- package/src/strand-formation-deadlines.ts +227 -227
- package/src/strand-formation-manager.ts +731 -731
- package/src/strand-formation-protocol.ts +1174 -1138
- package/src/strand-fret-addrs.ts +179 -179
- package/src/strand-instance-manager.ts +188 -63
- package/src/strand-membership-reconciler.ts +1315 -1310
- package/src/strand-membership-writer.ts +2152 -2150
- package/src/strand-move.ts +1 -1
- package/src/strand-network-config.ts +16 -6
- package/src/strand-offline.ts +178 -178
- package/src/strand-party-key-rotation.ts +440 -436
- package/src/strand-party-machines.ts +308 -293
- package/src/strand-party-peers.ts +151 -129
- package/src/strand-peer-redial.ts +1 -1
- package/src/strand-reactivity.ts +36 -19
- package/src/strand-revocation-enforcer.ts +758 -758
- package/src/strand-wake-protocol.ts +406 -394
- package/src/strand-watcher.ts +1 -1
- package/src/table-change-watch.ts +285 -285
- package/src/timed-step.ts +28 -28
- package/src/timeout-scheduler.ts +29 -29
- package/src/trusted-owner-store.ts +242 -242
- package/src/types.ts +3182 -3121
- package/src/webrtc-upgrade.ts +439 -0
|
@@ -1,180 +1,222 @@
|
|
|
1
|
-
import { BlockUnavailableError } from '@optimystic/db-core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `
|
|
28
|
-
* `
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* a
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* `
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* {@link
|
|
89
|
-
* {@link
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* `
|
|
130
|
-
* `
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
1
|
+
import { BlockUnavailableError } from '@optimystic/db-core';
|
|
2
|
+
import { FindCoordinatorError } from '@optimystic/db-p2p';
|
|
3
|
+
import { causeChain, reportsUnreachableCohort, retryControlOperation } from './control-retry.js';
|
|
4
|
+
import type { ControlRetryOptions } from './control-retry.js';
|
|
5
|
+
import { isUncommittedTransactorAggregate } from './control-write-retry.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Bounded retry for TRANSIENT control-read failures — the classifier and policy behind
|
|
9
|
+
* `ControlDatabase.readRows`, the single funnel every control read passes through.
|
|
10
|
+
*
|
|
11
|
+
* Why this exists: control WRITES have absorbed transient cluster failures since
|
|
12
|
+
* `control-write-retry.ts` landed, but a read had no second chance — one stream reset
|
|
13
|
+
* during a scan ended the read outright (measured: a rigged single `eval` failure killed
|
|
14
|
+
* `queryRevokedStamps` after exactly one attempt while the same injection against `exec`
|
|
15
|
+
* was absorbed). This module gives reads the same bounded re-presentation with a SHORTER
|
|
16
|
+
* deadline and a NARROWER failure set, because the tightest caller deadline over a control
|
|
17
|
+
* read is the inbound admission gate's 2 s fail-open timeout
|
|
18
|
+
* (`ADMISSION_DECISION_TIMEOUT_MS`, `link-budget.ts`) — a read budget that
|
|
19
|
+
* does not fit inside it with headroom spends its retries after the gate has already
|
|
20
|
+
* admitted.
|
|
21
|
+
*
|
|
22
|
+
* This is deliberately NOT "the write classifier minus its commit veto" — the retriable
|
|
23
|
+
* set differs in both directions (see {@link isRetriableControlReadFailure}). The loop
|
|
24
|
+
* lives in `control-retry.ts`, shared with the write policy; this module owns only the
|
|
25
|
+
* read policy. A block-unavailability failure is matched by TYPE: `OptimysticVirtualTable`
|
|
26
|
+
* rethrows a scan failure through `rewrapAsQueryError`
|
|
27
|
+
* (`quereus-plugin-optimystic/src/optimystic-module.ts`), which keeps the typed
|
|
28
|
+
* `BlockUnavailableError` on `cause`, and Quereus wraps that as
|
|
29
|
+
* `Error during query on table '<T>': …`, again preserving `cause`
|
|
30
|
+
* (`quereus/src/runtime/emit/scan.ts`). The transactor's aggregate is matched by type too — it
|
|
31
|
+
* arrives as a `PeersIncompleteError` naming the phase it came from. Both matchers fail CLOSED:
|
|
32
|
+
* a lost `cause` stops the retry engaging, it never makes it unsafe.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Attempts allowed per control read: the first, plus two retries. Attempts are cheap here —
|
|
37
|
+
* the observed transient failure (the transactor's read-phase aggregate off a stream still
|
|
38
|
+
* forming) surfaces in ~25 ms — and {@link CONTROL_READ_RETRY_BUDGET_MS} is what terminates
|
|
39
|
+
* the loop when an attempt is slow instead.
|
|
40
|
+
*/
|
|
41
|
+
export const CONTROL_READ_ATTEMPTS = 3;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Backoff before read retry N, jittered ±50% and capped at the largest base by the shared
|
|
45
|
+
* loop — so worst case 150 ms + 400 ms = 550 ms of total sleep (the second delay's
|
|
46
|
+
* upside jitter is clipped by the cap). Much shorter than the write list because the
|
|
47
|
+
* whole loop must fit under {@link CONTROL_READ_RETRY_BUDGET_MS}; the spec pins that
|
|
48
|
+
* relationship rather than the number.
|
|
49
|
+
*/
|
|
50
|
+
export const CONTROL_READ_RETRY_DELAYS_MS: readonly number[] = [100, 400];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Elapsed-time ceiling on the whole read-retry loop, checked after a failed attempt BEFORE
|
|
54
|
+
* sleeping — so one slow attempt (e.g. a `cohort-unreachable` read that burned the
|
|
55
|
+
* transactor's own deadline) terminates the loop rather than compounding.
|
|
56
|
+
*
|
|
57
|
+
* 1500 ms, sized against `ADMISSION_DECISION_TIMEOUT_MS` (2000 ms): the inbound admission
|
|
58
|
+
* gate reads the control DB and is FAIL-OPEN on both throw and timeout, so a read that
|
|
59
|
+
* outlives the gate's deadline spends its retries after the gate has already admitted an
|
|
60
|
+
* unplaced peer. Under the deadline, a read that succeeds on its second attempt lets the
|
|
61
|
+
* gate make the real decision instead. `control-read-retry.spec.ts` asserts the
|
|
62
|
+
* relationship so a future edit to either constant reddens instead of silently
|
|
63
|
+
* reintroducing the fail-open admit. NOTE: `queryCadrePeers` / `queryPeerRecord` each
|
|
64
|
+
* issue TWO network reads (the revoked-stamp filter plus the row scan) and the budget is
|
|
65
|
+
* per read, so a membership read can spend up to two budgets back to back — still inside
|
|
66
|
+
* 2 s only because each stays well under it. Do not raise these numbers without
|
|
67
|
+
* re-checking against `ADMISSION_DECISION_TIMEOUT_MS`.
|
|
68
|
+
*
|
|
69
|
+
* It cuts the loop off by design, so it does not grow with the link or with the number that
|
|
70
|
+
* dominates a slow attempt: an attempt whose cohort consult finds a silent peer costs
|
|
71
|
+
* `clusterPolicy.cohortQueryTimeoutMs`, two link round trips at the declared link
|
|
72
|
+
* (`cohortReadDeadlineMs` in `link-budget.ts`, 7 000 ms at the default declaration; the plugin's
|
|
73
|
+
* `COHORT_READ_DEADLINE_MS` is the same number). That is more than four times this budget, so
|
|
74
|
+
* such an attempt is never retried and the caller gets its error unchanged. That is deliberate:
|
|
75
|
+
* the caller this budget is sized for, the admission gate, has
|
|
76
|
+
* already taken its fail-open answer by then, and a retry would only spend time after it. What
|
|
77
|
+
* the budget still buys is the fast failures it was built for: the ~25 ms transactor read-phase
|
|
78
|
+
* aggregate off a stream still forming, and a `cohort-unreachable` read during bring-up, which
|
|
79
|
+
* fails fast because there is no connection to ask. Both retry twice well inside 1500 ms. See
|
|
80
|
+
* `docs/network/deadlines.md` → "Deadlines over Optimystic's reads and commits".
|
|
81
|
+
*/
|
|
82
|
+
// eslint-disable-next-line no-restricted-syntax -- cuts off by design: a slow attempt is not retried, because the admission gate this budget is sized for has already failed open by then; see docs/network/deadlines.md → "Deadlines over Optimystic's reads and commits"
|
|
83
|
+
export const CONTROL_READ_RETRY_BUDGET_MS = 1_500;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Pacing overrides for {@link retryControlRead} — the read twin of
|
|
87
|
+
* `ControlWriteRetryOptions`. Every field defaults to the shipped read policy
|
|
88
|
+
* ({@link CONTROL_READ_ATTEMPTS}, {@link CONTROL_READ_RETRY_DELAYS_MS},
|
|
89
|
+
* {@link isRetriableControlReadFailure}); field shapes and semantics live on the shared
|
|
90
|
+
* {@link ControlRetryOptions}.
|
|
91
|
+
*/
|
|
92
|
+
export type ControlReadRetryOptions = ControlRetryOptions;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Did this control read fail in a way a repeat read can improve on?
|
|
96
|
+
*
|
|
97
|
+
* Two classes, both meaning "the cluster could not be ASKED properly just now":
|
|
98
|
+
*
|
|
99
|
+
* - the transactor's read-phase aggregate ({@link isUncommittedTransactorAggregate}),
|
|
100
|
+
* reused verbatim from the write classifier — including its `pend` arm, which a read
|
|
101
|
+
* cannot produce at all because it presents no transaction, so claiming that phase here
|
|
102
|
+
* is unreachable rather than unsafe and one shared predicate is one thing to keep
|
|
103
|
+
* correct. The write side's indeterminate-commit veto likewise has nothing to veto here
|
|
104
|
+
* (a read commits nothing and re-running it is always safe);
|
|
105
|
+
* - a block read the cohort could not answer ({@link reportsUnreachableCohort}, the
|
|
106
|
+
* predicate the write classifier shares — see it for the reasons and the measured
|
|
107
|
+
* exclusions).
|
|
108
|
+
*
|
|
109
|
+
* Both are matched by TYPE, over one walk of the `cause` chain. Anything that is not an
|
|
110
|
+
* `Error` is never retried, and anything unmatched is not retried either.
|
|
111
|
+
*/
|
|
112
|
+
export function isRetriableControlReadFailure(error: unknown): boolean {
|
|
113
|
+
if (!(error instanceof Error)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const links = causeChain(error);
|
|
117
|
+
return reportsUnreachableCohort(links) || isUncommittedTransactorAggregate(links);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Did this control read fail because no cohort member other than the answering node could
|
|
122
|
+
* be asked about a block nobody here holds — a `BlockUnavailableError` with reason
|
|
123
|
+
* `cohort-unreachable` anywhere on the `cause` chain?
|
|
124
|
+
*
|
|
125
|
+
* Not a retry classifier. It answers "is there a better answer to wait for?", and is used
|
|
126
|
+
* by exactly one reader, `ControlDatabase.queryRevokedStamps`, to read an isolated node's
|
|
127
|
+
* never-received `Revocation` block as "no revocations known" (the reasoning is in the NOTE
|
|
128
|
+
* there). Upstream names this the one reason a caller may treat permissively
|
|
129
|
+
* (`db-core/src/transactor/network-transactor.ts`). The other reasons do NOT match:
|
|
130
|
+
* `peers-unreachable` means part of the cohort answered (or no coordinator did), and
|
|
131
|
+
* `claimed-elsewhere` / `unmaterializable` mean the block is known to exist, so an empty
|
|
132
|
+
* answer could hide a real revocation. NOTE: narrower than upstream's same-named
|
|
133
|
+
* `isCohortUnreachableRead` (`@optimystic/db-core`), which also matches `peers-unreachable`
|
|
134
|
+
* and is what the retry classifiers use ({@link reportsUnreachableCohort}); do not swap one
|
|
135
|
+
* for the other.
|
|
136
|
+
*
|
|
137
|
+
* Matched by TYPE, since the typed error survives upstream's rewraps (module comment).
|
|
138
|
+
* Fails CLOSED: a non-`Error`, a text-only copy of the message, and an error built by a
|
|
139
|
+
* second loaded copy of `@optimystic/db-core` (which `instanceof` cannot recognise) all
|
|
140
|
+
* answer false, and the reader throws as it did before this existed.
|
|
141
|
+
*/
|
|
142
|
+
export function isCohortUnreachableRead(error: unknown): boolean {
|
|
143
|
+
return causeChain(error).some(link =>
|
|
144
|
+
link instanceof BlockUnavailableError && link.reason === 'cohort-unreachable');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Did this failure mean no coordinator could be resolved for a block AT ALL — a
|
|
149
|
+
* `FindCoordinatorError` anywhere on the `cause` chain?
|
|
150
|
+
*
|
|
151
|
+
* The sibling of {@link isCohortUnreachableRead} for the failure shape a machine that stores
|
|
152
|
+
* none of a strand's blocks produces. Such a node's `findCluster` returns an EMPTY cohort, so
|
|
153
|
+
* every block falls through to `findCoordinator`, which waits out its bounded retry window and
|
|
154
|
+
* throws `FindCoordinatorError` — code `NO_NETWORK_COORDINATOR` when the only peers it saw were
|
|
155
|
+
* unconfirmed or serve another network, `NO_COORDINATOR_AVAILABLE` otherwise.
|
|
156
|
+
*
|
|
157
|
+
* Matched by CLASS, so all four of `FIND_COORDINATOR_ERROR_CODES` match, not only the two a
|
|
158
|
+
* client produces. That is the intent, not laxity: every code means "no coordinator was
|
|
159
|
+
* resolved", NONE of them means "the block does not exist", and the one reader
|
|
160
|
+
* (`StrandInstanceManager.buildStrandDatabase`) waits for a machine that can answer in every
|
|
161
|
+
* case. The two self-coordination codes reach a Sereus node only from a detected partition or
|
|
162
|
+
* suspicious cohort shrinkage — Sereus never switches self-coordination off by config — and
|
|
163
|
+
* waiting is the right answer there too.
|
|
164
|
+
*
|
|
165
|
+
* Not a retry classifier, and deliberately NOT folded into {@link isCohortUnreachableRead}:
|
|
166
|
+
* that predicate's other reader, `ControlDatabase.queryRevokedStamps`, reads an unmatched block
|
|
167
|
+
* as "no revocations known", so admitting a new class of failure there would widen a
|
|
168
|
+
* security-relevant default. One predicate per reader is what keeps that default where it was.
|
|
169
|
+
*
|
|
170
|
+
* The walk is over the same {@link causeChain}, because `StrandDatabase.initialize` runs the
|
|
171
|
+
* failure through Quereus's `db.exec`, which may wrap it. Fails CLOSED the same way: a
|
|
172
|
+
* non-`Error`, a text-only copy of the message, and an error built by a second loaded copy of
|
|
173
|
+
* `@optimystic/db-p2p` (which `instanceof` cannot recognise) all answer false, and the caller
|
|
174
|
+
* throws as it did before this existed.
|
|
175
|
+
*
|
|
176
|
+
* NOTE: matching the class rather than `.code` is the deliberate call, and the one code it
|
|
177
|
+
* admits against its own upstream advice is `SELF_COORDINATION_BLOCKED`, whose comment says
|
|
178
|
+
* retrying is unlikely to help. It costs a launch that hits it a `'syncing'` runtime retrying
|
|
179
|
+
* every 5 s instead of a watcher rebuild on a doubling delay, and only a SERVING node can hit
|
|
180
|
+
* it at all (a client is never a candidate coordinator, so it gets `NO_COORDINATOR_AVAILABLE`).
|
|
181
|
+
* Narrow this to `.code` if a config switch for self-coordination is ever passed from Sereus, or
|
|
182
|
+
* if a partition verdict is ever made from something that does not heal on its own.
|
|
183
|
+
*/
|
|
184
|
+
export function isNoCoordinatorResolved(error: unknown): boolean {
|
|
185
|
+
return causeChain(error).some(link => link instanceof FindCoordinatorError);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Run `attempt` — a full drain of one control read — up to
|
|
190
|
+
* {@link CONTROL_READ_ATTEMPTS} times, retrying only failures
|
|
191
|
+
* {@link isRetriableControlReadFailure} calls transient, and only while
|
|
192
|
+
* {@link CONTROL_READ_RETRY_BUDGET_MS} has not elapsed.
|
|
193
|
+
*
|
|
194
|
+
* Reads are idempotent, so `attempt` needs no atomicity contract — but it must be a
|
|
195
|
+
* COLLECTING drain, not a live iterator: a half-consumed iterator cannot be retried
|
|
196
|
+
* without re-yielding rows the caller already saw, which is why
|
|
197
|
+
* `ControlDatabase.readRows` materializes before this loop ever sees a failure.
|
|
198
|
+
*
|
|
199
|
+
* On exhaustion the LAST error is rethrown unchanged. Log lines carry the
|
|
200
|
+
* `Control read [<label>] …` prefix so a read's retries can be attributed among the
|
|
201
|
+
* several reads in flight concurrently in a real party.
|
|
202
|
+
*
|
|
203
|
+
* No reader passes an `onAbandon` observer, deliberately, though the shared options type
|
|
204
|
+
* offers one ({@link ControlRetryOptions.onAbandon}) and the loop would honour it. That hook
|
|
205
|
+
* exists because an abandoned WRITE can have no caller at all — the background self-record
|
|
206
|
+
* republish is `void`-ed with a `debug`-only catch, so giving up on it is invisible. Every
|
|
207
|
+
* control read is awaited by the caller that issued it, so an abandoned read surfaces as that
|
|
208
|
+
* caller's rejection; there is nothing here to lose silently. A fire-and-forget read would be
|
|
209
|
+
* the reason to start passing one.
|
|
210
|
+
*/
|
|
211
|
+
export function retryControlRead<T>(
|
|
212
|
+
attempt: () => Promise<T>,
|
|
213
|
+
options: ControlReadRetryOptions = {}
|
|
214
|
+
): Promise<T> {
|
|
215
|
+
return retryControlOperation(attempt, {
|
|
216
|
+
attempts: CONTROL_READ_ATTEMPTS,
|
|
217
|
+
delaysMs: CONTROL_READ_RETRY_DELAYS_MS,
|
|
218
|
+
budgetMs: CONTROL_READ_RETRY_BUDGET_MS,
|
|
219
|
+
isRetriable: isRetriableControlReadFailure,
|
|
220
|
+
logPrefix: 'Control read',
|
|
221
|
+
}, options);
|
|
222
|
+
}
|
package/src/control-retry.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
-
import { isCohortUnreachableRead } from '@optimystic/db-core';
|
|
2
|
+
import { isCohortUnreachableRead, PromiseShortfallError } from '@optimystic/db-core';
|
|
3
3
|
import { unwrapError } from '@quereus/quereus';
|
|
4
4
|
|
|
5
5
|
const log = debug('sereus:cadre:control-db');
|
|
@@ -233,9 +233,10 @@ function notifyAbandoned(
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
|
-
* Every message in the failure's `cause` chain — the substrate
|
|
237
|
-
*
|
|
238
|
-
*
|
|
236
|
+
* Every message in the failure's `cause` chain — the substrate for the matchers that have only
|
|
237
|
+
* TEXT to work with: the schema-init self-coordination refusal (`control-write-retry.ts`, whose
|
|
238
|
+
* `NOTE:` says why) and `ControlDatabase`'s own message probes. Both retry classifiers claim their
|
|
239
|
+
* failures by TYPE over {@link causeChain} instead. Every wrap on the way out of optimystic and
|
|
239
240
|
* Quereus embeds the inner message, so the text of the deepest failure is visible at every level.
|
|
240
241
|
*
|
|
241
242
|
* `unwrapError` declares its `message` as `string`, but it follows `.cause` without checking
|
|
@@ -318,6 +319,37 @@ export function reportsUnreachableCohort(links: readonly Error[]): boolean {
|
|
|
318
319
|
return links.some(link => isCohortUnreachableRead(link));
|
|
319
320
|
}
|
|
320
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Does any link of the `cause` chain report the cluster coordinator's super-majority shortfall with
|
|
324
|
+
* NOBODY having voted no — a `PromiseShortfallError` whose `rejections` is zero? The promise round
|
|
325
|
+
* reached no verdict (too few approvals to pass, too few rejections to count as a rejection), so the
|
|
326
|
+
* cohort was simply not all there, and a moment later it may be.
|
|
327
|
+
*
|
|
328
|
+
* The one shortfall test both write policies share — the control-write classifier
|
|
329
|
+
* (`isRetriableControlWriteFailure`) and the edge node's `retryAfterRestart` — so the funnel every
|
|
330
|
+
* local control write passes through and the helper an app wraps its first writes in cannot
|
|
331
|
+
* disagree on which shortfall is worth re-presenting.
|
|
332
|
+
*
|
|
333
|
+
* A non-zero `rejections` is deliberately excluded: a member actually voted no (that branch carries
|
|
334
|
+
* `membership-not-admitted` rejections), and no backoff changes that answer — re-presenting it would
|
|
335
|
+
* re-present a spent signature to a cohort that already refused it.
|
|
336
|
+
*
|
|
337
|
+
* Matched by TYPE, which upstream's own comment on the class asks consumers to prefer over its
|
|
338
|
+
* sentence. Every wrapper between the raise site and either caller keeps the error on `cause` — the
|
|
339
|
+
* optimystic plugin's `rewrapAsQueryError`, Quereus' statement-execution rewrap, its module-create
|
|
340
|
+
* wrapper and its DDL wrapper — so the claim reaches any depth. NOTE: an error built by a second
|
|
341
|
+
* loaded copy of `@optimystic/db-core`, or one rebuilt as a plain `Error` from its text, fails
|
|
342
|
+
* `instanceof` and is not claimed — the same fail-closed direction
|
|
343
|
+
* {@link reportsUnreachableCohort} already accepts.
|
|
344
|
+
*
|
|
345
|
+
* This says only that the round went unanswered. WHERE that leaves the write is the caller's: the
|
|
346
|
+
* control-write funnel still vetoes a shortfall carried by a commit-phase batch, because a commit
|
|
347
|
+
* may have landed with only the reply lost.
|
|
348
|
+
*/
|
|
349
|
+
export function reportsUnansweredShortfall(links: readonly Error[]): boolean {
|
|
350
|
+
return links.some(link => link instanceof PromiseShortfallError && link.rejections === 0);
|
|
351
|
+
}
|
|
352
|
+
|
|
321
353
|
/**
|
|
322
354
|
* Backoff for the retry that follows attempt `attemptNumber`: the matching base delay
|
|
323
355
|
* (last entry repeats), jittered ±50%, then capped at the list's largest base so no single
|