Skip to content

cli/core: introduce doublezero-cli-core crate and solana_l1_rpc_url#3753

Open
juan-malbeclabs wants to merge 2 commits into
mainfrom
jo/1-cli-core-foundation
Open

cli/core: introduce doublezero-cli-core crate and solana_l1_rpc_url#3753
juan-malbeclabs wants to merge 2 commits into
mainfrom
jo/1-cli-core-foundation

Conversation

@juan-malbeclabs
Copy link
Copy Markdown
Contributor

@juan-malbeclabs juan-malbeclabs commented May 22, 2026

RFC-20 implementation stack

This PR is part of a 9-PR chain delivering RFC-20: CLI standardization. Each PR's diff is only its own contribution; reviewers should consume them in order.

# PR Scope
1 #3753 doublezero-cli-core foundation crate + solana_l1_rpc_url
2 #3754 --solana-url + --log-verbose global flags + tracing init
3 #3755 CliContext built in main + centralized error rendering
4 #3756 rename doublezero_clidoublezero-serviceability-cli
5 #3757 rewrite location get as the async + CliContext reference verb
6 #3758 docs/cli-standard.md + CLAUDE.md pointer
7 #3759 move per-resource subcommand wrappers into the module crate
8 #3760 add ServiceabilityCommand enum + async dispatcher
9 #3761 #[command(flatten)] + collapse binary dispatch

This PR: #3753 — position 1 of 9. Previous: (none — base is main) · Next: #3754


Summary of Changes

  • Adds doublezero-cli-core (crates/doublezero-cli-core/), the shared library crate every doublezero-<module>-cli will reuse per RFC-20. Ships CliContext + CliContextBuilder, RequirementCheck bitflags (bit values aligned with the legacy CHECK_ID_JSON | CHECK_BALANCE | CHECK_FOUNDATION_ALLOWLIST constants), the shared validators (validate_pubkey, validate_pubkey_or_code, validate_code, validate_parse_bandwidth, validate_parse_delay_ms, validate_parse_jitter_ms, validate_parse_delay_override_ms), the DisplayVec formatter, a tracing + tracing-subscriber init_logging(verbosity) helper that writes to stderr, and testing helpers (cli_context_for_tests, cli_context_default_for_tests).
  • Adds solana_l1_rpc_url to doublezero-config::NetworkConfig with the per-environment defaults from RFC-20 §Environments (mainnet-beta -> Solana mainnet-beta; testnet and devnet -> Solana testnet; local -> http://localhost:8899) plus a DZ_SOLANA_RPC_URL env-var override mirroring the existing DZ_LEDGER_RPC_URL / DZ_LEDGER_WS_RPC_URL overrides.
  • Migrates the shared validators.rs and formatters.rs out of smartcontract/cli/ into the new core crate. Existing import paths continue to compile via thin pub use re-export shims in smartcontract/cli/src/{validators,formatters}.rs, so the rest of the workspace is unaffected.

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 7 +618 / -0 +618
Tests 1 +64 / -0 +64
Scaffolding 4 +50 / -167 -117
Config/build 3 +33 / -0 +33
Generated 1 +20 / -0 +20
Docs 1 +2 / -1 +1
Total 17 +787 / -168 +619

Introduces ~620 lines of shared CLI utility code in the new core crate while shrinking smartcontract/cli by replacing its validator and formatter implementations with thin re-export shims; no behavior change.

Key files (click to expand)
  • crates/doublezero-cli-core/src/context.rs - CliContext, OutputFormat, and the CliContextBuilder that resolves --env defaults from doublezero-config and applies per-field overrides.
  • crates/doublezero-cli-core/src/validators.rs - shared clap value-parsers (pubkey, code, pubkey-or-code, bandwidth, delay, jitter, delay-override) with their unit tests; moved verbatim from smartcontract/cli/src/validators.rs.
  • crates/doublezero-cli-core/src/requirements.rs - RequirementCheck bitflags type (KEYPAIR / BALANCE / FOUNDATION_ALLOWLIST) with bit values preserved for ABI continuity with the legacy u8 constants.
  • crates/doublezero-cli-core/src/testing.rs - cli_context_for_tests() / cli_context_default_for_tests() helpers for module-crate verb tests.
  • crates/doublezero-cli-core/src/formatters.rs - DisplayVec + stringify_vec moved from smartcontract/cli.
  • crates/doublezero-cli-core/src/error.rs - Result alias, CliError, render_eyre helper for chain-of-causes rendering.
  • crates/doublezero-cli-core/src/logging.rs - init_logging(verbosity) via tracing-subscriber with stderr writer; honors RUST_LOG when set.
  • config/src/env.rs - adds solana_l1_rpc_url to NetworkConfig, wires it through per environment, and adds DZ_SOLANA_RPC_URL override plus tests.

Testing Verification

  • cargo test -p doublezero-cli-core passes (16 tests across validators, requirements bitflags, context builder, testing helpers, formatters).
  • cargo test -p doublezero-config passes (9 tests including two new ones covering the Solana L1 URL resolution per environment and the DZ_SOLANA_RPC_URL override).
  • make rust-test green, including the program-accounts-compat run.
  • make rust-lint clean.
  • Verified existing smartcontract/cli consumers continue to compile against the shim files (use doublezero_cli::validators::* and friends resolve through the re-export).

Comment thread config/src/constants.rs
@juan-malbeclabs juan-malbeclabs force-pushed the jo/1-cli-core-foundation branch from 1732849 to 3bd8661 Compare May 22, 2026 18:09
When the caller supplies ledger_rpc_url but not ledger_ws_rpc_url, the
builder now derives the WebSocket URL by scheme swap (https to wss,
http to ws) instead of leaving the env default in place. Without this,
ctx.ledger_rpc_url and ctx.ledger_ws_rpc_url could disagree when only
the RPC URL was overridden, silently pairing a custom RPC with a stale
env-default WS endpoint.

Adds builder tests covering both schemes, the explicit-WS-wins case,
the env-only regression path, and extends the existing per-field
override test to assert the WS is derived from the custom RPC.
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.

2 participants