@serfab/cadre-core 1.4.0 → 1.6.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 (63) hide show
  1. package/dist/cadre-node.d.ts +38 -15
  2. package/dist/cadre-node.js +81 -29
  3. package/dist/cadre-node.js.map +1 -1
  4. package/dist/control-database.d.ts +24 -10
  5. package/dist/control-database.js +48 -16
  6. package/dist/control-database.js.map +1 -1
  7. package/dist/control-read-retry.d.ts +12 -0
  8. package/dist/control-read-retry.js +12 -0
  9. package/dist/control-read-retry.js.map +1 -1
  10. package/dist/control-write-retry.d.ts +5 -4
  11. package/dist/control-write-retry.js +24 -7
  12. package/dist/control-write-retry.js.map +1 -1
  13. package/dist/index.d.ts +3 -2
  14. package/dist/index.js +5 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/link-budget.d.ts +224 -0
  17. package/dist/link-budget.js +239 -0
  18. package/dist/link-budget.js.map +1 -0
  19. package/dist/peer-dial.d.ts +36 -17
  20. package/dist/peer-dial.js +37 -17
  21. package/dist/peer-dial.js.map +1 -1
  22. package/dist/peer-join-backfill.d.ts +58 -4
  23. package/dist/peer-join-backfill.js +166 -20
  24. package/dist/peer-join-backfill.js.map +1 -1
  25. package/dist/relay-reservation.d.ts +59 -11
  26. package/dist/relay-reservation.js +169 -43
  27. package/dist/relay-reservation.js.map +1 -1
  28. package/dist/seed-bootstrap.js +2 -1
  29. package/dist/seed-bootstrap.js.map +1 -1
  30. package/dist/strand-first-sync-gate.d.ts +105 -22
  31. package/dist/strand-first-sync-gate.js +121 -27
  32. package/dist/strand-first-sync-gate.js.map +1 -1
  33. package/dist/strand-instance-manager.d.ts +27 -2
  34. package/dist/strand-instance-manager.js +60 -13
  35. package/dist/strand-instance-manager.js.map +1 -1
  36. package/dist/strand-membership-reconciler.d.ts +200 -45
  37. package/dist/strand-membership-reconciler.js +302 -86
  38. package/dist/strand-membership-reconciler.js.map +1 -1
  39. package/dist/strand-membership-writer.d.ts +3 -2
  40. package/dist/strand-membership-writer.js +67 -90
  41. package/dist/strand-membership-writer.js.map +1 -1
  42. package/dist/strand-network-config.d.ts +2 -2
  43. package/dist/strand-network-config.js +2 -2
  44. package/dist/types.d.ts +105 -9
  45. package/dist/types.js +20 -4
  46. package/dist/types.js.map +1 -1
  47. package/package.json +8 -8
  48. package/src/cadre-node.ts +7449 -7397
  49. package/src/control-database.ts +48 -16
  50. package/src/control-read-retry.ts +214 -202
  51. package/src/control-write-retry.ts +24 -7
  52. package/src/index.ts +582 -563
  53. package/src/link-budget.ts +264 -0
  54. package/src/peer-dial.ts +39 -17
  55. package/src/peer-join-backfill.ts +648 -478
  56. package/src/relay-reservation.ts +1119 -951
  57. package/src/seed-bootstrap.ts +2 -1
  58. package/src/strand-first-sync-gate.ts +352 -258
  59. package/src/strand-instance-manager.ts +1520 -1458
  60. package/src/strand-membership-reconciler.ts +334 -92
  61. package/src/strand-membership-writer.ts +1962 -1987
  62. package/src/strand-network-config.ts +2 -2
  63. package/src/types.ts +104 -8
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Dial and reservation budgets derived from ONE declared link round trip, instead of fixed
3
+ * millisecond numbers chosen on a fast local network.
4
+ *
5
+ * Reaching another machine through a relay costs a FIXED NUMBER OF EXCHANGES, not a fixed
6
+ * number of milliseconds. So every budget written as milliseconds has a link speed above which
7
+ * it can never open a connection at all — and the slower the link, the more of them fall over,
8
+ * silently, because an abandoned dial looks the same as a peer that is not there. Counting round
9
+ * trips instead is what stops that class of defect coming back: the next person to widen a
10
+ * budget changes ONE declaration, and the next person to add a dial writes down its round-trip
11
+ * count beside the arithmetic.
12
+ *
13
+ * ── The instrument ──
14
+ *
15
+ * Every count and every number below comes from
16
+ * `packages/integration-tests/src/scenarios/relayed-dial-cost-by-latency.integration.ts`, which
17
+ * is committed and opt-in (`RELAY_DIAL_COST=1`). **Its doc comment is the single home of the
18
+ * measurement**; this module holds only what the derivation needs. Re-run it before changing
19
+ * anything here.
20
+ *
21
+ * ── The unit ──
22
+ *
23
+ * ONE LINK ROUND TRIP is a message from one machine reaching the other and a reply coming
24
+ * back, over the path those two machines actually use — through the relay, when that is the
25
+ * only way they can reach each other. In the instrument, which injects a constant ONE-WAY
26
+ * frame delay `d`, one link round trip is `2d`.
27
+ *
28
+ * A leg between a node and the RELAY is half a link round trip, because it crosses one of the
29
+ * two hops rather than both. That is why the reservation drive's cost reads as "four
30
+ * node-to-relay round trips" in one telling and "two link round trips" in another: same
31
+ * quantity, different unit. This module uses the LINK round trip throughout, so there is one
32
+ * unit to reason in.
33
+ *
34
+ * ── The counts, and what they cost ──
35
+ *
36
+ * | operation | link round trips | at the declared default |
37
+ * | ---------------------------------------------------- | ---------------- | ----------------------- |
38
+ * | open a relayed connection to another machine | 4 | 14 000 ms |
39
+ * | dial the relay itself | 1 | 3 500 ms |
40
+ * | request a reservation on an open relay connection | 1 | 3 500 ms |
41
+ * | negotiate a protocol over an established circuit | 1 | 3 500 ms |
42
+ *
43
+ * **Measured** 2026-09-26, one Windows machine, loopback dedicated relay: a relayed dial took
44
+ * 20-25 ms at no delay, **7 255-7 279 ms at 900 ms one-way**, and **12 066-12 094 ms at 1 500 ms
45
+ * one-way**. Four link round trips of pure delay would be 7 200 and 12 000, so the real cost
46
+ * sits about 60-95 ms ABOVE the arithmetic — the handshakes, which no delay figure contains.
47
+ * That residue is why {@link DECLARED_LINK_ROUND_TRIP_MS} carries headroom over the link sereus
48
+ * supports rather than matching it exactly: a declaration equal to the supported round trip
49
+ * would derive a budget marginally BELOW the dial it has to contain.
50
+ *
51
+ * ── libp2p's own two limits ──
52
+ *
53
+ * Two limits inside libp2p bound the same relayed dial as cadre's budgets do, and both were
54
+ * 10 000 ms until `@optimystic/db-p2p` 1.7.0 let an embedder set them: the DIALER's
55
+ * `connectionManager.dialTimeout`, which bounds every dial that carries no abort signal of its
56
+ * own, and the LISTENER's `connectionManager.inboundUpgradeTimeout`, which is how long the
57
+ * machine being called lets a half-built connection finish its handshakes. At 10 000 ms each,
58
+ * no relayed connection could be opened above about 1 250 ms one-way (a 2.5-second link round
59
+ * trip) whatever cadre declared. The listener's limit is the one that makes that failure
60
+ * silent: at 1 500 ms one-way the dialer's own 12 094 ms dial RESOLVED while the listener had
61
+ * already thrown the connection away at 10 s, so the first stream over it died with
62
+ * `Unexpected EOF - stream closed while reading 0/1 bytes` and the listener reported no peer at
63
+ * all. cadre now declares both from this module ({@link connectionManagerTimeouts}) on the
64
+ * control node and every strand node.
65
+ *
66
+ * ── What still fails at the supported link ──
67
+ *
68
+ * - **Optimystic's own request dials.** `@optimystic/db-p2p`'s RPC clients dial with fixed
69
+ * 3 000 ms deadlines of their own (`DEFAULT_DIAL_TIMEOUT_MS`, the `pushDialTimeoutMs`
70
+ * defaults), which neither limit above reaches because a caller's signal replaces
71
+ * `dialTimeout`. So an Optimystic request that has to OPEN a relayed connection fails above
72
+ * 375 ms one-way. A request over a connection that is already open does not dial, and the
73
+ * connections cadre opens itself are budgeted here. Upstream:
74
+ * `debt-rpc-dial-deadlines-cannot-open-a-slow-relayed-connection` in optimystic.
75
+ * - **Cadre deadlines still typed as milliseconds.** The strand wake, strand-address and seed
76
+ * delivery deadlines, and the cohort read deadline, bound exchanges over the same link but do
77
+ * not derive from it: `tickets/backlog/debt-three-more-dial-deadlines-ignore-the-declared-link`.
78
+ * - **A machine that declares a faster link than its peers.** Every machine is the listener
79
+ * for the others, so its `inboundUpgradeTimeout` — derived from ITS declaration — bounds
80
+ * connections other machines open to it. A peer declaring 3 500 ms dialing a machine that
81
+ * declared 500 ms gets exactly the silent failure above. Declare the same link on every
82
+ * machine of a party.
83
+ */
84
+ import type { Libp2pConnectionTimeouts } from '@optimystic/db-p2p';
85
+ /**
86
+ * The link round trip cadre assumes when a host declares none, in milliseconds. A deployment
87
+ * that knows its own link states it with `NetworkConfig.linkRoundTripMs` instead.
88
+ *
89
+ * **Why 3 500.** Sereus supports two machines that reach each other only through a relay up to
90
+ * a **3-second link round trip** (1 500 ms each way — a congested mobile or satellite link;
91
+ * `docs/architecture.md` → "Relay Integration"). The worst relayed dial measured at that link
92
+ * was 12 094 ms, above the 12 000 ms a declaration of exactly 3 000 would derive, so the
93
+ * declaration rounds the supported link up to the next half second. 3 500 derives 14 000 ms
94
+ * and leaves about 1.9 s over that dial: room for a phone's Noise handshake, which the
95
+ * loopback measurement on a desktop does not contain. (The previous 2 000 followed the same
96
+ * convention for the 1.8 s band sereus supported before, with about 720 ms to spare.)
97
+ *
98
+ * Two budgets outside this module were sized against the 1.8 s band and do NOT move with it:
99
+ * `COHORT_READ_DEADLINE_MS` (`quereus-plugin-sereus/src/cluster-size.ts`, 5 000 ms) and
100
+ * `DEFAULT_STRAND_FIRST_SYNC_TIMEOUT_MS` (`strand-first-sync-gate.ts`). The module doc's
101
+ * "What still fails" list carries the first.
102
+ *
103
+ * What 3 500 costs, against 2 000: a peer that is genuinely gone holds each operation longer
104
+ * before it is abandoned and retried — a relayed dial or a reservation drive 14 s instead of
105
+ * 8 s, and a control-cohort dial of one peer across all its addresses 56 s instead of 32 s.
106
+ * Raise it further for a link slower still; lower it only on a deployment where EVERY machine
107
+ * of the party is that close, for the reason the "What still fails" list gives.
108
+ */
109
+ export declare const DECLARED_LINK_ROUND_TRIP_MS = 3500;
110
+ /**
111
+ * Link round trips one relayed connection setup costs: transport, encryption and multiplexer
112
+ * handshakes to the relay, the circuit open, then both handshakes again end to end through it.
113
+ * Measured at 8 one-way delays, which is 4 link round trips.
114
+ */
115
+ export declare const RELAYED_DIAL_ROUND_TRIPS = 4;
116
+ /**
117
+ * Link round trips one whole reservation drive is budgeted for
118
+ * (`relay-reservation.ts`'s `driveRelayReservation`, whose ONE deadline covers the dial, the
119
+ * reservation request and the wait together).
120
+ *
121
+ * The protocol work measured is 2 — dial the relay (1) plus request the reservation (1). It is
122
+ * budgeted at 4, the relayed-dial count, because the wait afterwards may instead be satisfied
123
+ * by libp2p's own relay discovery, which repeats both legs after identify has run; 4 is
124
+ * therefore the largest thing this one deadline can be asked to contain, and the poll interval
125
+ * (`DEFAULT_RELAY_RESERVE_POLL_MS`) rounds up on top of it.
126
+ */
127
+ export declare const RELAY_RESERVATION_ROUND_TRIPS = 4;
128
+ /**
129
+ * Link round trips one request-and-answer over an ALREADY-OPEN circuit costs: the protocol
130
+ * negotiation (1, measured at 2 one-way delays) plus the request and its response (1). It does
131
+ * not include a dial — a caller that may have to open the connection budgets
132
+ * {@link RELAYED_DIAL_ROUND_TRIPS} separately, which is exactly what the two-field shape of
133
+ * Optimystic's `dialTimeoutMs` / `responseTimeoutMs` pair is for.
134
+ */
135
+ export declare const CIRCUIT_REQUEST_ROUND_TRIPS = 2;
136
+ /**
137
+ * What a block-transfer push message's BYTES get to cross, on top of the latency
138
+ * {@link CIRCUIT_REQUEST_ROUND_TRIPS} covers, in milliseconds.
139
+ *
140
+ * This part is bandwidth, not latency, so it does not scale with the declared round trip: a
141
+ * chunk is capped at `PeerJoinBackfillConfig.maxChunkBytes` (1 MiB by default) and crossing it
142
+ * costs whatever the link's throughput costs.
143
+ *
144
+ * NOTE: 6 000 ms is not a measurement of any throughput — it is the residue of the 10 000 ms
145
+ * this deadline shipped as before it was split into a latency part and a transfer part, chosen
146
+ * so that at the declaration then in force (2 000 ms) the derived value stayed 10 000 and no
147
+ * fast link got slower. Nobody has measured how long 1 MiB takes to cross a relayed mobile
148
+ * link. If pushes ever time out with the transfer only part done, measure that and raise THIS,
149
+ * not the declared round trip.
150
+ */
151
+ export declare const PUSH_TRANSFER_ALLOWANCE_MS = 6000;
152
+ /**
153
+ * Resolve a host's declared link round trip, falling back to
154
+ * {@link DECLARED_LINK_ROUND_TRIP_MS}.
155
+ *
156
+ * Validated here rather than downstream because nothing downstream would: every consumer
157
+ * multiplies this value into a `setTimeout` deadline, where a zero silently turns a budget into
158
+ * "give up immediately" and a `NaN` turns it into "never time out".
159
+ *
160
+ * Both node bring-up paths call this EAGERLY — `CadreNode.start()`, and
161
+ * `StrandInstanceManager.buildStrandRuntime` behind `addStrand`/`resumeStrand` — so a bad
162
+ * declaration fails the same start that Optimystic's own check on `cohortQueryTimeoutMs` fails.
163
+ * The eager call is what makes that true: every budget derived here is behind a condition (a
164
+ * node with no control storage builds no catch-up, a node with no relay addrs drives no
165
+ * reservation), so waiting for a first consumer would let a broken declaration boot and then
166
+ * throw inside a best-effort path that logs and carries on.
167
+ */
168
+ export declare function resolveLinkRoundTripMs(linkRoundTripMs?: number): number;
169
+ /**
170
+ * Deadline for OPENING a connection to another machine that may only be reachable through a
171
+ * relay: {@link RELAYED_DIAL_ROUND_TRIPS} at the declared link round trip.
172
+ */
173
+ export declare function relayedDialBudgetMs(linkRoundTripMs?: number): number;
174
+ /**
175
+ * libp2p's two connection-manager limits for a node at the declared link, handed to
176
+ * `@optimystic/db-p2p`'s `NodeOptions.connectionManager` on the control node and every strand
177
+ * node.
178
+ *
179
+ * Both bound the same thing — opening a relayed connection, measured at 8 one-way link delays,
180
+ * which is {@link RELAYED_DIAL_ROUND_TRIPS} (4) link round trips — so both are
181
+ * {@link relayedDialBudgetMs}: 4 x 3 500 = 14 000 ms at the default declaration, covering the
182
+ * 12 094 ms measured at the supported 3-second link.
183
+ *
184
+ * The listener's limit is deliberately NOT smaller than the dialer's. The listener's clock
185
+ * starts only when the relay hands it the circuit, a few one-way delays after the dialer's
186
+ * started, and both sides finish the handshakes at about the same moment; so with equal limits
187
+ * the listener never discards a connection that the dialer's own dial would still accept. A
188
+ * listener limit below the dialer's is what produced the silent failure in the module doc.
189
+ *
190
+ * The cost of a longer `inboundUpgradeTimeout` is that a peer which opens a connection and then
191
+ * stalls its handshake holds that half-built connection 14 s instead of 10 s.
192
+ *
193
+ * NOTE: derived from the declaration alone, so a per-field override that raises a cadre dial
194
+ * budget above it (`controlCohort.perAddressDialTimeoutMs`, `strandBackfill.dialTimeoutMs`)
195
+ * does not raise these; a dial that outlasts the listener's limit gets the silent failure
196
+ * again. If such overrides start being used for slow links, raise the declaration instead or
197
+ * take the largest configured dial budget here.
198
+ */
199
+ export declare function connectionManagerTimeouts(linkRoundTripMs?: number): Libp2pConnectionTimeouts;
200
+ /**
201
+ * Deadline for one whole relay reservation drive: {@link RELAY_RESERVATION_ROUND_TRIPS} at the
202
+ * declared link round trip.
203
+ */
204
+ export declare function relayReservationBudgetMs(linkRoundTripMs?: number): number;
205
+ /**
206
+ * Deadline for one request and its answer over a circuit that is already open —
207
+ * {@link CIRCUIT_REQUEST_ROUND_TRIPS} at the declared link round trip, plus `transferAllowanceMs`
208
+ * for the payload's own bytes.
209
+ */
210
+ export declare function circuitRequestBudgetMs(linkRoundTripMs?: number, transferAllowanceMs?: number): number;
211
+ /** The two deadlines one peer-join catch-up push needs, both derived from the declared link. */
212
+ export interface PeerJoinPushBudget {
213
+ /** Opening the connection to the peer being caught up — a relayed dial, in the worst case. */
214
+ dialTimeoutMs: number;
215
+ /** The push request and its answer over that connection, including the chunk's own bytes. */
216
+ responseTimeoutMs: number;
217
+ }
218
+ /**
219
+ * The dial and response deadlines a peer-join catch-up push needs at a declared link. One
220
+ * helper rather than two call-site expressions, because the two construction sites
221
+ * (`CadreNode`'s control catch-up and `StrandInstanceManager`'s per-strand one) and
222
+ * `DEFAULT_PEER_JOIN_BACKFILL` must not drift apart.
223
+ */
224
+ export declare function peerJoinPushBudget(linkRoundTripMs?: number): PeerJoinPushBudget;
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Dial and reservation budgets derived from ONE declared link round trip, instead of fixed
3
+ * millisecond numbers chosen on a fast local network.
4
+ *
5
+ * Reaching another machine through a relay costs a FIXED NUMBER OF EXCHANGES, not a fixed
6
+ * number of milliseconds. So every budget written as milliseconds has a link speed above which
7
+ * it can never open a connection at all — and the slower the link, the more of them fall over,
8
+ * silently, because an abandoned dial looks the same as a peer that is not there. Counting round
9
+ * trips instead is what stops that class of defect coming back: the next person to widen a
10
+ * budget changes ONE declaration, and the next person to add a dial writes down its round-trip
11
+ * count beside the arithmetic.
12
+ *
13
+ * ── The instrument ──
14
+ *
15
+ * Every count and every number below comes from
16
+ * `packages/integration-tests/src/scenarios/relayed-dial-cost-by-latency.integration.ts`, which
17
+ * is committed and opt-in (`RELAY_DIAL_COST=1`). **Its doc comment is the single home of the
18
+ * measurement**; this module holds only what the derivation needs. Re-run it before changing
19
+ * anything here.
20
+ *
21
+ * ── The unit ──
22
+ *
23
+ * ONE LINK ROUND TRIP is a message from one machine reaching the other and a reply coming
24
+ * back, over the path those two machines actually use — through the relay, when that is the
25
+ * only way they can reach each other. In the instrument, which injects a constant ONE-WAY
26
+ * frame delay `d`, one link round trip is `2d`.
27
+ *
28
+ * A leg between a node and the RELAY is half a link round trip, because it crosses one of the
29
+ * two hops rather than both. That is why the reservation drive's cost reads as "four
30
+ * node-to-relay round trips" in one telling and "two link round trips" in another: same
31
+ * quantity, different unit. This module uses the LINK round trip throughout, so there is one
32
+ * unit to reason in.
33
+ *
34
+ * ── The counts, and what they cost ──
35
+ *
36
+ * | operation | link round trips | at the declared default |
37
+ * | ---------------------------------------------------- | ---------------- | ----------------------- |
38
+ * | open a relayed connection to another machine | 4 | 14 000 ms |
39
+ * | dial the relay itself | 1 | 3 500 ms |
40
+ * | request a reservation on an open relay connection | 1 | 3 500 ms |
41
+ * | negotiate a protocol over an established circuit | 1 | 3 500 ms |
42
+ *
43
+ * **Measured** 2026-09-26, one Windows machine, loopback dedicated relay: a relayed dial took
44
+ * 20-25 ms at no delay, **7 255-7 279 ms at 900 ms one-way**, and **12 066-12 094 ms at 1 500 ms
45
+ * one-way**. Four link round trips of pure delay would be 7 200 and 12 000, so the real cost
46
+ * sits about 60-95 ms ABOVE the arithmetic — the handshakes, which no delay figure contains.
47
+ * That residue is why {@link DECLARED_LINK_ROUND_TRIP_MS} carries headroom over the link sereus
48
+ * supports rather than matching it exactly: a declaration equal to the supported round trip
49
+ * would derive a budget marginally BELOW the dial it has to contain.
50
+ *
51
+ * ── libp2p's own two limits ──
52
+ *
53
+ * Two limits inside libp2p bound the same relayed dial as cadre's budgets do, and both were
54
+ * 10 000 ms until `@optimystic/db-p2p` 1.7.0 let an embedder set them: the DIALER's
55
+ * `connectionManager.dialTimeout`, which bounds every dial that carries no abort signal of its
56
+ * own, and the LISTENER's `connectionManager.inboundUpgradeTimeout`, which is how long the
57
+ * machine being called lets a half-built connection finish its handshakes. At 10 000 ms each,
58
+ * no relayed connection could be opened above about 1 250 ms one-way (a 2.5-second link round
59
+ * trip) whatever cadre declared. The listener's limit is the one that makes that failure
60
+ * silent: at 1 500 ms one-way the dialer's own 12 094 ms dial RESOLVED while the listener had
61
+ * already thrown the connection away at 10 s, so the first stream over it died with
62
+ * `Unexpected EOF - stream closed while reading 0/1 bytes` and the listener reported no peer at
63
+ * all. cadre now declares both from this module ({@link connectionManagerTimeouts}) on the
64
+ * control node and every strand node.
65
+ *
66
+ * ── What still fails at the supported link ──
67
+ *
68
+ * - **Optimystic's own request dials.** `@optimystic/db-p2p`'s RPC clients dial with fixed
69
+ * 3 000 ms deadlines of their own (`DEFAULT_DIAL_TIMEOUT_MS`, the `pushDialTimeoutMs`
70
+ * defaults), which neither limit above reaches because a caller's signal replaces
71
+ * `dialTimeout`. So an Optimystic request that has to OPEN a relayed connection fails above
72
+ * 375 ms one-way. A request over a connection that is already open does not dial, and the
73
+ * connections cadre opens itself are budgeted here. Upstream:
74
+ * `debt-rpc-dial-deadlines-cannot-open-a-slow-relayed-connection` in optimystic.
75
+ * - **Cadre deadlines still typed as milliseconds.** The strand wake, strand-address and seed
76
+ * delivery deadlines, and the cohort read deadline, bound exchanges over the same link but do
77
+ * not derive from it: `tickets/backlog/debt-three-more-dial-deadlines-ignore-the-declared-link`.
78
+ * - **A machine that declares a faster link than its peers.** Every machine is the listener
79
+ * for the others, so its `inboundUpgradeTimeout` — derived from ITS declaration — bounds
80
+ * connections other machines open to it. A peer declaring 3 500 ms dialing a machine that
81
+ * declared 500 ms gets exactly the silent failure above. Declare the same link on every
82
+ * machine of a party.
83
+ */
84
+ /**
85
+ * The link round trip cadre assumes when a host declares none, in milliseconds. A deployment
86
+ * that knows its own link states it with `NetworkConfig.linkRoundTripMs` instead.
87
+ *
88
+ * **Why 3 500.** Sereus supports two machines that reach each other only through a relay up to
89
+ * a **3-second link round trip** (1 500 ms each way — a congested mobile or satellite link;
90
+ * `docs/architecture.md` → "Relay Integration"). The worst relayed dial measured at that link
91
+ * was 12 094 ms, above the 12 000 ms a declaration of exactly 3 000 would derive, so the
92
+ * declaration rounds the supported link up to the next half second. 3 500 derives 14 000 ms
93
+ * and leaves about 1.9 s over that dial: room for a phone's Noise handshake, which the
94
+ * loopback measurement on a desktop does not contain. (The previous 2 000 followed the same
95
+ * convention for the 1.8 s band sereus supported before, with about 720 ms to spare.)
96
+ *
97
+ * Two budgets outside this module were sized against the 1.8 s band and do NOT move with it:
98
+ * `COHORT_READ_DEADLINE_MS` (`quereus-plugin-sereus/src/cluster-size.ts`, 5 000 ms) and
99
+ * `DEFAULT_STRAND_FIRST_SYNC_TIMEOUT_MS` (`strand-first-sync-gate.ts`). The module doc's
100
+ * "What still fails" list carries the first.
101
+ *
102
+ * What 3 500 costs, against 2 000: a peer that is genuinely gone holds each operation longer
103
+ * before it is abandoned and retried — a relayed dial or a reservation drive 14 s instead of
104
+ * 8 s, and a control-cohort dial of one peer across all its addresses 56 s instead of 32 s.
105
+ * Raise it further for a link slower still; lower it only on a deployment where EVERY machine
106
+ * of the party is that close, for the reason the "What still fails" list gives.
107
+ */
108
+ export const DECLARED_LINK_ROUND_TRIP_MS = 3500;
109
+ /**
110
+ * Link round trips one relayed connection setup costs: transport, encryption and multiplexer
111
+ * handshakes to the relay, the circuit open, then both handshakes again end to end through it.
112
+ * Measured at 8 one-way delays, which is 4 link round trips.
113
+ */
114
+ export const RELAYED_DIAL_ROUND_TRIPS = 4;
115
+ /**
116
+ * Link round trips one whole reservation drive is budgeted for
117
+ * (`relay-reservation.ts`'s `driveRelayReservation`, whose ONE deadline covers the dial, the
118
+ * reservation request and the wait together).
119
+ *
120
+ * The protocol work measured is 2 — dial the relay (1) plus request the reservation (1). It is
121
+ * budgeted at 4, the relayed-dial count, because the wait afterwards may instead be satisfied
122
+ * by libp2p's own relay discovery, which repeats both legs after identify has run; 4 is
123
+ * therefore the largest thing this one deadline can be asked to contain, and the poll interval
124
+ * (`DEFAULT_RELAY_RESERVE_POLL_MS`) rounds up on top of it.
125
+ */
126
+ export const RELAY_RESERVATION_ROUND_TRIPS = 4;
127
+ /**
128
+ * Link round trips one request-and-answer over an ALREADY-OPEN circuit costs: the protocol
129
+ * negotiation (1, measured at 2 one-way delays) plus the request and its response (1). It does
130
+ * not include a dial — a caller that may have to open the connection budgets
131
+ * {@link RELAYED_DIAL_ROUND_TRIPS} separately, which is exactly what the two-field shape of
132
+ * Optimystic's `dialTimeoutMs` / `responseTimeoutMs` pair is for.
133
+ */
134
+ export const CIRCUIT_REQUEST_ROUND_TRIPS = 2;
135
+ /**
136
+ * What a block-transfer push message's BYTES get to cross, on top of the latency
137
+ * {@link CIRCUIT_REQUEST_ROUND_TRIPS} covers, in milliseconds.
138
+ *
139
+ * This part is bandwidth, not latency, so it does not scale with the declared round trip: a
140
+ * chunk is capped at `PeerJoinBackfillConfig.maxChunkBytes` (1 MiB by default) and crossing it
141
+ * costs whatever the link's throughput costs.
142
+ *
143
+ * NOTE: 6 000 ms is not a measurement of any throughput — it is the residue of the 10 000 ms
144
+ * this deadline shipped as before it was split into a latency part and a transfer part, chosen
145
+ * so that at the declaration then in force (2 000 ms) the derived value stayed 10 000 and no
146
+ * fast link got slower. Nobody has measured how long 1 MiB takes to cross a relayed mobile
147
+ * link. If pushes ever time out with the transfer only part done, measure that and raise THIS,
148
+ * not the declared round trip.
149
+ */
150
+ export const PUSH_TRANSFER_ALLOWANCE_MS = 6000;
151
+ /**
152
+ * Resolve a host's declared link round trip, falling back to
153
+ * {@link DECLARED_LINK_ROUND_TRIP_MS}.
154
+ *
155
+ * Validated here rather than downstream because nothing downstream would: every consumer
156
+ * multiplies this value into a `setTimeout` deadline, where a zero silently turns a budget into
157
+ * "give up immediately" and a `NaN` turns it into "never time out".
158
+ *
159
+ * Both node bring-up paths call this EAGERLY — `CadreNode.start()`, and
160
+ * `StrandInstanceManager.buildStrandRuntime` behind `addStrand`/`resumeStrand` — so a bad
161
+ * declaration fails the same start that Optimystic's own check on `cohortQueryTimeoutMs` fails.
162
+ * The eager call is what makes that true: every budget derived here is behind a condition (a
163
+ * node with no control storage builds no catch-up, a node with no relay addrs drives no
164
+ * reservation), so waiting for a first consumer would let a broken declaration boot and then
165
+ * throw inside a best-effort path that logs and carries on.
166
+ */
167
+ export function resolveLinkRoundTripMs(linkRoundTripMs) {
168
+ if (linkRoundTripMs === undefined) {
169
+ return DECLARED_LINK_ROUND_TRIP_MS;
170
+ }
171
+ if (!Number.isFinite(linkRoundTripMs) || linkRoundTripMs <= 0) {
172
+ throw new Error(`network.linkRoundTripMs must be a finite number of milliseconds above zero, not ${String(linkRoundTripMs)}`);
173
+ }
174
+ return linkRoundTripMs;
175
+ }
176
+ /**
177
+ * Deadline for OPENING a connection to another machine that may only be reachable through a
178
+ * relay: {@link RELAYED_DIAL_ROUND_TRIPS} at the declared link round trip.
179
+ */
180
+ export function relayedDialBudgetMs(linkRoundTripMs) {
181
+ return RELAYED_DIAL_ROUND_TRIPS * resolveLinkRoundTripMs(linkRoundTripMs);
182
+ }
183
+ /**
184
+ * libp2p's two connection-manager limits for a node at the declared link, handed to
185
+ * `@optimystic/db-p2p`'s `NodeOptions.connectionManager` on the control node and every strand
186
+ * node.
187
+ *
188
+ * Both bound the same thing — opening a relayed connection, measured at 8 one-way link delays,
189
+ * which is {@link RELAYED_DIAL_ROUND_TRIPS} (4) link round trips — so both are
190
+ * {@link relayedDialBudgetMs}: 4 x 3 500 = 14 000 ms at the default declaration, covering the
191
+ * 12 094 ms measured at the supported 3-second link.
192
+ *
193
+ * The listener's limit is deliberately NOT smaller than the dialer's. The listener's clock
194
+ * starts only when the relay hands it the circuit, a few one-way delays after the dialer's
195
+ * started, and both sides finish the handshakes at about the same moment; so with equal limits
196
+ * the listener never discards a connection that the dialer's own dial would still accept. A
197
+ * listener limit below the dialer's is what produced the silent failure in the module doc.
198
+ *
199
+ * The cost of a longer `inboundUpgradeTimeout` is that a peer which opens a connection and then
200
+ * stalls its handshake holds that half-built connection 14 s instead of 10 s.
201
+ *
202
+ * NOTE: derived from the declaration alone, so a per-field override that raises a cadre dial
203
+ * budget above it (`controlCohort.perAddressDialTimeoutMs`, `strandBackfill.dialTimeoutMs`)
204
+ * does not raise these; a dial that outlasts the listener's limit gets the silent failure
205
+ * again. If such overrides start being used for slow links, raise the declaration instead or
206
+ * take the largest configured dial budget here.
207
+ */
208
+ export function connectionManagerTimeouts(linkRoundTripMs) {
209
+ const budgetMs = relayedDialBudgetMs(linkRoundTripMs);
210
+ return { dialTimeout: budgetMs, inboundUpgradeTimeout: budgetMs };
211
+ }
212
+ /**
213
+ * Deadline for one whole relay reservation drive: {@link RELAY_RESERVATION_ROUND_TRIPS} at the
214
+ * declared link round trip.
215
+ */
216
+ export function relayReservationBudgetMs(linkRoundTripMs) {
217
+ return RELAY_RESERVATION_ROUND_TRIPS * resolveLinkRoundTripMs(linkRoundTripMs);
218
+ }
219
+ /**
220
+ * Deadline for one request and its answer over a circuit that is already open —
221
+ * {@link CIRCUIT_REQUEST_ROUND_TRIPS} at the declared link round trip, plus `transferAllowanceMs`
222
+ * for the payload's own bytes.
223
+ */
224
+ export function circuitRequestBudgetMs(linkRoundTripMs, transferAllowanceMs = PUSH_TRANSFER_ALLOWANCE_MS) {
225
+ return CIRCUIT_REQUEST_ROUND_TRIPS * resolveLinkRoundTripMs(linkRoundTripMs) + transferAllowanceMs;
226
+ }
227
+ /**
228
+ * The dial and response deadlines a peer-join catch-up push needs at a declared link. One
229
+ * helper rather than two call-site expressions, because the two construction sites
230
+ * (`CadreNode`'s control catch-up and `StrandInstanceManager`'s per-strand one) and
231
+ * `DEFAULT_PEER_JOIN_BACKFILL` must not drift apart.
232
+ */
233
+ export function peerJoinPushBudget(linkRoundTripMs) {
234
+ return {
235
+ dialTimeoutMs: relayedDialBudgetMs(linkRoundTripMs),
236
+ responseTimeoutMs: circuitRequestBudgetMs(linkRoundTripMs)
237
+ };
238
+ }
239
+ //# sourceMappingURL=link-budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-budget.js","sourceRoot":"","sources":["../src/link-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AAIH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAE/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,eAAwB;IAC9D,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO,2BAA2B,CAAC;IACpC,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,eAAe,IAAI,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CACd,mFAAmF,MAAM,CAAC,eAAe,CAAC,EAAE,CAC5G,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,eAAwB;IAC3D,OAAO,wBAAwB,GAAG,sBAAsB,CAAC,eAAe,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,yBAAyB,CAAC,eAAwB;IACjE,MAAM,QAAQ,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;IACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,qBAAqB,EAAE,QAAQ,EAAE,CAAC;AACnE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,eAAwB;IAChE,OAAO,6BAA6B,GAAG,sBAAsB,CAAC,eAAe,CAAC,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACrC,eAAwB,EACxB,mBAAmB,GAAG,0BAA0B;IAEhD,OAAO,2BAA2B,GAAG,sBAAsB,CAAC,eAAe,CAAC,GAAG,mBAAmB,CAAC;AACpG,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,eAAwB;IAC1D,OAAO;QACN,aAAa,EAAE,mBAAmB,CAAC,eAAe,CAAC;QACnD,iBAAiB,EAAE,sBAAsB,CAAC,eAAe,CAAC;KAC1D,CAAC;AACH,CAAC"}
@@ -25,28 +25,41 @@
25
25
  import type { Connection } from '@libp2p/interface';
26
26
  import type { Multiaddr } from '@multiformats/multiaddr';
27
27
  /**
28
- * Default limit on ONE address's dial attempt, in ms.
28
+ * Default limit on ONE address's dial attempt, in ms, at the DEFAULT declared link round trip:
29
+ * `RELAYED_DIAL_ROUND_TRIPS` (4) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms) = 14 000 ms. It was
30
+ * a fixed 8000 ms before it was derived.
29
31
  *
30
32
  * It has to cover the slowest address that should succeed, because an attempt
31
33
  * that needs longer fails the same way on every retry. That is a relayed dial on
32
34
  * a mobile link: connect to the relay (transport, encryption and multiplexer
33
35
  * handshakes, when no relay connection is open yet), open the circuit, then run
34
- * both handshakes again end to end through the relay at roughly twice the
35
- * round-trip time. At a few hundred ms per round trip that is several seconds.
36
- * A direct dial that works is far quicker — a phone's WebSocket dial to a node
37
- * forwarded over `adb reverse` measured 1.6 s end to end. 8 s covers the relayed
38
- * case with some margin while still abandoning a silently dropped address
39
- * sooner than libp2p's own 10 s dial timeout would.
36
+ * both handshakes again end to end through the relay. `link-budget.ts` is where that
37
+ * reasoning is now a measured count instead of an estimate — four link round trips, measured at
38
+ * 12 094 ms on a link whose round trip is 3 s — so the value MOVES with a host's
39
+ * `NetworkConfig.linkRoundTripMs` rather than pinning the band this node can reach to whatever
40
+ * number was typed here. A direct dial that works is far quicker — a phone's WebSocket dial to
41
+ * a node forwarded over `adb reverse` measured 1.6 s end to end.
42
+ *
43
+ * Deriving it rather than leaving it fixed is deliberate: at 8000 ms fixed, the per-address
44
+ * limit — not libp2p's own 10 s dial timeout — was the first thing to cut a relayed dial off,
45
+ * from about 1000 ms of one-way link delay upward. Nothing said so, and a reader raising
46
+ * `DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS` below would not have found it.
40
47
  *
41
48
  * NOTE: a `/p2p-circuit/webrtc` address also negotiates a WebRTC session after
42
49
  * the relay leg. If such dials are ever seen failing at exactly this limit, raise
43
- * it (or `network.controlCohort.perAddressDialTimeoutMs` on the affected nodes)
44
- * rather than the per-peer limit, which cannot help an address that is itself
50
+ * the declared link round trip (or `network.controlCohort.perAddressDialTimeoutMs` on the
51
+ * affected nodes) rather than the per-peer limit, which cannot help an address that is itself
45
52
  * cut off.
46
53
  *
47
54
  * Override per node with `network.controlCohort.perAddressDialTimeoutMs`.
48
55
  */
49
- export declare const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = 8000;
56
+ export declare const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS: number;
57
+ /**
58
+ * How many whole per-address dial attempts {@link DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS}
59
+ * budgets for: the address that works plus the three dead ones a lent cadre-host node is
60
+ * observed to report ahead of it (loopback and LAN WebSocket addresses, plus virtual adapters).
61
+ */
62
+ export declare const CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS = 4;
50
63
  /**
51
64
  * Default limit on dialing ONE peer — every candidate address together — in ms.
52
65
  *
@@ -59,18 +72,24 @@ export declare const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = 8000;
59
72
  *
60
73
  * Sized to fit a typical list with dead addresses ahead of the one that works:
61
74
  * a lent cadre-host node reports two to four addresses a phone can dial
62
- * (loopback and LAN WebSocket addresses, plus any virtual adapters). Three
63
- * silently dropped addresses cost 3 × 8 s = 24 s, leaving 6 s for the working
64
- * address after them — well over the 1.6 s the phone measured. A peer whose
65
- * working address sits behind four or more dropped ones does not fit, and fails
66
- * each pass the same way; if that shows up, the remedy is ordering (try the
67
- * address that last connected first), not a larger number here.
75
+ * (loopback and LAN WebSocket addresses, plus any virtual adapters). So it is
76
+ * {@link CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS} whole per-address budgets — three silently
77
+ * dropped addresses, then the one that works, each getting the FULL per-address limit. A peer
78
+ * whose working address sits behind four or more dropped ones does not fit, and fails each pass
79
+ * the same way; if that shows up, the remedy is ordering (try the address that last connected
80
+ * first), not a larger number here.
81
+ *
82
+ * Counted as whole per-address budgets rather than the flat 30_000 it was before, because the
83
+ * old number left only 6 s after three dropped addresses — enough for the 1.6 s direct dial the
84
+ * phone measured, but NOT for the relayed dial the per-address limit is sized to cover. A peer
85
+ * whose only working address was a relayed one behind two dead ones therefore could not be
86
+ * dialled at all, and the arithmetic in this comment was what said otherwise.
68
87
  *
69
88
  * Override per node with `network.controlCohort.dialTimeoutMs` — tests that
70
89
  * drive dead addresses on purpose set it low so a pass's duration is a chosen
71
90
  * number rather than a transitive libp2p default stretched by machine load.
72
91
  */
73
- export declare const DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS = 30000;
92
+ export declare const DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS: number;
74
93
  /** Time limits for dialing one peer from a list of candidate addresses. */
75
94
  export interface PeerDialBudget {
76
95
  /** Limit on one address's attempt, in ms. */
package/dist/peer-dial.js CHANGED
@@ -24,30 +24,44 @@
24
24
  */
25
25
  import debug from 'debug';
26
26
  import { withDeadline } from './control-stream.js';
27
+ import { relayedDialBudgetMs } from './link-budget.js';
27
28
  const log = debug('sereus:cadre:peer-dial');
28
29
  /**
29
- * Default limit on ONE address's dial attempt, in ms.
30
+ * Default limit on ONE address's dial attempt, in ms, at the DEFAULT declared link round trip:
31
+ * `RELAYED_DIAL_ROUND_TRIPS` (4) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms) = 14 000 ms. It was
32
+ * a fixed 8000 ms before it was derived.
30
33
  *
31
34
  * It has to cover the slowest address that should succeed, because an attempt
32
35
  * that needs longer fails the same way on every retry. That is a relayed dial on
33
36
  * a mobile link: connect to the relay (transport, encryption and multiplexer
34
37
  * handshakes, when no relay connection is open yet), open the circuit, then run
35
- * both handshakes again end to end through the relay at roughly twice the
36
- * round-trip time. At a few hundred ms per round trip that is several seconds.
37
- * A direct dial that works is far quicker — a phone's WebSocket dial to a node
38
- * forwarded over `adb reverse` measured 1.6 s end to end. 8 s covers the relayed
39
- * case with some margin while still abandoning a silently dropped address
40
- * sooner than libp2p's own 10 s dial timeout would.
38
+ * both handshakes again end to end through the relay. `link-budget.ts` is where that
39
+ * reasoning is now a measured count instead of an estimate — four link round trips, measured at
40
+ * 12 094 ms on a link whose round trip is 3 s — so the value MOVES with a host's
41
+ * `NetworkConfig.linkRoundTripMs` rather than pinning the band this node can reach to whatever
42
+ * number was typed here. A direct dial that works is far quicker — a phone's WebSocket dial to
43
+ * a node forwarded over `adb reverse` measured 1.6 s end to end.
44
+ *
45
+ * Deriving it rather than leaving it fixed is deliberate: at 8000 ms fixed, the per-address
46
+ * limit — not libp2p's own 10 s dial timeout — was the first thing to cut a relayed dial off,
47
+ * from about 1000 ms of one-way link delay upward. Nothing said so, and a reader raising
48
+ * `DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS` below would not have found it.
41
49
  *
42
50
  * NOTE: a `/p2p-circuit/webrtc` address also negotiates a WebRTC session after
43
51
  * the relay leg. If such dials are ever seen failing at exactly this limit, raise
44
- * it (or `network.controlCohort.perAddressDialTimeoutMs` on the affected nodes)
45
- * rather than the per-peer limit, which cannot help an address that is itself
52
+ * the declared link round trip (or `network.controlCohort.perAddressDialTimeoutMs` on the
53
+ * affected nodes) rather than the per-peer limit, which cannot help an address that is itself
46
54
  * cut off.
47
55
  *
48
56
  * Override per node with `network.controlCohort.perAddressDialTimeoutMs`.
49
57
  */
50
- export const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = 8000;
58
+ export const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = relayedDialBudgetMs();
59
+ /**
60
+ * How many whole per-address dial attempts {@link DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS}
61
+ * budgets for: the address that works plus the three dead ones a lent cadre-host node is
62
+ * observed to report ahead of it (loopback and LAN WebSocket addresses, plus virtual adapters).
63
+ */
64
+ export const CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS = 4;
51
65
  /**
52
66
  * Default limit on dialing ONE peer — every candidate address together — in ms.
53
67
  *
@@ -60,18 +74,24 @@ export const DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS = 8000;
60
74
  *
61
75
  * Sized to fit a typical list with dead addresses ahead of the one that works:
62
76
  * a lent cadre-host node reports two to four addresses a phone can dial
63
- * (loopback and LAN WebSocket addresses, plus any virtual adapters). Three
64
- * silently dropped addresses cost 3 × 8 s = 24 s, leaving 6 s for the working
65
- * address after them — well over the 1.6 s the phone measured. A peer whose
66
- * working address sits behind four or more dropped ones does not fit, and fails
67
- * each pass the same way; if that shows up, the remedy is ordering (try the
68
- * address that last connected first), not a larger number here.
77
+ * (loopback and LAN WebSocket addresses, plus any virtual adapters). So it is
78
+ * {@link CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS} whole per-address budgets — three silently
79
+ * dropped addresses, then the one that works, each getting the FULL per-address limit. A peer
80
+ * whose working address sits behind four or more dropped ones does not fit, and fails each pass
81
+ * the same way; if that shows up, the remedy is ordering (try the address that last connected
82
+ * first), not a larger number here.
83
+ *
84
+ * Counted as whole per-address budgets rather than the flat 30_000 it was before, because the
85
+ * old number left only 6 s after three dropped addresses — enough for the 1.6 s direct dial the
86
+ * phone measured, but NOT for the relayed dial the per-address limit is sized to cover. A peer
87
+ * whose only working address was a relayed one behind two dead ones therefore could not be
88
+ * dialled at all, and the arithmetic in this comment was what said otherwise.
69
89
  *
70
90
  * Override per node with `network.controlCohort.dialTimeoutMs` — tests that
71
91
  * drive dead addresses on purpose set it low so a pass's duration is a chosen
72
92
  * number rather than a transitive libp2p default stretched by machine load.
73
93
  */
74
- export const DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS = 30000;
94
+ export const DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS = CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS * DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS;
75
95
  /** {@link PeerDialBudget} built from the two defaults above. */
76
96
  export const DEFAULT_PEER_DIAL_BUDGET = {
77
97
  perAddressMs: DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS,