refactor(toolkit): give each ledger version its own copy of the builders - #2075
refactor(toolkit): give each ledger version its own copy of the builders#2075ozgb wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ad796549f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -1,6 +1,7 @@ | |||
| use super::ledger_helpers_local::{self, DefaultDB, FinalizedTransaction, mn_ledger_serialize}; | |||
| use crate::commands::contract_address::{ContractAddressBoth, ContractAddressError}; | |||
There was a problem hiding this comment.
Add the required license headers to new Rust files
Add LICENSE_HEADER.txt to this newly introduced source file and the other headerless additions: seven command files under each ledger version, plus contract_custom.rs, register_dust_address.rs, and transactions.rs under each builders version. All 20 are added as new .rs paths in this commit but begin directly with imports, contrary to the repository requirement for every new source file.
AGENTS.md reference: AGENTS.md:L239-L241
Useful? React with 👍 / 👎.
30b23fd to
86f1a8f
Compare
This comment has been minimized.
This comment has been minimized.
`tx_generator/builder/builders/common/**` and `commands/fork/common/**` were
each compiled twice via a `#[path = "common"] pub mod inner { … }` trick, once
bound to the ledger-8 helpers and once to the ledger-9 helpers, with
`ledger_helpers_local` resolving differently in each instantiation. A reader of
a file under `common/` could not tell which ledger version it was looking at,
and an edit meant for one version silently applied to both. This finishes the
job #2059 and the ledger-helpers split started.
Each version now has its own directory — `builders/{ledger_8,ledger_9}/` and
`commands/fork/{ledger_8,ledger_9}/` — and each file names its own version with
a `use midnight_node_ledger_helpers::ledger_N as ledger_helpers_local;` line, so
the two copies stay byte-identical apart from that one word and `diff -r` can
police them. The only genuine divergence left is `builders/*/mod.rs`, which
carries the per-version `serialize_tx`.
The `inner` wrapper module is gone (nothing referenced it), so every external
path — `builders::ledger_8::SingleTxBuilder`, `fork::ledger_9::show_wallet`, … —
is unchanged, as is the CLI surface.
`impl_encoded_zswap_conversions!` stays in `builders/mod.rs`: `ledger_storage`
still aliases to `ledger_storage_ledger_8` in both versions, so duplicating the
impls per version would still hit E0119.
With this, `grep -r '#\[path' --include='*.rs'` over the workspace returns
nothing, and no directory is compiled more than once.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
Assisted-by: Claude:claude-opus-5 Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
86f1a8f to
9f11c7b
Compare
Overview
Last of three PRs closing #1768: directories compiled twice via Rust's
#[path = "…"]attribute, once bound to the ledger-8 crates and once to theledger-9 crates, so that
super::resolves differently in each instantiation.A reader of such a file cannot tell which ledger crate an alias refers to, and
an edit meant for one generation silently applies to both. #2059 fixed
ledger/src/, the previous PR in the stack fixedledger/helpers/src/, andthis one fixes the two remaining occurrences in the toolkit.
Both used the same trick:
so
builders/common/(16 files, 3328 lines) andcommands/fork/common/(8 files, 374 lines) were each compiled twice. Each version now has its own
directory —
builders/{ledger_8,ledger_9}/andcommands/fork/{ledger_8,ledger_9}/— and each file names its own version withone
use midnight_node_ledger_helpers::ledger_N as ledger_helpers_local;line,so bodies stay byte-identical between the two copies.
util/toolkit/src/commands/common/is a different, single-compiled module andis left alone.
This is not a move toward a generic
<L: Ledger>builder. rustc alreadyemitted both instantiations; this only makes the existing duplication visible so
diff -rcan police it. In particulartype_convert.rs's identity conversionson the v9 side stay exactly as they are.
Notes for review:
innerwrapper module disappears. It is referenced nowhere outside thesefour files, so every external path (
builders::ledger_8::SingleTxBuilder,fork::ledger_9::show_wallet, …) and the whole CLI surface are unchanged.impl_encoded_zswap_conversions!stays inbuilders/mod.rs. Its commentneeded one phrase updated, but the reason still holds:
ledger_storagealiases to
ledger_storage_ledger_8in both versions, so some types areshared and duplicate impls would still conflict with E0119.
remote_prover.rs(impl …ledger_8::ProofProvider) is outside the duplicatedtree and is untouched.
With this merged,
grep -rn '#\[path' --include='*.rs'over the workspacereturns nothing and no directory is compiled more than once — #1768 is done.
🗹 TODO before merging
📌 Submission Checklist
git commit -s) for the DCO🧪 Testing Evidence
(The Docker-based
hardfork_e2eintegration test fails locally against a stalepre-#2059 node image —
expected header tag 'midnight:ledger-state[v18]:', got '…[v13]:'from the container's own genesis load, before any toolkit code runs.CI builds that image from the branch.)
The layout check the split buys — the two copies must be identical apart from
the version name:
And the surface is unchanged:
Also run:
cargo fmt --all --check,cargo clippy -p midnight-node-toolkit --all-targets -- -D warnings,cargo check --workspace --all-targets,cargo build --release.🔱 Fork Strategy
Links