Skip to content

DRY zaino-common#1371

Open
zancas wants to merge 3 commits into
devfrom
dry_zaino_common
Open

DRY zaino-common#1371
zancas wants to merge 3 commits into
devfrom
dry_zaino_common

Conversation

@zancas

@zancas zancas commented Jul 5, 2026

Copy link
Copy Markdown
Member

Deduplicates zaino-common and deletes its dead public API. Net −247 lines of Rust (391 deleted, 144 added including CHANGELOG), behavior preserved throughout.

logging.rs — 386 → 187 lines

  • The six init_tree/try_init_tree/init_stream/try_init_stream/init_json/try_init_json bodies (plus the duplicated EnvFilter construction) collapse into one private try_install(LogConfig) -> Result<(), TryInitError>. init() panics if a global subscriber is already set; try_init() ignores that case — same public semantics as before.
  • Deleted dead public API (zero callers workspace-wide): DisplayHash, DisplayHexStr, init_with_config, try_init_with_config, the LogConfig builder methods, and show_span_events (only settable through the deleted builder, so effectively constant false). LogConfig/LogFormat are now private, per minimum-visibility policy.
  • The runtime interface is untouched: ZAINOLOG_FORMAT / ZAINOLOG_COLOR / RUST_LOG behave exactly as before, and all three output formats (stream/tree/json) are preserved.

config/network.rs — 371 → 308 lines

  • New activation_heights_mirror! declarative macro records the NetworkUpgrade-variant ↔ ActivationHeights-field correspondence exactly once and expands to:
    • the two mirror From impls between ActivationHeights and zebra's ConfiguredActivationHeights, and
    • ActivationHeights::from_zebra_pairs, replacing the hand-written all-None literal + 12-arm upgrade match inside From<zebra_chain::parameters::Network>.
  • Exhaustive destructures and an exhaustive match keep full compile-time drift detection: a new zebra field or variant fails the build until its pair is added. A future network upgrade lands as a single (Variant, field) entry (plus the struct field). The macro's doc comment records why a macro (plain fns cannot abstract over struct fields; Nu5/nu5 casing is not derivable in macro_rules!) and why it also covers the upgrade walk (upstream conversion shape is stable; upgrades are the recurring edit).
  • Deleted Network::zaino_regtest_heights — no callers anywhere in the workspace.

CHANGELOG / versions

Breaking removals and the internal refactors are recorded in packages/zaino-common/CHANGELOG.md under Unreleased. No version bumps — deferred to release per project policy.

Verification

  • cargo check --workspace — clean
  • cargo clippy -p zaino-common --all-targets — clean
  • cargo fmt — applied
  • cargo nextest run -p zaino-common — 19/19 passed (includes the round-trip test now exercising the macro-generated impls)
  • cargo test --doc -p zaino-common — 8/8 passed

🤖 Generated with Claude Code

Deduplicate zaino-common and delete its dead public API; net -247
lines of Rust, behavior preserved.

logging.rs (386 -> 187 lines):
- Collapse the six init_*/try_init_* bodies into one private
  try_install(LogConfig); init() panics if a global subscriber is
  already set, try_init() ignores that case.
- Delete unused DisplayHash/DisplayHexStr and the unreachable
  programmatic config surface (LogConfig builder methods,
  show_span_events, the *_with_config entry points); LogConfig and
  LogFormat are now private.
- The ZAINOLOG_FORMAT/ZAINOLOG_COLOR/RUST_LOG interface and all three
  output formats are unchanged.

config/network.rs (371 -> 308 lines):
- New activation_heights_mirror! macro records the NetworkUpgrade
  variant <-> ActivationHeights field correspondence once and expands
  to the two mirror From impls plus from_zebra_pairs (all-None init +
  upgrade-list walk). Exhaustive destructures and match keep full
  compile-time drift detection; a future network upgrade lands as a
  single (Variant, field) pair.
- Delete Network::zaino_regtest_heights (no callers workspace-wide).

CHANGELOG: breaking removals and internal refactors recorded under
Unreleased; version bump deferred to release.

Verified: cargo check --workspace, cargo clippy --all-targets,
cargo fmt, cargo nextest run -p zaino-common (19/19 passed),
doctests (8/8 passed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zancas zancas requested a review from idky137 July 5, 2026 21:34
Compiler-verified sweep: each dependency in zaino-common's manifest was
deleted one at a time and the crate re-checked with
`cargo check -p zaino-common --all-targets`; a passing check kept the
deletion, a failing one restored the dependency.

Dropped (zero references, check passes without them):
- thiserror — never used by this crate
- nu-ansi-term — never used directly; tracing-tree pulls its own copy
  transitively
- hex — last consumers were DisplayHash/DisplayHexStr, removed in the
  preceding DRY commit

Kept (check fails without them): zebra-chain, serde, tracing,
tracing-subscriber, tracing-tree, time.

The root [workspace.dependencies] nu-ansi-term entry is now unused by
every member but left in place; removing it is a separate root-manifest
decision.

Verified: cargo check --workspace --all-targets clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zancas zancas requested a review from nachog00 July 5, 2026 22:05
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.

1 participant