Skip to content

Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data#159

Merged
louisliu2048 merged 21 commits intomainfrom
dumi/gen-genesis-only
Mar 4, 2026
Merged

Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data#159
louisliu2048 merged 21 commits intomainfrom
dumi/gen-genesis-only

Conversation

@dloghin
Copy link
Contributor

@dloghin dloghin commented Feb 27, 2026

Description

Adding a tool to bin/tools crate 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:

just install-tools
xlayer-reth-tools gen-genesis --datadir <path-to-existing-xlayer-reth-datadir> --chain xlayer-testnet --template-genesis ./config-op/genesis.json --output ./config-op/genesis-reth.json

We can also run this via Docker, by creating the xlayer-reth-tools image:

just build-docker-tools

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Code Guidelines

Before submitting your PR, please review the relevant code guidelines in the docs/ folder:

Specific Guidelines by Component:

Checklist

  • I have reviewed the relevant code guidelines in the docs/ folder
  • My code follows the coding standards of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Testing

Tested in xlayer-toolkit (branch dumi/gen-genesis).

@dloghin dloghin marked this pull request as ready for review February 27, 2026 04:46
@dloghin dloghin requested a review from Vui-Chee February 27, 2026 04:46
@dloghin dloghin changed the title https://github.com/apache/incubator-resilientdb/tree/fides Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data Feb 27, 2026
@dloghin dloghin closed this Feb 27, 2026
@dloghin dloghin reopened this Feb 27, 2026
Copy link
Contributor

@Vui-Chee Vui-Chee left a comment

Choose a reason for hiding this comment

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

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]:

  1. reth-db-api — used in gen_genesis.rs for DbCursorRO, DbDupCursorRO, tables, and DbTx. This needs to be added to the workspace dependencies in the root Cargo.toml.

  2. reth-node-types — added to bin/tools/Cargo.toml but never actually imported or used anywhere in the source code. This should either be removed from Cargo.toml, or if it was intended to be used, the workspace dependency needs to be added to root Cargo.toml and the relevant code should use it.

Fix

  • Add reth-db-api to [workspace.dependencies] in the root Cargo.toml (with the appropriate git source matching other reth-* crates).
  • Remove reth-node-types from bin/tools/Cargo.toml since 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_bytecode redundant guard: The function takes Option<B256> and pattern-matches on None, but the caller at line 233 already checks account.bytecode_hash.is_some() before calling. Consider simplifying to take B256 directly.
  • Empty code hash computed on every call: alloy_primitives::keccak256([]) in read_account_bytecode (line 306) is recomputed for every account with code. Consider making it a const or lazy_static / once_cell.
  • The DockerfileTools exposes network ports (EXPOSE 30303 ...) which aren't relevant for a tools-only image — this is cosmetic but could be cleaned up.

@dloghin dloghin requested a review from Vui-Chee February 27, 2026 07:19
…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.
Copy link
Contributor

@Vui-Chee Vui-Chee left a comment

Choose a reason for hiding this comment

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

All previous review comments have been addressed:

  • reth-db-api / reth-node-types: Both added to workspace dependencies in root Cargo.toml — build resolves correctly now.
  • EMPTY_CODE_HASH const: Moved from per-call keccak256([]) to a compile-time const at module level — good.
  • Missing bytecode logging: Upgraded from debug! to warn! 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-types is in bin/tools/Cargo.toml but not imported in any source file — unused dependency.
  • DockerfileTools still exposes network ports (EXPOSE 30303 ...) that aren't relevant for a tools-only image.

LGTM — good to merge.

@dloghin dloghin requested a review from Vui-Chee March 2, 2026 11:22
Copy link
Contributor

@Vui-Chee Vui-Chee left a comment

Choose a reason for hiding this comment

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

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.

@dloghin dloghin requested a review from Vui-Chee March 4, 2026 06:07
Copy link
Contributor

@Vui-Chee Vui-Chee left a comment

Choose a reason for hiding this comment

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

All review comments have been addressed. LGTM — good to merge.

@louisliu2048 louisliu2048 merged commit 6428aa9 into main Mar 4, 2026
@dloghin dloghin deleted the dumi/gen-genesis-only branch March 4, 2026 07:14
Vui-Chee added a commit that referenced this pull request Mar 9, 2026
* 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)
Vui-Chee added a commit that referenced this pull request Mar 13, 2026
* 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)
  ...
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.

3 participants