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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
//! Wire types for the loopback admin JSON-RPC surface (`appendix-local-admin-http.md`).
//!
//! Shared between the daemon (which implements [`AdminRpcServer`] over a
//! local cache + peer table) and the user CLI (which speaks
//! [`AdminRpcClient`] from `decdn node …`). jsonrpsee's
//! `#[rpc(server, client)]` macro consumes the source `AdminRpc` trait
//! and emits separate `AdminRpcServer` / `AdminRpcClient` traits in its
//! place; the original `AdminRpc` name is not a linkable rustdoc item,
//! hence the bare backticks.
//!
//! DTO fields are deliberately wire-only: no engine handles, no
//! peer-table types, no daemon runtime types. They use simple owned
//! values (`String`, `u64`, primitive arrays). Pulling `decdn-common`
//! into the CLI does not pull the daemon runtime.
//!
//! The helper [`parse_hash_arg`] returns [`struct@Hash`] from the
//! `decdn-config-types` leaf crate (the same leaf the typed config
//! fields `DecompressMode`, `RetryPolicy`, `OriginUrl`, `PinnedHashes`
//! come from). That keeps `decdn-cache`/iroh-blobs out of the publisher
//! CLI's dependency tree (#578); the daemon's `evict` handler converts
//! the leaf hash to the blob-store hash at its boundary via
//! `decdn_cache::to_store_hash`. The parser is used only by that
//! handler today.
use Hash;
use RpcResult;
use rpc;
use ErrorObjectOwned;
use ;
/// Whether the node's local iroh key is the one bound to its operator address
/// on-chain (#1034).
///
/// This is a correctness signal, not a liveness one. `SlashJudge` resolves an
/// accused node through `CapacityBond.nodeIdOf`, so a node serving under a key
/// no binding points at is **unslashable**: it earns normally while its bond is
/// unreachable, which is a protocol fault rather than an outage — and one with
/// no symptom the operator would otherwise notice. A key rotation that swapped
/// `node.secret` without submitting `bindNodeId` lands exactly here, which is
/// why `decdn node rotate-key` orders its steps to make the state unreachable
/// and why the daemon reports it when it happens anyway.
///
/// Advisory by construction. The check is one RPC at bring-up, and a daemon
/// that refused to start on it would be brickable by a transient RPC failure
/// and unable to run the very rotation that repairs it.
/// Response body for `admin_v1_health`. Shared between the server
/// (serializes) and `decdn node health` (deserializes via the generated
/// client). Intentionally minimal: this method exists so an operator
/// script can answer "is this admin port the node I think it is, and
/// has it been up since I started watching?" with one RPC call.
/// Request body for `admin_v1_evict` (issue #279).
/// Response body for `admin_v1_evict`.
///
/// Carries both the pre-evict snapshot (always populated, so an operator's
/// audit log captures size and pin status at the moment of evict) and a
/// `dry_run` flag indicating whether the cache state was actually mutated.
/// Pre-evict snapshot returned inside [`EvictResponse::preview`].
/// Mirrors the cache engine's `EvictionPreview` minus the
/// engine-internal `served` field (folded into
/// [`EvictResponse::was_present`]).
/// Response body for `admin_v1_reload` (issue #373). Reports the
/// post-reload values the SIGHUP arm logs to stdout, so operators using
/// the RPC path get the same after-state confirmation without scraping
/// `tracing` output. Only the *reloadable* fields appear here: changes
/// to non-reloadable sections are logged by the reload path itself
/// (one `info!` per changed-but-ignored field) and aren't echoed in
/// the RPC response.
/// Request body for `admin_v1_drain` (issue #244). Required, as is its
/// one field: a caller states which shutdown ordering it wants.
/// Response body for `admin_v1_drain` (issue #244). `initiated: true`
/// reports that the trigger fired; `wait_admin_honored` reports
/// whether the server actually plans to keep admin alive through
/// `router.shutdown` (issue #604). The trigger is first-writer-wins, so
/// a `wait_admin: true` request that loses the race to an earlier drain
/// without it gets `false` here. The `decdn node drain --wait` client
/// then refuses to enter the polling loop instead of treating the
/// imminent ECONNREFUSED as drain completion. A `true` ack covers
/// admin-RPC races only: a SIGINT/SIGTERM that wins the runtime's
/// shutdown select still closes admin early.
/// Per-bucket fill stat for `admin_v1_status` (issue #741). One entry
/// per *non-empty* Kademlia k-bucket — empty buckets (the vast majority
/// of the 256-bucket keyspace on a small network) are omitted so the
/// snapshot stays compact. The bucket capacity is the same Kademlia `K`
/// for every bucket and so lives once on [`RoutingHealth::bucket_capacity`]
/// rather than being repeated here.
/// Routing-table health section of `admin_v1_status` (issue #741).
/// DHT provider-record store utilization for `admin_v1_status` (issue #741).
/// Republish-scheduler health for `admin_v1_status` (issue #741).
/// Response body for `admin_v1_status` (issue #741): a single-shot
/// snapshot of this node's DHT participation health, so an operator can
/// diagnose cold-start / routing-table degradation without scraping
/// Prometheus or reading logs.
/// JSON view of one lane this node provides against a `PaymentPool`,
/// emitted by `admin_v1_lanes` (issue #749). A lane is keyed by
/// `(pool_id, signer, provider)` — `decdn_incentive::LaneKey`. Defined
/// separately from `decdn-incentive`'s internal `LaneState` so the
/// replay-critical `last_*` accessors, the `U256` money types, and any
/// future internal fields can't leak into the wire format: every field
/// here is a plain owned wire value. Shared between the server
/// (serializes) and `decdn node lanes` (deserializes via the generated
/// client).
///
/// Money amounts are reported in **micro-USDC** (`u64`) — the same base
/// unit `blockchain.redeem_threshold_micro_usdc` is configured in. The
/// underlying `LaneState` carries them as `U256`; the server narrows with
/// `u64::try_from(...).unwrap_or(u64::MAX)`, so a value that somehow
/// exceeded `u64::MAX` micro-USDC (~1.8e13 USDC — unreachable for a real
/// pool) saturates rather than wraps.
/// Response body for `admin_v1_lanes` (issue #749). Shared between the
/// server (serializes), `decdn node lanes` (deserializes via the
/// generated client), and the integration tests.
/// One lane the node pays on, as the buyer's own store records it
/// (`admin_v1_pools`). The buyer-side mirror of [`LaneSnapshot`]: where that
/// reports what a lane has accrued *against* this node, this reports what this
/// node has already promised to pay a provider.
/// One `PaymentPool` deposit the node's buyer leg tracks (`admin_v1_pools`).
///
/// The amounts are the *stored* ones, not a chain read: this is what the daemon
/// believes, which is the half an operator cannot otherwise see. A disagreement
/// with `PaymentPool.getPool` is itself the diagnostic.
/// Snapshot of the node's buyer-side `PaymentPool` state (`admin_v1_pools`).
///
/// This is the only way to read `buyer.redb` on a running node: `redb` holds a
/// process-exclusive lock on that file for the daemon's lifetime, so no CLI can
/// open it — not even read-only — while the node is up.
/// One slash detected against this node's operator (`SlashJudge.Slashed`,
/// #1032, G-NODE-05). Surfaced so an operator (or a keeper script) can notice a
/// slash and file `decdn appeal slash` within the 30-day window without watching
/// the chain directly.
/// Snapshot of every slash the watcher has detected against this node's
/// operator (#1032). Empty list when none — a clean operator.
/// JSON-RPC error code: the request shape was wrong (bad hex, etc.).
/// Matches the standard JSON-RPC 2.0 `Invalid params` code.
pub const INVALID_PARAMS_CODE: i32 = -32_602;
/// JSON-RPC error code: the cache layer reported an error during evict
/// (e.g. the underlying iroh-blobs store I/O failed when persisting the
/// evicted-hash log).
pub const CACHE_ERROR_CODE: i32 = -32_002;
/// JSON-RPC error code: the node was started without a config file
/// path, so `admin_v1_reload` has nothing to re-read. Distinct from
/// [`RELOAD_ERROR_CODE`] so an operator script can tell "this node
/// can't reload, ever, until it's restarted with `--config <path>`"
/// from "this node tried and failed".
pub const CONFIG_PATH_UNSET_CODE: i32 = -32_003;
/// JSON-RPC error code: `RuntimeReloadState::reload` returned an error
/// (file unreadable, malformed TOML, rejected resolution, mutex poison,
/// log-level setter failed). Mirrors the SIGHUP arm's "previous values
/// retained" guarantee — by the time this surfaces, the running config
/// is unchanged.
pub const RELOAD_ERROR_CODE: i32 = -32_004;
/// JSON-RPC error code: `admin_v1_status` was called on a node whose DHT
/// subsystem is not wired (e.g. a future CLI-only or test invocation that
/// brings up the admin surface without the DHT handler). A benign,
/// expected configuration state — distinct from a generic failure so an
/// operator gets "this node has no DHT to report on" rather than a
/// confusing transport error, and distinct from [`DHT_POISONED_CODE`] so
/// it isn't confused with an in-process fault.
pub const DHT_UNAVAILABLE_CODE: i32 = -32_005;
/// JSON-RPC error code: `admin_v1_status` found a DHT subsystem mutex
/// (routing table or record store) poisoned — i.e. a thread panicked
/// while holding it, so the DHT's in-memory state may be inconsistent.
/// This is a severe in-process fault, kept distinct from the benign
/// [`DHT_UNAVAILABLE_CODE`] ("no DHT wired") so an operator script can
/// tell "this node never had a DHT" from "this node's DHT just broke".
/// The server also logs the poisoning at `error` level.
pub const DHT_POISONED_CODE: i32 = -32_006;
/// JSON-RPC error code: `admin_v1_lanes` could not read the pool state
/// store (issue #749) — e.g. the redb load failed or a poisoned
/// in-memory mutex. A read-side fault distinct from the cache/DHT codes
/// so an operator script can tell "lane snapshot is unavailable right
/// now" from a generic transport failure. The server also logs the
/// underlying store error.
pub const POOL_STORE_ERROR_CODE: i32 = -32_007;
/// JSON-RPC error code: `admin_v1_slashes` was called on a node whose slash
/// watcher is not wired (e.g. no `slash_judge_address`, or a test/CLI-only
/// invocation). Benign config state, distinct from a generic failure so an
/// operator gets "no slash detection on this node" rather than an opaque error.
pub const SLASH_DETECTION_UNAVAILABLE_CODE: i32 = -32_009;
/// JSON-RPC error code: `admin_v1_pools` could not read the buyer pool store.
/// Distinct from [`POOL_STORE_ERROR_CODE`], which covers the seller-side lane
/// store: the two are different files, and a fault in one says nothing about
/// the other.
pub const BUYER_POOL_STORE_ERROR_CODE: i32 = -32_010;
/// JSON-RPC error code: `admin_v1_pools` was called on an admin surface with
/// no buyer pool store attached, so it can say nothing about what this node
/// tracks.
///
/// Deliberately an error rather than an empty list — unlike `admin_v1_lanes`,
/// which reports zero lanes as a legitimate state. "This node does not pay for
/// pulls" and "this node owns no pools" demand opposite responses from an
/// operator hunting a stranded deposit, and rendering the first as the second
/// is the ambiguity this method exists to remove.
///
/// The production runtime attaches the buyer store unconditionally, so a
/// running daemon does not answer this: it covers a hand-built `AdminState` —
/// a test, or a future bring-up with no buy leg — the same posture as
/// [`DHT_UNAVAILABLE_CODE`]. The alternative for that arm would be an empty
/// list, which is the answer this code exists to avoid giving.
pub const BUYER_POOL_UNAVAILABLE_CODE: i32 = -32_011;
/// Admin RPC surface. Versioned via the namespace prefix
/// (`admin_v1_...`): new methods may be added backwards-compatibly
/// within `v1`, a breaking change cuts over to `admin_v2_...`.
/// Decode a 64-character hex BLAKE3 hash into a [`struct@Hash`].
///
/// Goes through `alloy::primitives::hex::decode` (case-insensitive,
/// `0x`/`0X`-prefix-tolerant) rather than `Hash::from_str` so operators
/// may paste a `0x`-prefixed hash and get a uniform `INVALID_PARAMS`
/// error on malformed input. (The leaf [`struct@Hash`]'s own `FromStr`
/// is panic-free since #578 — unlike the old iroh-blobs `Hash::from_str`
/// which fell through to a base32 decoder that panicked on a
/// wrong-size output buffer — but it does not accept a `0x` prefix, so
/// the alloy path is kept for the operator ergonomics.)
///
/// # Errors
/// Returns an [`ErrorObjectOwned`] with [`INVALID_PARAMS_CODE`] when the
/// input is not valid hex or doesn't decode to exactly 32 bytes.