Skip to content

feat: implement eth_config RPC with morph extension#72

Merged
panos-xyz merged 4 commits intomainfrom
feat/eth-config-rpc
Mar 31, 2026
Merged

feat: implement eth_config RPC with morph extension#72
panos-xyz merged 4 commits intomainfrom
feat/eth-config-rpc

Conversation

@panos-xyz
Copy link
Copy Markdown
Contributor

@panos-xyz panos-xyz commented Mar 30, 2026

Summary

  • Implement the eth_config RPC method (EIP-7910) with Morph-specific extension fields (useZktrie, jadeForkTime) that morphnode requires at startup
  • Add MorphEthConfigHandler in morph-rpc crate that follows the upstream EthConfigHandler logic but produces a response with the morph extension object on each fork config
  • Register the handler on all configured transports (HTTP/WS/IPC) via merge_configured in the node add-ons

This is a prerequisite for morphnode to connect to morph-reth. morphnode calls eth_config at startup to determine:

  1. Whether the chain uses ZkTrie (current.morph.useZktrie)
  2. The Jade fork activation timestamp (morph.jadeForkTime from current/next/last)

Without this implementation, morphnode fails to start when connected to morph-reth.

Test plan

  • Unit tests for serialization of MorphExtension, MorphForkConfig (field names, hex encoding, omitempty)
  • cargo check -p morph-rpc -p morph-node passes
  • cargo test -p morph-rpc -p morph-node passes (all 17 tests)
  • Integration: start morph-reth, verify curl -X POST -d '{"jsonrpc":"2.0","method":"eth_config","params":[],"id":1}' http://localhost:8545 returns response with morph extension
  • Integration: verify morphnode can successfully connect and start against morph-reth

Summary by CodeRabbit

  • New Features

    • Added an RPC endpoint to fetch detailed chain configuration: current/next/last fork info, activation timestamps, chain/fork identifiers, blob schedule, precompile mappings, and Morph-specific extensions (useZktrie and optional jadeForkTime).
  • Chores

    • Wired the new endpoint into node startup with registration and tracing logs.
    • Updated crate manifests and public re-exports to expose the new RPC types.

…patibility

Add a Morph-specific eth_config RPC handler that extends the standard
EIP-7910 response with morph extension fields (useZktrie, jadeForkTime).

morphnode calls eth_config at startup to determine the trie type and
Jade fork timing. Without this implementation, morphnode cannot connect
to morph-reth and fails to start.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 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: fa6ad6eb-5c30-44b9-b8a5-1465630874c6

📥 Commits

Reviewing files that changed from the base of the PR and between 49c6522 and 0c0950c.

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

📝 Walkthrough

Walkthrough

Adds a new Morph eth_config JSON-RPC endpoint, exposes MorphEthConfigApiServer/MorphEthConfigHandler, implements fork-derived config logic and precompile extraction, and wires the handler into node RPC registration with logging.

Changes

Cohort / File(s) Summary
RPC Manifest & Re-exports
crates/rpc/Cargo.toml, crates/rpc/src/lib.rs
Added workspace dependency flags to Cargo, declared eth_config module, and re-exported MorphEthConfigApiServer and MorphEthConfigHandler.
Eth Config RPC Endpoint
crates/rpc/src/eth_config.rs
New module implementing eth_config RPC: response types (MorphEthConfig, MorphForkConfig, MorphExtension), MorphEthConfigApi trait and MorphEthConfigHandler; computes current/next/last fork timestamps, derives blob schedules and fork-id, instantiates per-fork EVM contexts to collect precompiles, maps errors to RPC, and includes unit tests.
Node Add-ons Integration
crates/node/src/add_ons.rs
Imported and instantiated MorphEthConfigHandler, adjusted RPC module destructuring, merged eth_config handler into startup RPC modules, and added tracing around registration.

Sequence Diagram

sequenceDiagram
    participant Client as RPC Client
    participant Handler as MorphEthConfigHandler
    participant Provider as Chain Provider
    participant ChainSpec as Chain Spec
    participant EVM as EVM (per-fork)

    Client->>Handler: eth_config()
    Handler->>Provider: fetch latest header / block timestamp(s)
    Provider-->>Handler: header(s)
    Handler->>ChainSpec: query fork activation timestamps & Jade metadata
    ChainSpec-->>Handler: fork activation data
    Handler->>EVM: instantiate per-fork EVM context (current/next/last)
    EVM-->>Handler: precompile registry & config
    Handler->>Handler: assemble MorphForkConfig entries (blob schedule, fork-id, precompiles, extension)
    Handler-->>Client: MorphEthConfig response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through forks and timestamps bright,
I gathered precompiles by soft moonlight,
Blob schedules stacked, Jade peeking through,
A new eth_config for Morph — who knew?
thump

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: implement eth_config RPC with morph extension' clearly and specifically summarizes the main change—implementing an eth_config JSON-RPC endpoint with Morph-specific extensions, which is the primary objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.

✏️ 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/eth-config-rpc

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
crates/rpc/src/eth_config.rs (1)

291-335: Add one fork-resolution test case (not just serialization).

Current tests validate JSON shape, but they don’t cover current/next/last selection behavior. A focused test for “latest timestamp before first timestamp fork” would lock in the expected semantics and prevent regressions in config_impl.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/rpc/src/eth_config.rs`:
- Around line 65-66: The doc comment for the precompiles map is reversed: update
the comment on the precompiles field (type BTreeMap<String, Address>) to state
"name -> address" (since the map key is the precompile name and the value is the
Address) and make the same correction in the other occurrences noted (around
lines 272-285) so documentation matches the builder and type (reference symbols:
precompiles, BTreeMap<String, Address>).
- Around line 200-206: The current selection logic for
current_fork_idx/current_fork_timestamp uses .or_else(||
fork_timestamps.len().checked_sub(1)) which incorrectly falls back to the last
scheduled fork when latest.timestamp() is earlier than the first fork; remove
that fallback so a position of 0 yields None instead of wrapping to the last
index (i.e., drop the .or_else fallback and let .and_then(...).ok_or_else(...)
trigger the error), and make the same change for the analogous selection at the
block handling lines 217–219 (referencing variables/current logic using
fork_timestamps, position(|ts| &latest.timestamp() < ts), and the
current_fork_idx/current_fork_timestamp assignment).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 742aa3e0-7cb6-41e8-a9bd-5bef961ef8b9

📥 Commits

Reviewing files that changed from the base of the PR and between 6ea9660 and a98aeb0.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/node/src/add_ons.rs
  • crates/rpc/Cargo.toml
  • crates/rpc/src/eth_config.rs
  • crates/rpc/src/lib.rs

- Fix precompiles field doc comment: "address -> name" → "name -> address"
  to match the actual BTreeMap<String, Address> type.
- Replace position/checked_sub/or_else chain with rfind/find for current
  fork selection. The old logic incorrectly fell back to the last fork
  when latest timestamp was before the first timestamp fork.
@panos-xyz panos-xyz requested review from anylots and chengwenxi March 31, 2026 07:59
Copy link
Copy Markdown
Contributor

@chengwenxi chengwenxi left a comment

Choose a reason for hiding this comment

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

LGTM. EIP-7910 eth_config implementation is well-structured. The fork-selection fix (rfind) in commit 49c6522 is correct. MorphExtension with jadeForkTime/useZktrie is cleanly integrated. Minor suggestions for follow-up:

  • Add a unit test for config_impl fork-selection logic (current/next/last partitioning, error path)
  • system_contracts being always empty is fine for now but worth documenting if morphnode ever expects L2-specific contracts there

@panos-xyz panos-xyz merged commit 3664ec0 into main Mar 31, 2026
9 checks passed
@panos-xyz panos-xyz deleted the feat/eth-config-rpc branch March 31, 2026 13:46
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.

2 participants