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
//! Failure-class taxonomy for the buyer-side `openPool` path (#966).
//!
//! The buyer `open_pool` kernel (`decdn-client`) can fail three ways
//! that an operator must triage differently:
//!
//! - **`InsufficientDeposit`** — a *misconfiguration*: the node's USDC balance
//! or standing allowance cannot cover the deposit; or the deposit is zero —
//! either as requested, or as the balance delta actually received under a
//! fee-on-transfer token; or the credited deposit is below the
//! governance-set `minDeposit` Sybil floor. (A zero deposit cannot be
//! requested: both the daemon
//! and the CLI validate `buyer_working_deposit_micro_usdc` / the
//! `--working-deposit-micro-usdc` flag `> 0` at config load, so the reachable
//! zero here is the received-delta one.) The fix is operator-side (fund or
//! resize the deposit), not infrastructure.
//! - **`ContractRevert`** — any *other* deterministic on-chain revert (a
//! paused contract, a future revert reason). The deposit was not escrowed;
//! the cause is on-chain state, not this node's wallet or RPC.
//! - **`RpcError`** — a *transient* transport/RPC fault (connectivity, a
//! timed out receipt wait, a transaction-nonce blip — the sender's tx
//! sequence number, unrelated to a voucher). Retrying typically clears it;
//! the fix is infrastructure-side.
//!
//! Splitting these lets the node bump the matching
//! `decdn_pool_open_failures_{insufficient_deposit,contract_revert,rpc_error}_total`
//! sibling counter (a plain counter field carries no label dimension, so each class is its own
//! counter rather than one labeled `{reason=…}` series) and emit the same
//! `reason` token as a structured-log field, so a dashboard distinguishes "the
//! operator under-funded the gas/USDC wallet" from "the RPC endpoint is flaky"
//! — the whole point of #966. The classification is driven by the alloy
//! error's *revert data*: a deterministic revert carries ABI-encoded error data
//! (caught at gas estimation, so it surfaces on `send()` before a receipt),
//! whereas a transport fault carries none. A present revert selector is decoded
//! against the known insufficient-deposit error signatures to split
//! `InsufficientDeposit` from a generic `ContractRevert`. A token that reverts
//! in the older `Error(string)` style carries no custom-error selector, so its
//! message is matched for the same shortfall — an under-funded wallet reads as
//! `InsufficientDeposit` whichever revert style the deployed USDC uses.
use Bytes;
use sol;
use ;
sol!
/// Which class of failure aborted a buyer `openPool` attempt (#966). Carried
/// through the `anyhow` error chain as typed context so the metrics layer can
/// bump the matching `decdn_pool_open_failures_{reason}_total` sibling
/// counter (one counter per class — a plain counter field carries no label dimension) and
/// attach a structured `reason` log field, while the human-readable message is
/// preserved for logs.
///
/// The sibling-counter shape is the settled convention (#1475), not a stopgap:
/// these three classes have unrelated operator remedies (fund the wallet / fix
/// the contract call / chase the RPC) *and* no meaningful aggregate — "how many
/// pool opens failed" is not a question with one answer or one response. `decdn_probe_hold_unavailable_total` is the one
/// labeled reason split, and it is labeled precisely because its values *do*
/// share one aggregate and one budget axis.
/// Whether ABI-encoded `revert_data` begins with one of the known
/// insufficient-deposit error selectors (the leading 4 bytes). A too-short
/// payload (no full selector) is treated as not-matching, so it falls through to
/// the generic `ContractRevert` class rather than panicking on a slice.
///
/// A token that predates custom errors reverts `Error(string)` instead, so the
/// string payload is matched as well — see [`is_erc20_shortfall_string`].
/// Whether `revert_data` is a solidity `Error(string)` revert whose message is
/// an ERC-20 balance or allowance shortfall.
///
/// `PaymentPool.openPool` bubbles whatever its `safeTransferFrom` reverts, and
/// the USDC deployments the network settles against are not all
/// `OpenZeppelin` v5: a token built on the string-revert `require` style emits
/// `Error("ERC20: transfer amount exceeds balance")` rather than the
/// `ERC20InsufficientBalance` custom error. Both mean the same thing to an
/// operator — fund the wallet — so both classify as
/// [`PoolOpenFailureReason::InsufficientDeposit`]. Matching on the message
/// text is what the payload affords: a string revert carries no structured
/// discriminant, and the alternative is reporting an under-funded wallet as an
/// opaque `ContractRevert` that names no remedy.
/// Whether an ERC-20 revert is specifically an *allowance* shortfall
/// (`ERC20InsufficientAllowance`) — the one class a just-in-time `approve`
/// can fix. An insufficient-balance revert, a zero-amount revert, or any
/// other selector returns `false`: an `approve` cannot recover those, so the
/// caller must treat them as terminal. A string-revert token spells the same
/// shortfall as `Error("ERC20: insufficient allowance")`, which counts too.
/// Pass alloy's `Error::as_revert_data()`.
/// Whether a `topUp` revert is `PoolNotOpen`: the pool is `Closing` or
/// `Closed` and accepts no funds. Pass alloy's `Error::as_revert_data()`.