Skip to content

fix(chainspec): propagate genesis parse errors and preserve ChainSpec fields - #243

Open
panos-xyz wants to merge 1 commit into
mainfrom
fix/chainspec-genesis-error-handling
Open

panos-xyz wants to merge 1 commit into
mainfrom
fix/chainspec-genesis-error-handling

Conversation

@panos-xyz

Copy link
Copy Markdown
Contributor

Summary

Fixes M-M05: improves Morph genesis parsing error handling and preserves parsed ChainSpec fields in morph-chainspec:

Changes (crates/chainspec/src/{genesis.rs,spec.rs,lib.rs})

  • Propagate Morph hardfork deserialization errors (genesis.rs): MorphGenesisInfo::try_from now propagates MorphHardforkInfo::try_from(others)? instead of swallowing errors with .ok(), so malformed Morph fork fields (e.g. "celadonTime": "1750000000", negative integers, wrong types) fail loudly rather than silently disabling all Morph hardforks and Prague. Empty hardfork fields still deserialize cleanly.
  • Preserve inner serde errors in MorphChainConfig::try_from (genesis.rs): Matched others.get_deserialized::<Self>("morph") directly so malformed "morph" subfields (feeVaultAddress, maxTxPayloadBytesPerBlock, wrong type) report the real deserialization error instead of falsely reporting missing field 'morph'.
  • Fallible MorphChainSpec construction & clean CLI errors (spec.rs, lib.rs):
    • Added MorphChainSpecError (InvalidGenesisInfo(serde_json::Error) and MissingGenesisHash) and fallible constructors MorphChainSpec::try_from_genesis and MorphChainSpec::try_from_genesis_with_config, keeping from_genesis, from_genesis_with_config, and From<Genesis> delegating to try_*().expect(...) for API compatibility.
    • Updated chain_value_parser (#[cfg(feature = "cli")]) to use MorphChainSpec::try_from_genesis(reth_cli::chainspec::parse_genesis(s)?)?, returning clean eyre::Result CLI errors instead of panicking on invalid custom genesis inputs.
  • Preserve all parsed ChainSpec fields (spec.rs): Build the base Ethereum ChainSpec::from_genesis once (after validating Morph genesis info and GenesisConfig) and explicitly destructure and preserve all fields (paris_block_and_final_difficulty, deposit_contract, base_fee_params, prune_delete_limit, blob_params, hardforks, chain, genesis) instead of discarding them via ..Default::default(). MORPH_MAINNET and MORPH_HOODI genesis headers, hashes, hardforks, and MORPH_BASE_FEE defaults remain identical.
  • Tests: Added 6 unit tests covering malformed hardfork fields, empty hardforks, preserved inner serde errors on malformed "morph" subfields, missing "morph", MissingGenesisHash, preserved ChainSpec fields (both via try_from_genesis and From<ChainSpec>), and chain_value_parser (#[cfg(feature = "cli")]).

Verification

  • cargo fmt --all -- --check — pass
  • cargo clippy --workspace --all-targets -- -D warnings — pass
  • cargo clippy -p morph-chainspec --all-features --all-targets -- -D warnings — pass
  • cargo test -p morph-chainspec — 49/49 unit + 3/3 doc-tests passed
  • cargo test -p morph-chainspec --all-features — 50/50 unit + 3/3 doc-tests passed
  • cargo test -p morph-reth — 3/3 passed

… fields (M-M05)

- Stop swallowing MorphHardforkInfo deserialization errors in
  MorphGenesisInfo::try_from so malformed Morph fork fields fail loudly
  instead of silently disabling Morph hardforks and Prague.
- Preserve inner serde errors in MorphChainConfig::try_from instead of
  masking malformed `morph` subfields as `missing field 'morph'`.
- Add MorphChainSpecError and fallible MorphChainSpec::try_from_genesis
  / try_from_genesis_with_config constructors, and wire
  chain_value_parser to return clean CLI errors instead of panicking on
  invalid custom genesis files.
- Build the base Ethereum ChainSpec once and destructure/preserve all of
  its fields (paris_block_and_final_difficulty, deposit_contract,
  base_fee_params, prune_delete_limit, blob_params) instead of
  discarding them via `..Default::default()`.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34a5472e-34fb-457b-9fda-0c04793710dd
Commits

Reviewing files that changed from the base of the PR and between e01b16a and a06b716.

Files selected for processing: 3

  • crates/chainspec/src/genesis.rs
  • crates/chainspec/src/lib.rs
  • crates/chainspec/src/spec.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

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

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.

1 participant