Skip to content

feat(cli): bake genesis into build#237

Merged
camembera merged 4 commits intomainfrom
feat/bake-genesis
Apr 10, 2026
Merged

feat(cli): bake genesis into build#237
camembera merged 4 commits intomainfrom
feat/bake-genesis

Conversation

@camembera
Copy link
Copy Markdown
Collaborator

@camembera camembera commented Apr 9, 2026

build.rs copies test fixture into build tree (this is allegedly cleaner)

currently is uncompressed, not trying to be too clever here

Summary by CodeRabbit

  • New Features

    • Chainspec parser includes built-in genesis configurations for mainnet and bepolia; default network set to mainnet.
  • Build Changes

    • Ethereum genesis fixtures are baked into the build output so built-in networks are available at runtime.
  • Dependency Changes

    • JSON serialization library promoted from dev-only to a regular runtime dependency.
  • Tests

    • Added unit tests validating supported networks, default selection, and built-in genesis parsing.

Copilot AI review requested due to automatic review settings April 9, 2026 18:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e89c20e-e159-49a0-bb66-d8bda8cc8c21

📥 Commits

Reviewing files that changed from the base of the PR and between e380619 and a5e5d5d.

📒 Files selected for processing (1)
  • src/chainspec/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/chainspec/mod.rs

📝 Walkthrough

Walkthrough

Embedded Ethereum genesis fixtures (mainnet and bepolia) are baked into the build output via a new build script; serde_json was moved from dev-dependencies to regular dependencies. The chain-spec parser now recognizes "mainnet" and "bepolia" and returns embedded genesis-derived specs, falling back to existing parsing for other inputs.

Changes

Cohort / File(s) Summary
Dependency Management
Cargo.toml
Moved serde_json = "1.0" from [dev-dependencies] to [dependencies], making it a regular dependency.
Build-time Genesis Embedding
build.rs
Added logic to copy tests/fixtures/mainnet-genesis.json and tests/fixtures/bepolia-genesis.json into OUT_DIR, registered cargo:rerun-if-changed for these fixtures, and introduced helper functions and constants for baking fixtures.
Chain Specification Parser Update
src/chainspec/mod.rs
Added embedded include_str! references to baked genesis JSONs, advertised supported chains ["mainnet","bepolia"], set default chain to "mainnet", and updated parse to return embedded-genesis-derived specs for those names; added unit tests.

Sequence Diagram

sequenceDiagram
    participant Cargo as Build System
    participant BuildRS as build.rs
    participant Fixtures as Fixtures (`tests/fixtures/*`)
    participant OutDir as OUT_DIR
    participant Runtime as ChainSpec Parser

    Cargo->>BuildRS: run build script
    BuildRS->>Fixtures: read mainnet & bepolia fixture files
    BuildRS->>BuildRS: emit cargo:rerun-if-changed for fixtures
    BuildRS->>OutDir: copy baked fixture files into OUT_DIR

    Note over Runtime: At runtime (parsing chain)
    Runtime->>Runtime: receive chain name input
    alt input == "mainnet" or "bepolia"
        Runtime->>OutDir: include_str! baked JSON from OUT_DIR
        OutDir-->>Runtime: embedded genesis JSON
    else other
        Runtime->>Runtime: call parse_genesis(input)
    end
    Runtime-->>Runtime: return ChainSpec
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • calbera
  • fridrik01

Poem

🐰 Hopping through builds with a crate in tow,

Fixtures tucked in where cold bytes grow,
Mainnet and Bepolia snug and bright,
Parsed at runtime, ready to take flight,
Tiny paws cheer for a seamless night! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(cli): bake genesis into build' accurately describes the main change: a build step that bakes genesis fixture files into the build output.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/bake-genesis

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/chainspec/mod.rs (1)

1869-1870: Extract parser test chain IDs into named constants.

These literals make maintenance brittle and violate the repository rule for magic numbers.

♻️ Proposed change
+    const BERACHAIN_MAINNET_CHAIN_ID: u64 = 80094;
+    const BERACHAIN_BEPOLIA_CHAIN_ID: u64 = 80069;
+
     #[test]
     fn test_parser_builtin_mainnet_and_bepolia_parse() {
         let mainnet = BerachainChainSpecParser::parse(BERACHAIN_MAINNET).unwrap();
         let bepolia = BerachainChainSpecParser::parse(BERACHAIN_BEPOLIA).unwrap();

-        assert_eq!(mainnet.inner.chain.id(), 80094);
-        assert_eq!(bepolia.inner.chain.id(), 80069);
+        assert_eq!(mainnet.inner.chain.id(), BERACHAIN_MAINNET_CHAIN_ID);
+        assert_eq!(bepolia.inner.chain.id(), BERACHAIN_BEPOLIA_CHAIN_ID);
     }

As per coding guidelines: "Extract magic numbers into documented constants".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/chainspec/mod.rs` around lines 1869 - 1870, Extract the magic numeric
literals used in the parser test assertions into named, documented constants and
use those constants in the asserts instead of raw numbers; specifically, define
constants (e.g., PARSER_TEST_CHAIN_ID_MAINNET and PARSER_TEST_CHAIN_ID_BEPOLIA)
near the top of the tests or module and replace the literals in the assertions
referencing mainnet.inner.chain.id() and bepolia.inner.chain.id() with these
constants, adding a short doc comment for each constant explaining what chain ID
it represents.
build.rs (1)

94-101: Add copy-path context to fixture copy failures.

If copy fails, current errors are low-context. Including source/destination in the error greatly improves CI/debuggability.

♻️ Proposed change
 fn copy_fixture_to_out_dir(
     manifest_dir: &str,
     fixture_relative_path: &str,
     destination: &Path,
 ) -> Result<(), Box<dyn Error>> {
     let source = PathBuf::from(manifest_dir).join(fixture_relative_path);
-    fs::copy(source, destination)?;
+    fs::copy(&source, destination).map_err(|err| {
+        std::io::Error::new(
+            err.kind(),
+            format!(
+                "failed to copy fixture '{}' -> '{}': {err}",
+                source.display(),
+                destination.display()
+            ),
+        )
+    })?;
     Ok(())
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@build.rs` around lines 94 - 101, The copy_fixture_to_out_dir function returns
low-context errors when fs::copy fails; update the fs::copy call to map the
error into a new Box<dyn Error> that includes the source (source.display()) and
destination (destination.display()) and the original error message so CI logs
show both paths. Concretely, replace the plain fs::copy(source, destination)?
with logic that captures the error (e.g., using map_err or match) and constructs
a descriptive error string like "failed to copy {source} -> {destination}:
{err}", then return that as the Boxed error, leaving the rest of
copy_fixture_to_out_dir unchanged. Ensure you reference the local variables
source and destination in the error text so the paths are included.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@build.rs`:
- Around line 94-101: The copy_fixture_to_out_dir function returns low-context
errors when fs::copy fails; update the fs::copy call to map the error into a new
Box<dyn Error> that includes the source (source.display()) and destination
(destination.display()) and the original error message so CI logs show both
paths. Concretely, replace the plain fs::copy(source, destination)? with logic
that captures the error (e.g., using map_err or match) and constructs a
descriptive error string like "failed to copy {source} -> {destination}: {err}",
then return that as the Boxed error, leaving the rest of copy_fixture_to_out_dir
unchanged. Ensure you reference the local variables source and destination in
the error text so the paths are included.

In `@src/chainspec/mod.rs`:
- Around line 1869-1870: Extract the magic numeric literals used in the parser
test assertions into named, documented constants and use those constants in the
asserts instead of raw numbers; specifically, define constants (e.g.,
PARSER_TEST_CHAIN_ID_MAINNET and PARSER_TEST_CHAIN_ID_BEPOLIA) near the top of
the tests or module and replace the literals in the assertions referencing
mainnet.inner.chain.id() and bepolia.inner.chain.id() with these constants,
adding a short doc comment for each constant explaining what chain ID it
represents.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a1c12f90-6b41-4b5d-847b-cf4ff88d2bdf

📥 Commits

Reviewing files that changed from the base of the PR and between b633d71 and e2f4d8a.

📒 Files selected for processing (3)
  • Cargo.toml
  • build.rs
  • src/chainspec/mod.rs

@calbera calbera linked an issue Apr 9, 2026 that may be closed by this pull request
@camembera camembera changed the title feat: bake genesis into build feat(cli): bake genesis into build Apr 9, 2026
Copy link
Copy Markdown
Contributor

@calbera calbera left a comment

Choose a reason for hiding this comment

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

Resolve conflict then utACK

@calbera calbera self-requested a review April 10, 2026 03:20
Signed-off-by: Camembera <camembear@berachain.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/chainspec/mod.rs (1)

1869-1870: Avoid magic chain-id literals in assertions.

Line 1869 and Line 1870 use raw IDs. Prefer named chain variants to reduce drift risk and improve readability.

♻️ Suggested diff
-        assert_eq!(mainnet.inner.chain.id(), 80094);
-        assert_eq!(bepolia.inner.chain.id(), 80069);
+        assert_eq!(mainnet.inner.chain.id(), Berachain as u64);
+        assert_eq!(bepolia.inner.chain.id(), BerachainBepolia as u64);

As per coding guidelines: Extract magic numbers into documented constants.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/chainspec/mod.rs` around lines 1869 - 1870, The assertions use raw
chain-id literals; define descriptive constants (e.g., MAINNET_CHAIN_ID and
BEPOLIA_CHAIN_ID) or reference existing named chain variants and use those
constants in the asserts instead of 80094 and 80069; update the assertions that
call mainnet.inner.chain.id() and bepolia.inner.chain.id() to compare against
the new constants/variants and add a brief doc comment for each constant to
explain the value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/chainspec/mod.rs`:
- Around line 1869-1870: The assertions use raw chain-id literals; define
descriptive constants (e.g., MAINNET_CHAIN_ID and BEPOLIA_CHAIN_ID) or reference
existing named chain variants and use those constants in the asserts instead of
80094 and 80069; update the assertions that call mainnet.inner.chain.id() and
bepolia.inner.chain.id() to compare against the new constants/variants and add a
brief doc comment for each constant to explain the value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf359a83-a6e5-4af8-859b-b17e41af3681

📥 Commits

Reviewing files that changed from the base of the PR and between e2f4d8a and e380619.

📒 Files selected for processing (1)
  • src/chainspec/mod.rs

@camembera camembera enabled auto-merge (squash) April 10, 2026 12:47
@camembera camembera merged commit 2c7a9c5 into main Apr 10, 2026
10 checks passed
@camembera camembera deleted the feat/bake-genesis branch April 10, 2026 13:02
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.

Make the default --chain as bera-mainnet

2 participants