Skip to content

feat(cli): decdn setup — guided node onboarding wizard (#933) - #953

Merged
thiras merged 3 commits into
mainfrom
feat/decdn-setup-wizard
Jun 19, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/decdn-setup-wizard

Conversation

@thiras

@thiras thiras commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements decdn setup (closes #933), the operator-onboarding wizard from ADR 019 §Deferred. It is thin orchestration over the existing primitives (key-gen, node bond #932, node register #929) with the Phase 1 pre-flight checks ADR 019 §Context calls for and a Phase 5 readiness summary — no new on-chain logic (every contract call reuses bond::execute / register::submit_registration or a read-only CapacityBond view).

decdn setup --mbps <N> --region <CC> [--multiaddr …] [--yes] [--dry-run]

Flow: pre-flight → confirm → bond → register → readiness, decrypting the keystore once for the on-chain phase (the signer is built up front and shared across bond + register).

Pre-flight checks (read-only; abort before any tx)

  • RPC reachability + chain-id match — a mismatch silently dooms every signature (signed for resolved.chain_id).
  • Clock skew vs the RPC's RFC-7231 Date header, ≤10s per ADR 019 Phase 1 step 2 — no new NTP dependency. An undetermined reference renders WARN (non-blocking), not a false ok.
  • TOKEN balance ≥ bond shortfall.
  • Native-gas balance ≥ estimated Phase 2 gas.

Safety properties

  • Register-divergence guard: setup bails if the operator is already bound on-chain to a different node key, rather than silently skipping registration and reporting success for an unregistered local key.
  • Idempotent: bond is stake-to-tier (skips when already at target); register skips when this key is already bound. A second run converges.
  • --dry-run previews without submitting (and still validates the tier band); --yes skips the interactive confirm for CI.

Refactors to enable reuse (no behavior change)

  • bond.rs: Plan/Outcome/build_plan/execute/write_plan widened to pub(crate).
  • register.rs: extracted submit_registration + write_outcome (owned RegisterOutcome replacing the borrowed Params) so setup shares one signer/provider load. Original register output contract preserved; added a submitted-tx test.

Review

A multi-agent review (code / silent-failure / type-design / comments / tests) ran on this branch; all material findings were fixed — notably the register-key divergence guard, the --json --dry-run single-object output, the keys-absent dry-run band check, a Preflight struct that removes a 16-arg/5-bool emitter, and the ADR-citation/clock-threshold doc corrections.

Test plan

  • cargo build, cargo clippy --workspace --all-targets — clean
  • cargo fmt -- --check — clean
  • cargo nextest run — 1885/1885 pass (13 new setup unit tests: RFC-7231 parsing + boundaries, days_from_civil, Preflight predicates, build_summary discriminants, precheck_keys)
  • cargo deny check — clean (confirms no new dependency)
  • decdn setup --help renders
  • End-to-end against Arbitrum Sepolia with a funded keystore (manual; needs live RPC)

🤖 Generated with Claude Code

Implement `decdn setup`, the operator-onboarding wizard from ADR 019 §Deferred:
thin orchestration over the existing primitives (`key-gen`, `node bond`,
`node register`) with Phase 1 pre-flight checks and a Phase 5 readiness summary.
It introduces no new on-chain logic — every contract call reuses an existing
primitive (`bond::execute`, `register::submit_registration`) or a read-only
`CapacityBond` view.

Flow: pre-flight → confirm → bond → register → readiness, decrypting the
keystore once for the on-chain phase (the signer is built up front and shared
across bond + register).

Pre-flight checks (all read-only; abort before any tx):
- RPC reachability + chain-id match (a mismatch silently dooms signatures)
- clock skew vs the RPC's RFC-7231 Date header, ≤10s per ADR 019 (no NTP dep);
  undetermined renders WARN, not a false pass
- TOKEN balance ≥ bond shortfall
- native-gas balance ≥ estimated Phase 2 gas

Register is guarded against silent node-key divergence: setup bails if the
operator is already bound to a different node key rather than reporting success
for an unregistered local key. Bond is idempotent (stake-to-tier); a re-run
converges. `--dry-run` previews without submitting; `--yes` skips the confirm.

Refactors to enable reuse (no behavior change):
- bond.rs: Plan/Outcome/build_plan/execute/write_plan widened to pub(crate)
- register.rs: extract submit_registration + write_outcome (owned RegisterOutcome
  replacing borrowed Params) so setup shares the signer/provider

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 18, 2026 20:32

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new guided node onboarding wizard command, decdn setup, which orchestrates existing primitives (key-gen, node bond, and node register) alongside pre-flight checks (e.g., clock synchronization, token balance, and native gas checks) and provides a final readiness summary. To support this orchestration, several structs and functions in the bond and register commands were refactored and made pub(crate) for reuse. Feedback on these changes highlights two key improvements: redacting sensitive userinfo from RPC URLs in error messages to prevent credential leakage, and validating the range of the parsed year in parse_http_date to avoid potential integer overflow and panics.

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.

Comment thread crates/cli/src/commands/setup.rs Resolved
Comment thread crates/cli/src/commands/setup.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new decdn setup CLI subcommand implementing ADR 019’s guided operator onboarding flow by orchestrating existing primitives (key generation, bonding, registration) and surfacing pre-flight checks plus a final readiness summary.

Changes:

  • Introduces SetupArgs in common and wires Command::Setup through the CLI entrypoint.
  • Implements the decdn setup orchestration flow with pre-flight checks (chain-id match, clock skew, balances), optional confirmation, and readiness output (human + aggregated JSON).
  • Refactors bond and register command internals (pub(crate) plan/outcome helpers + submit_registration) for reuse by setup.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/common/src/cli/setup.rs Adds clap args for the new decdn setup subcommand.
crates/common/src/cli/mod.rs Exposes setup module and adds Command::Setup.
crates/cli/src/main.rs Dispatches Command::Setup to commands::setup::run.
crates/cli/src/commands/setup.rs Implements the guided onboarding wizard, pre-flight checks, and readiness/JSON summary.
crates/cli/src/commands/register.rs Extracts submit_registration and write_outcome to support reuse from setup.
crates/cli/src/commands/mod.rs Registers the new setup commands module.
crates/cli/src/commands/bond.rs Widens plan/outcome/build/execute/write helpers to pub(crate) for reuse by setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cli/src/commands/setup.rs Resolved
Comment thread crates/cli/src/commands/setup.rs Resolved
@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.58% (was 84.21%, ▼ 0.63%) — 38722/46328 lines

File Coverage Lines Δ
crates/cli/src/commands/bond.rs 32.06% 67/209 ● 0.00%
crates/cli/src/commands/chain_ctx.rs 67.04% 120/179 ▼ 0.38%
crates/cli/src/commands/register.rs 29.89% 52/174 ▲ +1.21%
crates/cli/src/commands/setup.rs 43.11% 291/675 new
crates/cli/src/main.rs 70.59% 24/34 ▼ 1.29%
History
Commit Total Δ vs base
dba7df5 83.59% ▼ 0.63%
c668887 83.58% ▼ 0.64%
1ed5a3a (HEAD) 83.58% ▼ 0.63%

thiras and others added 2 commits June 19, 2026 00:08
…larify prompts

- Redact `user:pass@` userinfo from the rpc_url shown in the malformed-URL
  error, via the existing shared `decdn_common::redact::redact_userinfo`
  (setup.rs `dry_run_without_keys` + the identical pre-existing site in
  `chain_ctx::build_provider`).
- Bound the parsed year to `1970..=9999` in `parse_http_date` so a malformed/
  adversarial `Date` header can't overflow `days_from_civil(...) * 86_400`
  (i64). IMF-fixdate years are 4-digit, so this rejects nothing valid; added a
  regression test.
- Correct the `parse_http_date` doc to match its deliberately-lenient behavior
  (weekday ignored, zone trusted as GMT) instead of claiming strict validation.
- Reword the bond confirmation so the `shortfall == 0` case no longer implies
  register-only — `declareMbps` may still submit.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… bound

Follow-up to the PR #953 review (silent-failure-hunter):

- An rpc_url secret commonly lives in the path/query (Infura/Alchemy keys),
  which `redact_userinfo` (userinfo-only) doesn't scrub. Switch the two
  malformed-URL error sites (`setup::dry_run_without_keys`,
  `chain_ctx::build_provider`) to hide the value entirely as
  `<redacted> (N chars)`, matching the established `config validate` policy.
- Add an in-band upper-boundary assertion (year 9999 parses) so an off-by-one
  in the `parse_http_date` `..=9999` year bound is caught.

Note: the broader transport-error rpc_url leak (reqwest Display echoes the full
URL through alloy errors on any failed RPC call) is pre-existing and
codebase-wide (bond/register/node); tracked separately rather than patched
piecemeal here.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 73563d1 into main Jun 19, 2026
20 checks passed
@thiras
thiras deleted the feat/decdn-setup-wizard branch June 19, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement decdn setup — guided node onboarding wizard (ADR 019 Phases 1–2)

2 participants