Repository navigation
refactor(node,cli)!: split decdn binary into decdn-node daemon + decdn cli (#421) - #425
Conversation
Step 1 of the binary split (#421). Moves the modules both binaries need to share — config schema, identity loading, clap argument structs — out of `crates/node/` and into a new `crates/common/` crate. The node crate re-exports `decdn_common::{cli, config, identity}` at their old paths so existing tests and the still-present `commands/` keep compiling unchanged. These re-exports are removed in the commit that completes the slim of the node crate. Visibility uplifts: `DEFAULT_ADMIN_PORT` and the helper functions `load_file_config`, `parse_pinned_hashes`, `resolve_payment`, `resolve_observability`, `resolve_security`, `resolve_origin_retry`, and `fresh_secret_key` move from `pub(crate)` to `pub` since their callers now live in a sibling crate. No behaviour changes. All 463 workspace tests pass; clippy clean under the workspace anti-panic policy. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Step 2 of the binary split (#421). Moves the admin JSON-RPC wire contract — the `AdminRpc` trait, all request/response DTOs, error code constants, and `parse_hash_arg` — out of `crates/node/src/admin.rs` and into `crates/common/src/admin.rs`. The user CLI's `decdn node …` subcommands (added in the next commit) consume the generated `AdminRpcClient` from common without dragging the daemon's runtime into the CLI binary. Server-side state (`AdminState`, `AdminRpcImpl`, `DrainTrigger`, `ReloadHook`, `RawPeer`, the `AdminRpcServer` impl, `bind` / `serve`) stays in `crates/node/src/admin.rs`. It also re-exports the wire types so existing `decdn_node::admin::{AdminRpcClient, PeerView, …}` paths keep resolving for tests and the still-present client code in `crates/node/src/commands/node.rs`. Both the re-export and that file are removed in the commit that finishes slimming the node crate. The error-code constants graduate from `pub(crate)` to `pub` so they're visible across the new crate boundary; `INVALID_PARAMS_CODE` is now public so the CLI can reference it when classifying errors. No wire-format changes — every DTO field, error code, and method name matches what `admin_v1` already speaks. All 463 workspace tests pass; clippy clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…n cli Step 3 of #421: complete the dockerd-style split. Adds the user-facing `decdn` binary in a new `crates/cli/` crate, slims `crates/node/` to daemon-only, and renames its binary to `decdn-node`. Combines the "create cli crate" and "rename + slim node" steps from the plan into one commit so the workspace never has two `[[bin]] name = "decdn"` entries. `crates/cli/`: - new package `decdn-cli` with `[[bin]] name = "decdn"` - `src/commands/{key_gen,probe,config,node}.rs` carry the command implementations moved from `crates/node/src/commands/`. The sizable `node.rs` (admin client dispatch, 896 lines) and the integration tests `tests/{admin_peers,config_validate}.rs` are `git mv`-renamed from node to keep history attached. - `src/main.rs` parses the user-facing `Command` enum (no `Run`) and dispatches into `commands::*`. `decdn run` errors with a redirect to `decdn-node run`. - dev-deps on `decdn-node` / `decdn-cache` / `decdn-gossip` so the relocated `admin_peers.rs` integration test can spin up a real `AdminState` end-to-end against the loopback admin RPC. `crates/node/`: - `[[bin]] name = "decdn"` -> `name = "decdn-node"` - `src/main.rs` becomes a tiny clap shell: `--config` plus a single `run` subcommand that calls `commands::run`. - `commands/mod.rs` keeps only `run` and the tracing/OTLP bring-up helpers; everything user-facing has moved to `decdn-cli`. - `lib.rs` drops the temporary `decdn_common::{cli,config,identity}` re-exports and the `admin` wire-type re-exports added in earlier steps. Tests import wire types from `decdn_common::admin` and config/cli/identity from `decdn_common` directly. `Dockerfile`: - copy new `crates/{common,cli}/Cargo.toml` for the dep-priming layer - rename builder copy + ENTRYPOINT from `decdn` to `decdn-node` - container ships the daemon only; CLI users grab the `decdn-${VERSION}-${TARGET}.tar.gz` release archive `.github/workflows/release.yml`: - matrix doubles in size: each target now produces both a `decdn-node-${VERSION}-${TARGET}.tar.gz` (operator) and a `decdn-${VERSION}-${TARGET}.tar.gz` (publisher) archive - `--package` is matrix-driven so cross-builds and native builds share one set of build steps BREAKING CHANGE: `decdn run` no longer exists. Run the daemon with `decdn-node run`. The user CLI is `decdn` and gains `node {peers,health,announce,drain,evict,reload}`, `key-gen`, `config {init,validate}`, `probe` — all moved from the old fused binary, no behaviour changes. Container image entrypoint is now `decdn-node`. All 463 workspace tests pass; clippy clean under the workspace anti-panic policy. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Step 5 of #421. Documents the dockerd-style split landed in the preceding commits. - New `adr/appendix-binaries.md` covering the rationale for the `decdn-node` daemon + `decdn` user-CLI shape, why the `node` admin namespace lives on `decdn` (not `decdn-node`), why a single shared `decdn-common` (atomic-PR cost dominates), why the Prometheus metric prefix and OTLP `service.name` stay `decdn` (dashboard continuity), container-image policy, and the CLI binary-size budget. - `adr/architecture.md` gains a "Binaries" subsection (table of binary → role → crate → listens-on) and updates the crate-structure block to include `cli/` and `common/`. - `adr/appendix-local-admin-http.md` updates the implementation pointer to reflect that the trait + DTOs now live in `crates/common/src/admin.rs` and the client-side `decdn node peers` in `crates/cli/src/commands/node.rs`. - `adr/019-node-onboarding.md` and `adr/024-account-abstraction.md` flip dangling references to `decdn-node` as a CLI command (now ambiguous with the daemon binary name) over to `decdn` — `decdn node register`, `decdn setup`. - `README.md` adds a Binaries table and refreshes the Crate Structure block. - `CLAUDE.md` updates the Status line and Crate Structure to match the eight-crate workspace and adds the dependency-flow note for the two binaries. - `CHANGELOG.md` adds an Unreleased "Changed (BREAKING)" entry naming the binary rename, and updates the existing CLI section so `decdn run` reads as `decdn-node run`. No code changes; pre-commit hooks (markdownlint, cargo deny) pass on the touched docs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Final cleanup for #421. Two small follow-ons noticed during smoke tests of the release binary: - The user CLI's `Command` enum still carried a `Run(Box<RunArgs>)` variant from before the split, with `decdn run` returning a redirect error. That was effectively a soft shim: `decdn run` printed a helpful "use decdn-node run" message instead of clap's default "unrecognized subcommand". The plan calls for a hard cut, so drop the variant entirely. `decdn run` now errors with clap's default `error: unrecognized subcommand 'run'` and `decdn --help` no longer lists a phantom `run` command. - `decdn --help`'s `about` line was auto-pulled from `decdn-common`'s package description ("Shared types for deCDN binaries…"). Set an explicit `about` / `long_about` on `decdn_common::cli::Cli` so the help text describes the user CLI rather than the package that hosts the clap struct. `RunArgs` itself stays in `decdn-common` — `decdn config validate` still flattens it for env-var parity with the daemon, and the daemon crate's `DaemonCli` parses it under its own `run` subcommand. The `run_subcommand_args_are_wired_to_decdn_env_vars` test pivots from walking `Cli::command().find_subcommand("run")` to walking `<RunArgs as Args>::augment_args(...)` so it still enforces the same env-var contract without needing a `run` subcommand on the user CLI. All 463 workspace tests pass; clippy clean; release binaries build to 22 MB (decdn) and 29 MB (decdn-node), well under the 50 MB soft budget noted in `adr/appendix-binaries.md`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request refactors the project by splitting the monolithic decdn binary into a daemon (decdn-node) and a user-facing CLI (decdn), with shared types moved to a new decdn-common crate. The changes include updates to the workspace structure, Dockerfile, and documentation to support this split. Feedback was provided to improve the robustness of JSON output in the probe command by using serde_json instead of manual string formatting.
There was a problem hiding this comment.
Pull request overview
This PR implements the dockerd-style binary split for the node: a daemon-only decdn-node binary and a separate user-facing decdn CLI, with a new decdn-common crate to share config/identity/admin wire types between them. This reshapes packaging (Docker + release artifacts) and moves the CLI surface out of the daemon crate while preserving the existing operational/admin behaviors via loopback JSON-RPC.
Changes:
- Introduce
crates/common(decdn-common) to host shared config schema/resolution, identity loading, clap arg structs, and admin JSON-RPC wire types (trait + DTOs). - Split binaries:
crates/nodenow buildsdecdn-node(daemon with onlyrun), and newcrates/clibuildsdecdn(probe, node admin, key-gen, config). - Update distribution/docs: Dockerfile now ships daemon-only, release workflow produces two archives per target, and ADR/README/CHANGELOG/CLAUDE reflect the new split.
Reviewed changes
Copilot reviewed 38 out of 46 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new decdn-node/decdn binary split and updates crate structure. |
| Dockerfile | Updates build priming for new crates and switches runtime image to ship decdn-node. |
| crates/node/tests/sighup_signal.rs | Switches test imports from decdn_node to shared decdn_common CLI/config types. |
| crates/node/tests/probe_loopback.rs | Updates ResolvedSecurity import to decdn_common. |
| crates/node/src/runtime/reload.rs | Migrates reload/config types to decdn_common and adjusts type references accordingly. |
| crates/node/src/runtime/mod.rs | Switches identity/config imports to decdn_common after extraction. |
| crates/node/src/main.rs | Replaces the fused CLI entrypoint with a daemon-only clap shell for decdn-node run. |
| crates/node/src/lib.rs | Updates crate docs and removes re-exported CLI/config/identity modules now in decdn_common. |
| crates/node/src/dispatch.rs | Uses decdn_common::config::ResolvedSecurity for limiter construction/tests. |
| crates/node/src/commands/mod.rs | Shrinks to daemon startup/run concerns; imports shared CLI/config from decdn_common. |
| crates/node/src/admin.rs | Moves admin wire types/trait/DTOs to decdn_common::admin; keeps server implementation in node crate. |
| crates/node/Cargo.toml | Renames bin to decdn-node and adds dependency on decdn-common. |
| crates/common/src/lib.rs | New shared library crate root exposing admin, cli, config, identity. |
| crates/common/src/identity.rs | Makes fresh_secret_key public for reuse by the CLI probe client. |
| crates/common/src/config/types.rs | Minor doc adjustment in security section comment. |
| crates/common/src/config/resolved.rs | New module defining resolved config DTOs used by daemon and CLI summary output. |
| crates/common/src/config/mod.rs | Exposes config helpers/constants publicly for cross-crate use; adjusts tests for removed run subcommand from user CLI. |
| crates/common/src/cli/run.rs | New shared clap arg structs for daemon run flags/env wiring. |
| crates/common/src/cli/probe.rs | New shared clap args for decdn probe. |
| crates/common/src/cli/node.rs | New shared clap args for decdn node … admin command group. |
| crates/common/src/cli/mod.rs | Defines the user CLI command tree (intentionally without run). |
| crates/common/src/cli/key_gen.rs | New shared clap args for decdn key-gen. |
| crates/common/src/cli/config_cmd.rs | New shared clap args for decdn config {init,validate}. |
| crates/common/src/cli/common.rs | New shared CLI helpers (default paths, ~ expansion, test-only home override seam). |
| crates/common/src/admin.rs | New shared admin JSON-RPC wire layer (rpc trait, DTOs, error codes, hash parsing helper). |
| crates/common/Cargo.toml | Adds decdn-common crate manifest and dependencies. |
| crates/cli/tests/config_validate.rs | Updates tests to use decdn_cli command impl + decdn_common types. |
| crates/cli/tests/admin_peers.rs | Updates admin tests to use shared AdminRpcClient and CLI command implementation modules. |
| crates/cli/src/main.rs | New decdn binary entrypoint dispatching to decdn_cli::commands using decdn_common::cli parsing. |
| crates/cli/src/lib.rs | New CLI library crate exposing commands for integration tests/downstream use. |
| crates/cli/src/commands/probe.rs | Implements decdn probe client logic (moved from old fused binary). |
| crates/cli/src/commands/node.rs | Implements decdn node … loopback admin RPC client commands using shared wire types. |
| crates/cli/src/commands/mod.rs | CLI command module wiring for config/key-gen/node/probe. |
| crates/cli/src/commands/key_gen.rs | Implements decdn key-gen using shared identity helpers. |
| crates/cli/src/commands/config.rs | Implements decdn config init/validate using shared config resolver and summary writer. |
| crates/cli/Cargo.toml | Adds new decdn-cli package producing decdn and configures dev-deps for end-to-end admin tests. |
| CLAUDE.md | Updates workspace overview/status and dependency flow for the split. |
| CHANGELOG.md | Adds breaking-change entry and updates CLI command listing (decdn-node run). |
| Cargo.toml | Adds crates/common and crates/cli to workspace and registers decdn-common/decdn-node workspace deps. |
| Cargo.lock | Records new workspace packages decdn-common and decdn-cli and dependency graph updates. |
| adr/architecture.md | Documents binaries table and updates crate-structure diagram to include new crates. |
| adr/appendix-local-admin-http.md | Updates implementation pointers for shared admin trait/DTOs and new client location. |
| adr/appendix-binaries.md | New appendix documenting rationale/implications of the binary split. |
| adr/024-account-abstraction.md | Updates references from decdn-node … tooling to decdn … where applicable. |
| adr/019-node-onboarding.md | Updates references to onboarding tooling command naming to match new CLI binary. |
| .github/workflows/release.yml | Expands release matrix to build/package both decdn-node and decdn artifacts per target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ker CMD
Two PR review touch-ups:
- `crates/cli/src/commands/probe.rs`: switch the `--json` output path
from a manual format string to `serde_json::json!(...)`. Quantize
`rtt_ms` to 3 decimals before serialization so the wire format
matches the prior `{:.3}` output exactly — `as_secs_f64()` carries
microsecond noise past 3 decimals anyway, so the quantization isn't
lossy in any meaningful sense. Other fields are emitted as native
JSON types (numbers, not strings) the same way the manual version
did. (gemini-code-assist suggestion.)
- `Dockerfile`: add `CMD ["run"]` so `docker run <image>` starts the
daemon by default rather than exiting with clap usage; operators
can still override (`docker run <image> --version`,
`docker run <image> run --config /etc/decdn/node.toml`, etc.).
(Copilot suggestion — straightforward UX fix that aligns with the
"container = daemon-only" intent in `adr/appendix-binaries.md`.)
Not implemented:
- gemini's sub-suggestion to "use existing hex utility functions".
The cli crate doesn't depend on `alloy` (the workspace's hex
helper); pulling it in for a 6-line fallback path that only fires
when iroh's `PublicKey::from_bytes` rejects 32 bytes (effectively
unreachable) would inflate the release binary for no maintainability
gain. Manual hex stays.
All 463 workspace tests pass; clippy clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Fixes from the PR #425 multi-agent review: - **Stale `decdn run` references** in moved doc comments. Three files in `crates/common/src/cli/{run,config_cmd,node}.rs` still described `RunArgs` as belonging to the pre-split `decdn run` invocation. Flipped to `decdn-node run`. (comment-analyzer) - **`adr/appendix-binaries.md` redirect claim was wrong.** Said `decdn run` "errors with a redirect to `decdn-node run`"; commit 2084cec dropped the `Run` variant entirely so clap emits the generic `unrecognized subcommand 'run'`. Tightened the appendix to describe what actually happens. Also softened the "no cache engine" claim to acknowledge that `decdn-cache` is a build-time dep of `decdn-common` for typed config fields. (comment-analyzer) - **Unused dependencies** declared but never imported. Dropped `tracing` and `tracing-subscriber` from `crates/cli/Cargo.toml`, and `serde_json` and `ed25519-dalek` from `crates/common/Cargo.toml` — none had any `use` site in source. (code-reviewer) - **`crates/common/src/admin.rs` module docstring** overstated encapsulation by claiming "no cache-internal types". Tightened to acknowledge that `parse_hash_arg` returns `decdn_cache::Hash` and that `decdn-cache` is in the dep tree for typed config fields regardless. (type-design-analyzer) - **`adr/architecture.md` mermaid dependency graph** still showed only the pre-split crates. Added `cli` and `common` nodes, plus `gossip` (which was already a member but missing from the graph), with the edges that reflect the post-split shape. (comment-analyzer) - **`probe.rs` `rtt_ms` JSON wire-format drift** — old code was `{:.3}` always (3 decimals, e.g. `12.500`); new code drops trailing zeros via serde_json (e.g. `12.5`). The earlier touch-up comment claimed the wire contract was preserved; it isn't. Tightened the comment to describe the actual change and added a CHANGELOG line under the BREAKING note. (silent-failure-hunter) - **`probe.rs` JSON output had no test coverage.** Refactored `print_probe_response` to `write_probe_response(&mut impl Write, ...)` returning `io::Result` (mirrors the `write_validate_summary` pattern in `crates/cli/src/commands/config.rs`) and added four unit tests pinning: the JSON key set + types, the `rtt_ms` ms-precision quantization, the single-line guarantee, and the pretty-output line order. (pr-test-analyzer) - **`Command` enum rustdoc** clarified — points readers at `decdn-node run` for starting the daemon and at `decdn config validate` for dry-run resolution. Also refreshed the `decdn_common::cli` module doc with a forward reference to `RunArgs`'s `ConfigValidateArgs` re-use. (type-design-analyzer) Deferred (filed mentally, not as issues): - Daemon clap shell integration test and `decdn run` rejection clap test — both rated 4/10 by pr-test-analyzer; clap structurally enforces the contracts these would assert. - Demoting `pub` resolve helpers in `crates/common/src/config/mod.rs` back to `pub(crate)` — they have callers in `decdn-node`'s `runtime/reload.rs`, a sibling crate, so `pub(crate)` doesn't work without a sub-module reshuffle that's purely cosmetic. All 467 workspace tests pass (was 463; 4 new probe tests); clippy clean; fmt clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The appendix is meant to be durable architecture rationale, not a transition narrative. Rewrites the Context, Decision, and rejected- alternatives sections in present tense — describes what the binaries *are* and why this shape was chosen, without "pre-#421"/"post-split" hedges that date the document and add nothing for a reader landing on the appendix in 2027 trying to understand the layout. Behaviour-relevant content unchanged: the four "Why …" subsections (node-admin namespace placement, single shared crate, metric prefix continuity) keep their full text. Distribution and follow-ups blocks are unchanged except for one "post-split" -> drop. The transition story still lives in CHANGELOG (under "Changed (BREAKING)") for operators upgrading; the appendix doesn't repeat it. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a major architectural change by splitting the existing fused binary into two separate binaries: decdn-node (the daemon) and decdn (the user-facing CLI). This split reduces the dependency footprint for operators and publishers, improves containerization, and aligns with standard patterns like dockerd + docker. A new decdn-common crate was introduced to share configuration schemas, identity loading, and admin RPC types between the two binaries. The codebase, documentation, and build configuration (including Dockerfile and Cargo workspace) have been updated to reflect this new structure, and a new ADR appendix has been added to document the rationale.
The "Performs no I/O beyond reading the config file" claim is wrong —
`decdn_common::config::resolve_config` also stats and opens
`blockchain.eth_keystore` (`crates/common/src/config/mod.rs:325-336`)
to fail readability problems at validation time rather than at daemon
startup. Bug predates the binary split; the comment moved with the
file from the old `crates/node/src/commands/mod.rs`.
Updates the doc to keep the load-bearing guarantees ("does not bind
ports, does not connect to the JSON-RPC endpoint, does not open the
cache") while accurately describing the eth_keystore stat/open the
resolver does perform. (Copilot review on PR #425.)
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adopt the dockerd-style binary split per #421:
decdn-node(daemon-only) — single subcommand:decdn-node run [--config <path>]. Lean, easy to containerise, minimal supply-chain surface.decdn(user CLI) —probe,node {peers,health,announce,drain,evict,reload},key-gen,config {init,validate}. Thenodeadmin namespace talks to a running daemon over loopback HTTP per ADR 025; on a host with no daemon it errors cleanly.decdn-common(new lib) — shared types both binaries need: TOML config schema + resolver, identity loading,AdminRpctrait + DTOs, clap argument structs.The container image ships
decdn-nodeonly. Release archives ship two tarballs per target:decdn-node-${VERSION}-${TARGET}.tar.gz(operators) anddecdn-${VERSION}-${TARGET}.tar.gz(publishers).Five commits, each green at the boundary:
refactor(common): extract config, identity, cli args into decdn-commonrefactor(common): extract AdminRpc trait and DTOs into decdn-commonrefactor(cli,node)!: split decdn binary into decdn-node daemon + decdn cli(the structural change)docs(adr,readme,changelog): document decdn-node + decdn binary splitrefactor(cli): drop Run from user-CLI Command enum, polish help textHard cut, per the issue's stated non-goal: there is no
decdn runshim.decdn runerrors with clap's defaultunrecognized subcommand 'run'.ADRs / docs
adr/appendix-binaries.mdcovering the rationale (dockerd-shape, whynodeadmin lives ondecdn, why a singledecdn-common, why the Prometheus metric prefix and OTLPservice.namestaydecdn, container-image policy, CLI binary-size budget).adr/architecture.mdgains a Binaries subsection + table; crate-structure block updated.adr/appendix-local-admin-http.mdupdates the implementation pointer (trait + DTOs incrates/common/src/admin.rs, server incrates/node/src/admin.rs, client incrates/cli/src/commands/node.rs).adr/019-node-onboarding.mdandadr/024-account-abstraction.mdflip dangling references that nameddecdn-nodeas a CLI command (now ambiguous with the daemon binary) over todecdn.README.mdadds the Binaries table and refreshes the Crate Structure block.CLAUDE.mdupdates Status + Crate Structure + dependency-flow note.CHANGELOG.mdadds an Unreleased "Changed (BREAKING)" entry.Operational changes
crates/{common,cli}/Cargo.tomlfor the dep-priming layer; rename builder copy + ENTRYPOINT fromdecdntodecdn-node..github/workflows/release.yml: matrix doubles in size — each target now produces bothdecdn-node-${VERSION}-${TARGET}.tar.gzanddecdn-${VERSION}-${TARGET}.tar.gz.--packageis matrix-driven so cross-builds and native builds share one set of build steps.ci.yml/security.yml/pr-title.yml/dependabot.ymlare workspace-scoped or path-globbed and pick up the new crates without changes (audited).release.tomlunchanged —shared-version = truealready locks all workspace members to one version.Verification
Run from
decdn/:cargo build --workspace --all-targetscargo clippy --workspace --all-targets -- -D warnings(anti-panic policy)cargo nextest run --workspace— 463/463 passcargo deny checkcargo fmt --checkdecdn --versionanddecdn-node --versionboth report0.1.0decdn config init,decdn key-genend-to-end smokedecdn node healthagainst a non-existent admin port errors cleanly with a useful message (no panic, no stack trace)decdn22 MB,decdn-node29 MB (under the 50 MB soft budget noted inadr/appendix-binaries.md)Test plan
cargo install --path crates/cliproduces a workingdecdnon$PATHcargo install --path crates/nodeproduces a workingdecdn-nodeon$PATHdocker build .succeeds;docker run --rm <image> --versionprints the daemon versiondecdn-node run --config /tmp/decdn.toml, thendecdn node healthreturns OK;decdn node drainshuts the daemon down cleanlyBREAKING CHANGE:
decdn runno longer exists. Run the daemon withdecdn-node run. The user CLI isdecdnand gainsnode {peers,health,announce,drain,evict,reload},key-gen,config {init,validate},probe— all moved from the old fused binary, no behaviour changes. Container image entrypoint is nowdecdn-node. Release archives now ship two tarballs per target.Closes #421.
🤖 Generated with Claude Code