Repository navigation
feat(cli): add decdn node channels payment-channel snapshot (#749) - #791
Conversation
Add a `decdn node channels` subcommand and the backing `admin_v1_channels` RPC that print a live snapshot of every open payment channel: per channel the last-accepted nonce, outstanding accrued claim (micro-USDC), escrowed deposit, time since the last voucher, and settlement eligibility. - common: `ChannelSnapshot` / `ChannelsResponse` wire DTOs + `channels()` RPC method on the `AdminRpc` trait, `CHANNEL_STORE_ERROR_CODE`, and serde round-trip / legacy-default tests. - node admin: `ChannelStatusHandles` (channel store + voucher-activity clock + redeem threshold) attached via `with_dht`-style `with_channels`; the handler loads the store off the blocking pool, builds snapshots, and computes `settlement_eligible` as `outstanding >= redeem_threshold` (upper bound — the admin surface has no on-chain `withdrawnAmount`). - incentive: new in-memory `VoucherActivity` clock (non-durable, resets on restart) shared between the `cdn/client/v1` handler (stamps on each accepted voucher) and the admin snapshot (reports seconds-since). - cli: `Channels(ChannelsArgs)` subcommand + handler with a grep-friendly plain-text table and `--json`, mirroring `node status` / `node peers`. Settlement eligibility uses `>=` to match the redeemer's `< threshold` short-circuit. Time-since-voucher is `None` after a restart until the next voucher, since `ChannelState` persists no last-voucher wall-clock. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request adds the decdn node channels CLI command and the admin_v1_channels RPC endpoint to allow operators to inspect open payment channels and track voucher activity. The review feedback suggests reusing the existing format_age helper to avoid code duplication and simplifying the channel snapshot sorting logic using sort_unstable_by_key.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds operator-facing payment-channel introspection by extending the admin JSON-RPC surface with admin_v1_channels and exposing it via a new decdn node channels CLI subcommand, including an in-memory “time since last voucher” signal.
Changes:
- Introduces
ChannelSnapshot/ChannelsResponseDTOs and anAdminRpc::channels()method (plus error code) on the common admin wire surface. - Wires a shared in-memory
VoucherActivityclock into the client voucher-acceptance path (writer) and admin channels snapshot (reader). - Implements the node-side
admin_v1_channelshandler and the CLI renderer (--jsonor grep-friendly table), with unit + integration tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/runtime/mod.rs | Wires VoucherActivity and attaches channel-status handles into the admin state builder. |
| crates/node/src/handlers/client.rs | Stamps VoucherActivity on successful voucher acceptance (best-effort). |
| crates/node/src/admin.rs | Adds channel introspection handles, implements admin_v1_channels, and unit-tests snapshot building + RPC behavior. |
| crates/incentive/src/voucher_activity.rs | New in-memory per-channel last-voucher clock with unit tests. |
| crates/incentive/src/lib.rs | Exposes voucher_activity module and re-exports VoucherActivity. |
| crates/common/src/cli/node.rs | Adds Channels subcommand + args to the shared CLI definition. |
| crates/common/src/cli/mod.rs | Re-exports ChannelsArgs from the CLI module. |
| crates/common/src/admin.rs | Defines wire DTOs, adds admin RPC method + error code, and serde/back-compat tests. |
| crates/cli/tests/admin_peers.rs | Adds HTTP integration tests for admin_v1_channels plus CLI error-path test. |
| crates/cli/src/commands/node.rs | Implements decdn node channels command, table formatting, and unit tests for formatting helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 86.68% (was 86.60%, ▲ +0.08%) — 27076/31236 lines
History
|
…ck wiring (#791 review) Multi-agent review of #791 found the new VoucherActivity clock CLEAN on correctness but surfaced one type-design leak and one test gap. LOAD-BEARING: VoucherActivity.touch inserted per ChannelId with no eviction. On-chain channel close removes the channel from the live map but left its Instant lingering for the process lifetime -- a slow leak on a long-running, high-churn node. Add panic-free, idempotent VoucherActivity::forget (poisoned lock = no-op, same safe degradation as touch/seconds_since) and call it from ClientHandler::forget_channel, the single site that drops a closed channel from the live map (both ChannelSettled callers funnel through it). TEST GAP: the two one-liners wiring the clock (attach_voucher_activity + the touch in the accept path) had zero test callers, so a dropped/mis-placed stamp or the writer and reader holding different Arcs would silently report seconds_since_last_voucher: None forever. Add: - client_loopback: a real signed-voucher accept through the live handler advances the shared Arc<VoucherActivity> (crit 7); - admin: a touch on the SAME Arc the channels() reader holds surfaces as Some(age) and sorts the active channel first (crit 6). Plus VoucherActivity::forget unit tests (removes a stamped channel; unknown channel no-op). MicroUsdc newtype (optional #3): declined-for-scope -- the *_micro_usdc unit suffix already disambiguates the three amount fields from last_nonce, and a newtype on the DTO fields alone would force .0/MicroUsdc(..) conversions across ~99 references in 8 files (config types, resolved config, runtime, reload, CLI) where micro-USDC flows as u64. Not low-churn. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…mplify sort, accurate JoinError log - crates/cli: drop `format_age_secs`; the channels path now scales the whole-second wire value and reuses `format_age` (microsecond input) via `saturating_mul(1_000_000)`. Boundary buckets are identical and covered by `format_age_units`; the now-redundant `format_age_secs_units` test is removed. - crates/node: `build_channel_snapshots` uses `sort_unstable_by_key` with the same total-order key tuple (no closure, no allocation), preserving ordering. - crates/node: the channel-store `JoinError` log distinguishes cancellation from panic (`is_cancelled`) so a shutdown-time cancel isn't logged as a panic. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alpergundogdu
left a comment
There was a problem hiding this comment.
Review — decdn node channels snapshot
Solid, mergeable. No correctness, anti-panic, concurrency, or wire-compat blockers found. The wire DTO is cleanly separated from internal ChannelState (owned String/u64/bool), the sync store read is correctly offloaded with spawn_blocking, poison handling uses lock().ok()?/into_inner, and the with_channels builder keeps the ~15 AdminState::new call sites untouched.
Verified-correct design points worth confirming explicitly (they look surprising but are intentional and documented):
settlement_eligiblecompares the full accruedlast_amountagainst the threshold (outstanding >= threshold), not the redeemer's un-redeemed delta (last_amount - withdrawnAmount < threshold). The admin surface deliberately never reads on-chainwithdrawnAmount, so this is an upper-bound liveness signal — documented on the DTO field. Good.forget_channeldrops the asyncchannelslock beforeactivity.forget()/spawn_blocking— no lock held across.await.- The
(is_none(), age, Reverse(outstanding))sort key correctly orders active channels first, then by recency, then by claim size.
Test coverage is unusually strong — the shared-Arc wiring guard and the real signed-voucher loopback test (proving the accept path actually calls touch through the same Arc the channels() reader holds) close the most likely silent-failure gap. The VoucherActivity::forget eviction fixing the per-ChannelId Instant leak on channel close is a genuine improvement.
Minor (non-blocking):
crates/cli/src/commands/node.rsformat_usdc/ column width: the{:>12}OUTSTANDING/DEPOSITcolumns overflow forformat_usdc(u64::MAX)(21 chars). This only occurs on the saturating arm for a value exceeding the on-chain deposit (documented as unreachable for a real channel), so it's purely cosmetic — widen the columns or leave as-is.- Optional test gaps: no assertion on the CLI
--jsonoutput path, and the table-render test uses a lowercase counterparty rather than an EIP-55 mixed-case one (note thecounterpartydoc was correctly fixed to say checksummed). Both low-risk.
LGTM.
Generated by Claude Code
…ndering (#791, Alper review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed in 98a2786:
Not changed, by decision: the Verified green: |
# Conflicts: # crates/node/src/handlers/client.rs # crates/node/tests/client_loopback.rs
Closes #749
Adds a
decdn node channelssubcommand and the backingadmin_v1_channelsRPC that print a live snapshot of every open payment channel. Per channel: last-accepted nonce, outstanding accrued claim (micro-USDC), escrowed deposit, time since the last voucher, and settlement eligibility. Mirrors the existingdecdn node status/decdn node peersadmin-RPC surface.What changed
crates/common/src/admin.rs—ChannelSnapshot/ChannelsResponsewire DTOs (ownedString/u64/bool, no internal handles), achannels()method on theAdminRpctrait,CHANNEL_STORE_ERROR_CODE, plus serde round-trip + legacy-default tests.crates/node/src/admin.rs—ChannelStatusHandles(channel-state store + voucher-activity clock + redeem threshold) attached via awith_dht-stylewith_channelsbuilder so the ~15AdminState::newcall sites are untouched. The handler loads the store off the blocking pool (the store trait is sync), builds snapshots via the pure, unit-testedbuild_channel_snapshots, and computessettlement_eligibleasoutstanding >= redeem_threshold.crates/incentive/src/voucher_activity.rs(new) — in-memoryVoucherActivityclock, non-durable by design, shared between thecdn/client/v1handler (stamps on each accepted voucher) and the admin snapshot (reports seconds-since).crates/node/src/handlers/client.rs+runtime/mod.rs— wire the activity clock (writer) and the channel handles (reader) into the existing store/handler graph.crates/common/src/cli/node.rs+crates/cli/src/commands/node.rs—Channels(ChannelsArgs)subcommand + handler with a grep-friendly plain-text table and--json, reusing the admin-client/URL-resolution helpers.Design notes
withdrawnAmount, so it compares the full accrued claim against the threshold (documented on the DTO field).>=matches the redeemer's< thresholdshort-circuit inpayment_settlement.rs.ChannelStatepersists no last-voucher wall-clock, so a channel hydrated at boot reportsNoneuntil its next voucher (rendered "never"). This is the correct shape for a current-liveness diagnostic.CHANNEL_STORE_ERROR_CODEwith anerror!log.Review
Self-review applied the code-reviewer, silent-failure-hunter, pr-test-analyzer, type-design-analyzer, and comment-analyzer lenses to the diff.
counterpartyDTO doc claimed "lowercase hex", butalloy::AddressDisplayis EIP-55 mixed-case checksummed (verified in the crate source). Corrected the doc and contrasted it withPeerView::node_id(plain lowercase iroh key).settlement_eligibleis recomputable client-side from threshold + outstanding, but pre-computing server-side directly answers the issue's ask and is documented as an upper bound.Post-review follow-up (commit
f417cc2)A second multi-agent review found the diff CLEAN on correctness but surfaced one load-bearing type-design issue and one real test gap; both are now fixed:
VoucherActivity.touchinserted perChannelIdwith no eviction, so a channel that closed on-chain (removed from the live map) left itsInstantlingering for the whole process lifetime — a slow leak on a long-running, high-churn node. Added a panic-free, idempotentVoucherActivity::forget(poisoned lock = no-op, same safe degradation astouch/seconds_since) and call it fromClientHandler::forget_channel, the single site that drops a closed channel from the live map (bothChannelSettledcallers funnel through it). Unit tests cover removal + the unknown-channel no-op.attach_voucher_activity+ thetouchin the accept path) had zero test callers, so a dropped/mis-placed stamp — or the writer and thechannels()reader holding differentArcs — would silently reportseconds_since_last_voucher: None("never") forever. Added: aclient_loopbacktest where a real signed-voucher accept through the live handler advances the sharedArc<VoucherActivity>(crit 7); and anadmintest where atouchon the sameArcthechannels()reader holds surfaces asSome(age)and sorts the active channel first (crit 6). This supersedes the earlier "no dedicated accept→clock test" note.MicroUsdcnewtype (optional, declined-for-scope). Wrapping the three DTO amount fields in a#[serde(transparent)] MicroUsdc(u64)would keep the wire bytes identical, but it is not low-churn: the*_micro_usdcunit suffix already disambiguates the amounts fromlast_nonce, and the newtype would force.0/MicroUsdc(..)conversions across ~99 references in 8 files (config types, resolved config, runtime, reload, CLI) where micro-USDC flows asu64. Declined.Verification
cargo build,cargo clippy --workspace --all-targets— clean (no warnings).cargo nextest run -p decdn-cli -p decdn-common -p decdn-node -p decdn-incentive— 1007 passed, 0 failed (4 new tests).cargo fmt -- --check— clean. Pre-commit hooks (fmt, clippy, doc, deny) all passed.🤖 Generated with Claude Code