Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data#159
Conversation
Vui-Chee
left a comment
There was a problem hiding this comment.
Build Failure: just c fails
Running just c (the check command) fails immediately with:
error inheriting `reth-db-api` from workspace root manifest's `workspace.dependencies.reth-db-api`
Caused by:
`dependency.reth-db-api` was not found in `workspace.dependencies`
Root Cause
bin/tools/Cargo.toml adds two new workspace dependencies that don't exist in the root Cargo.toml's [workspace.dependencies]:
-
reth-db-api— used ingen_genesis.rsforDbCursorRO,DbDupCursorRO,tables, andDbTx. This needs to be added to the workspace dependencies in the rootCargo.toml. -
reth-node-types— added tobin/tools/Cargo.tomlbut never actually imported or used anywhere in the source code. This should either be removed fromCargo.toml, or if it was intended to be used, the workspace dependency needs to be added to rootCargo.tomland the relevant code should use it.
Fix
- Add
reth-db-apito[workspace.dependencies]in the rootCargo.toml(with the appropriate git source matching otherreth-*crates). - Remove
reth-node-typesfrombin/tools/Cargo.tomlsince it's unused, or add it to workspace deps if it's actually needed.
Code Review Notes (non-blocking, for after the build is fixed)
The implementation itself looks clean and well-structured. A few minor observations:
read_account_bytecoderedundant guard: The function takesOption<B256>and pattern-matches onNone, but the caller at line 233 already checksaccount.bytecode_hash.is_some()before calling. Consider simplifying to takeB256directly.- Empty code hash computed on every call:
alloy_primitives::keccak256([])inread_account_bytecode(line 306) is recomputed for every account with code. Consider making it aconstorlazy_static/once_cell. - The
DockerfileToolsexposes network ports (EXPOSE 30303 ...) which aren't relevant for a tools-only image — this is cosmetic but could be cleaned up.
…s.rs - Changed the source label in DockerfileTools from 'xlayer' to 'okx'. - Updated log messages in README.md to reflect the new versioning format for xlayer-reth-tools. - Improved logging in gen_genesis.rs to provide clearer warnings for missing bytecode and set up an interrupt handler for graceful shutdown.
- Removed redundant EXPOSE statements in DockerfileTools. - Enhanced condition in justfile to only remove .cargo if it exists and suffix is not 'dev'. - Simplified bytecode retrieval logic in gen_genesis.rs for better readability and performance.
Vui-Chee
left a comment
There was a problem hiding this comment.
All previous review comments have been addressed:
reth-db-api/reth-node-types: Both added to workspace dependencies in rootCargo.toml— build resolves correctly now.EMPTY_CODE_HASHconst: Moved from per-callkeccak256([])to a compile-timeconstat module level — good.- Missing bytecode logging: Upgraded from
debug!towarn!with a clearer message about potential DB corruption. - Interrupt handler: Moved before DB initialization for earlier Ctrl+C handling.
just c passes (sweep-check, check-format, check-clippy, and tests all green). The one flaky test failure (block_fill_flashblocks) is pre-existing and not related to this PR — confirmed it passes on re-run on both main and this branch.
Minor non-blocking notes for future cleanup (not blocking merge):
reth-node-typesis inbin/tools/Cargo.tomlbut not imported in any source file — unused dependency.DockerfileToolsstill exposes network ports (EXPOSE 30303 ...) that aren't relevant for a tools-only image.
LGTM — good to merge.
Vui-Chee
left a comment
There was a problem hiding this comment.
Code Review
Reviewed the new gen-genesis subcommand. The overall structure is solid — clean separation of concerns, good use of template merging, and proper interrupt handling. Below are the issues found, ordered by severity.
Vui-Chee
left a comment
There was a problem hiding this comment.
All review comments have been addressed. LGTM — good to merge.
* main: Feat(chainspec): adding xlayer-devnet chainspec (#167) chore(builder): flatten flashblocks builder, remove unnecessary trait interfaces (#172) rpc: remove unnecessary trait bounds and dependencies from XlayerRpcExtApiServer impl (#171) fix fmt in bin/tools/gen_genesis.rs (#170) fix(builder): Resolve bugs on upstream flashblocks timing scheduler (#169) Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data (#159) feat(flashblocks): Add flashblocks sequence persistence logic on RPC and sequence replay flashblock builder (#162) chore(builder): remove unused custom-engine-api feature flag in tests (#168) fix: p2p test hang due to hang on port (#165)
* main: (25 commits) fix: bump quinn-proto to 0.11.14 to patch CVE-2026-31812 DoS vuln (#183) pre-job authorization (#193) fix: trigger review skill failed to ack (#192) feat: trigger skill review separately (#191) feat: add Claude skills and CLAUDE.md for AI-assisted development (#190) rename ext (#185) supply workflow for claude (#184) feat(builder): incremental trie cache optimization for flashblocks state root (#163) chore(flashblocks-rpc): migrate op-reth flashblocks into xlayer-reth (#175) Feat(chainspec): adding xlayer-devnet chainspec (#167) chore(builder): flatten flashblocks builder, remove unnecessary trait interfaces (#172) rpc: remove unnecessary trait bounds and dependencies from XlayerRpcExtApiServer impl (#171) fix fmt in bin/tools/gen_genesis.rs (#170) fix(builder): Resolve bugs on upstream flashblocks timing scheduler (#169) Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data (#159) feat(flashblocks): Add flashblocks sequence persistence logic on RPC and sequence replay flashblock builder (#162) chore(builder): remove unused custom-engine-api feature flag in tests (#168) fix: p2p test hang due to hang on port (#165) fix: update testcontainers to v0.27.0 to remediate CVE-2025-62518 (#164) chore(builder): further clean up builder crate (#161) ...
Description
Adding a tool to
bin/toolscrate to allow the creation of a genesis file starting from a template genesis file and existing chain data. This is useful when we want to run a local devnet with XLayer testnet or mainnet data (e.g., from a snapshot). In such a case, the template genesis and existing chain data are the devnte genesis and testnet or mainnet snapshots, respectively.The tool can be used as follows:
We can also run this via Docker, by creating the
xlayer-reth-toolsimage:Type of Change
Code Guidelines
Before submitting your PR, please review the relevant code guidelines in the
docs/folder:Specific Guidelines by Component:
Checklist
docs/folderTesting
Tested in xlayer-toolkit (branch dumi/gen-genesis).