Repository navigation
refactor(chains): move embedded genesis JSON into base-common-genesis-json - #6690
BrianBland wants to merge 3 commits into
Conversation
🟡 Heimdall Review Status
|
| pub fn for_chain_id(chain_id: u64) -> &'static str { | ||
| match chain_id { | ||
| 8453 => MAINNET_GENESIS_JSON, | ||
| 84532 => SEPOLIA_GENESIS_JSON, | ||
| 763360 => ZERONET_GENESIS_JSON, | ||
| _ => DEVNET_GENESIS_JSON, | ||
| } |
There was a problem hiding this comment.
The silent _ => DEVNET_GENESIS_JSON fallback breaks the old link between a ChainConfig and its own genesis JSON. Now BaseChainSpec::try_from(&ChainConfig) (spec.rs:584) loads devnet's alloc for any config with an unknown chain_id, while still using that config's genesis_l2_hash in SealedHeader::new. The result is a chainspec whose genesis contents don't match its sealed hash, and nothing reports an error.
This already happens in runtime_registry_overrides_execution_fee_and_blob_params, which clones mainnet with chain_id = 9_100_006: it now gets devnet genesis sealed with mainnet's hash. Suggest returning Option<&'static str> and mapping None to a BaseChainSpecError. Also reuse the chain-ID constants from base-common-chains (or key on the chain name) instead of repeating 8453/84532/763360 as literals that can drift from ChainConfig.
There was a problem hiding this comment.
Great catch — fixed in c419390: replaced for_chain_id (and its silent devnet fallback and literal chain IDs) with a 1-byte GenesisKind enum (Mainnet | Sepolia | Devnet | Zeronet) on ChainConfig and an exhaustive GenesisJson::for_kind(cfg.genesis_kind). Cloned configs with overridden chain_id now retain their exact original genesis JSON.
Summary
Move the embedded execution-layer genesis JSON files (
base.json,sepolia_base.json,dev.json,zeronet_base.json— ~26.3 MiB total) out ofbase-common-chains(ChainConfig.genesis_json) into a dedicated#![no_std]cratebase-common-genesis-json(crates/common/genesis-json) backed bystatics.Why
crates/execution/chainspec/src/spec.rsandcrates/execution/evm/benches/fixtures/mainnet_block.rs).ChainConfig::MAINNET/SEPOLIA/ZERONETareconsts withgenesis_json: &'static str, rustc/LLVM was embedding and duplicating the ~26.3 MiB of uncompressed JSON across codegen units in every downstream crate and binary—including non-execution binaries that never touch genesis JSON (libbasectl_cli.rlibwas 110 MiB;basectlhad 74.5 MiB of__TEXT.__const, shrinking from 92.6 MiB → 18.2 MiB (-80%);base-consensushad the same ~74 MiB bloat).GenesisJsonwithstatics in its own crate also ensures execution binaries (base,base-reth-node,base-builder) emit each genesis JSON once instead of duplicating it across CGUs.Changes
crates/common/genesis-json(base-common-genesis-json,#![no_std], zero dependencies) withGenesisJson::{mainnet, sepolia, devnet, zeronet, for_chain_id}.crates/common/chains/res/genesis/*.json→crates/common/genesis-json/res/*.jsonand removeChainConfig.genesis_json.base-execution-chainspecandbase-execution-evm(dev-dependency for benchmark fixture) to read frombase_common_genesis_json::GenesisJson.Verification
cargo test -p base-common-chains(60 passed) andcargo test -p base-execution-chainspec embedded_genesis(passed).cargo clippy -p base-common-genesis-json -p base-common-chains -p base-execution-chainspec --lib -- -D warnings: clean.cargo check -p base-common-genesis-json -p base-common-chains --no-default-features: clean.zepter format features,./etc/scripts/ci/check-crate-deps.sh,cargo deny check bans, root & SP1 guestcargo metadata --locked: clean.