1
2
3
4
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
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
89
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//! How long a caller must wait for a Trust Task, given what the VTA may do with
//! it on the way.
//!
//! # The failure this exists to prevent
//!
//! A client's budget and the VTA's own were two unrelated literals in two
//! crates, and they inverted. `create_did_webvh` allowed 60s; the VTA, relaying
//! the mint onward to a DID hosting server, spends up to
//! [`TSP_REPLY_TIMEOUT_SECS`] on the first send and — under the §7.2.2
//! self-repair path in `recover_send_tsp` — the same again on the resend after
//! re-forming the relationship. Observed live: 60.27s, 60.58s. The client gave
//! up a few hundred milliseconds before the VTA's real answer arrived, on all
//! four attempts, so the operator saw "timed out waiting for the TSP reply"
//! instead of the diagnosis, **every time and by construction**.
//!
//! Neither number was wrong on its own. What was missing was anything relating
//! them, so nothing could notice they had crossed.
//!
//! # The rule
//!
//! > A caller's budget must strictly exceed the worst case of whoever it is
//! > waiting on.
//!
//! [`min_relay_budget_secs`] is that bound, derived from the VTA's own constant
//! rather than guessed alongside it, and `budget_floor_holds_for_every_task`
//! pins every call site against it. The arithmetic is a test, not a coincidence.
//!
//! # Why the constant lives here
//!
//! It is a fact about a conversation, so it cannot belong to one end of it.
//! `vta-service` reads [`TSP_REPLY_TIMEOUT_SECS`] from here rather than keeping
//! its own copy, exactly as it already reads
//! [`retry_safety`](crate::retry_safety) — the precedent this module follows,
//! and for the same reason: a shared fact with two homes has none.
//!
//! Like [`retry_safety`](crate::retry_safety) this module is always-on and
//! dependency-free, so the service can consult it without pulling in the client.
use cratetrust_tasks;
/// How long the VTA waits for a peer's reply on one TSP hop.
///
/// The authoritative copy. `vta-service`'s `operations::outbound` reads this;
/// it must not define its own, or the two ends can drift apart silently — which
/// is the whole defect this module was written for.
pub const TSP_REPLY_TIMEOUT_SECS: u64 = 30;
/// Reply-awaiting hops a relayed task may spend at the VTA: the first send,
/// then the §7.2.2 self-repair resend after the relationship is re-formed.
///
/// Two, not one, because the resend is where a task whose URI is blind-retry-
/// safe spends a second full window — and that is not decided by the task the
/// *client* named. The VTA relays under a different URI, so a client cannot
/// reason about it from its own request. Hence the floor assumes the resend
/// happens.
const RELAY_HOPS: u64 = 2;
/// Slack between those hops for the relationship re-form itself.
///
/// Measured sub-second in the field (the whole overshoot that broke
/// `create_did_webvh` was 0.58s), so this is deliberately generous: it is
/// bounding a network round trip whose cost we do not otherwise model, and
/// being too small here re-creates the defect while being too large costs only
/// a slower report of a peer that is genuinely gone.
const REFORM_MARGIN_SECS: u64 = 10;
/// Headroom between the VTA's worst case and the client's budget, covering the
/// legs this module does not model: mediator queueing either way, and the
/// client's own send before its clock starts.
const CLIENT_MARGIN_SECS: u64 = 10;
// The margins are the only thing standing between a derived floor and the
// hand-picked literals it replaced, so a zeroed one is worth refusing to
// compile. Stated here rather than as a test because it is knowable without
// running anything — and a test asserting on constants is one clippy is right
// to distrust.
const _: = assert!;
const _: = assert!;
/// The longest the VTA can take on a task it relays onward before answering.
pub const
/// The smallest client budget that can outlast [`relay_worst_case_secs`] — i.e.
/// the smallest one on which the VTA's real error is reachable at all.
///
/// A budget below this does not make a relayed call fail faster. It makes it
/// fail *uninformatively*, which is strictly worse: the work still happens, the
/// answer still comes, and the caller is no longer listening.
pub const
/// Tasks the VTA may answer by calling a third party and waiting for a reply.
///
/// These are the tasks whose budget must clear [`min_relay_budget_secs`]: the
/// VTA's own wait is *inside* the caller's, so a caller that allows less than
/// the VTA can spend is guaranteed to stop listening before the answer comes.
/// Everything absent is served from the VTA's own storage and needs only the
/// caller's own patience.
///
/// # Conservative by construction
///
/// Several of these relay only for *some* payloads — `services/enable` only for
/// `service: "didcomm"` (the mediator handshake), `vault/proxy-login` only for
/// a `password` entry, `provision/integration` only when the template names a
/// `WEBVH_SERVER`, and the webvh DID verbs only for server-managed (non-
/// serverless) DIDs. A URI cannot distinguish those, so a task that relays
/// under *any* payload is listed. Over-listing costs a slower report of a peer
/// that is genuinely gone; under-listing costs the silent, undiagnosable
/// timeout this module exists to prevent. Same asymmetry, and same answer, as
/// [`retry_safety`](crate::retry_safety)'s.
///
/// # Keeping it true
///
/// This is a fact about `vta-service`'s handlers, not about the URI, so nothing
/// here can derive it — `relay_list_names_only_real_tasks` can only catch a URI
/// that no longer exists. **If you give a handler an onward call that waits for
/// a reply, add its URI here.** The transport it relays over does not matter:
/// TSP is the worst case this floor is sized for, and DIDComm and REST both sit
/// inside it.
// names the deprecated 0.1 proxy-login URI on purpose — still served
pub const RELAYS_ONWARD: & = &;
/// Whether the VTA may answer `type_uri` by waiting on a third party.
/// The budget a caller should actually use for `type_uri`, given what it asked
/// for.
///
/// For a relaying task this raises `requested` to [`min_relay_budget_secs`]; it
/// never lowers anything. Raising rather than replacing keeps a caller that
/// deliberately allows longer — a slow link, a patient batch job — in charge of
/// its own patience, while making the incoherent case impossible: a budget
/// under the floor does not fail a relayed call faster, it fails it blind.