Skip to content

Conversation

@panos-xyz
Copy link
Contributor

@panos-xyz panos-xyz commented Jan 23, 2026

Summary by CodeRabbit

  • New Features

    • Introduced L2 Engine API for block assembly, validation, and finalization
    • Added JSON‑RPC interface for Engine API interactions
    • Implemented structured Engine API error handling with RPC mapping
    • Added state-root validation utilities for fork timing control
  • Chores

    • Updated workspace configuration to include the new Engine API crate
    • Adjusted a dependency feature set and minor .gitignore update

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds a new morph-engine-api crate to the workspace providing an async L2 Engine API trait, JSON-RPC bindings, error types, and validation utilities; registers the crate in the workspace and updates a payload dependency feature.

Changes

Cohort / File(s) Summary
Root config
\.gitignore`, `Cargo.toml``
Updated .gitignore (adds docs/ entry) and added crates/engine-api as a workspace member plus workspace dependency morph-engine-api.
New crate manifest
\crates/engine-api/Cargo.toml``
New crate manifest for morph-engine-api with workspace=true and dependencies on workspace crates and helper crates; no default features.
Public API trait
\crates/engine-api/src/api.rs``
Adds MorphL2EngineApi async trait (assemble/validate/new_l2_block/new_safe_l2_block) with auto_impl and async_trait.
RPC layer
\crates/engine-api/src/rpc.rs`, `crates/engine-api/src/lib.rs``
Adds MorphL2EngineRpc JSON-RPC trait, MorphL2EngineRpcHandler wrapper, server impl delegating to MorphL2EngineApi, and re-exports public API surface from lib.rs.
Error types
\crates/engine-api/src/error.rs``
Introduces MorphEngineApiError enum, mapping to JSON-RPC ErrorObjectOwned, and EngineApiResult<T> alias; includes unit tests for error mapping.
Validation utilities
\crates/engine-api/src/validator.rs``
Adds should_validate_state_root function and MorphValidationContext wrapper for MPT fork-based state-root validation with tests.
Payload dependency feature
\crates/payload/types/Cargo.toml``
Adds "reth-codec" feature to morph-primitives dependency in payload types crate.

Sequence Diagram(s)

sequenceDiagram
    participant Client as RPC Client
    participant RPC as MorphL2EngineRpcHandler
    participant API as MorphL2EngineApi Impl
    participant Exec as Execution Layer

    Client->>RPC: assembleL2Block(params)
    RPC->>API: assemble_l2_block(params)
    API->>Exec: build/assemble L2 block (internal)
    Exec-->>API: ExecutableL2Data
    API-->>RPC: EngineApiResult<ExecutableL2Data>
    RPC->>RPC: into_rpc_result()
    RPC-->>Client: RpcResult<ExecutableL2Data>

    Client->>RPC: validateL2Block(data)
    RPC->>API: validate_l2_block(data)
    API->>Exec: validate block
    Exec-->>API: GenericResponse
    API-->>RPC: EngineApiResult<GenericResponse>
    RPC-->>Client: RpcResult<GenericResponse>
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • anylots
  • chengwenxi

Poem

🐇 A tiny rabbit scribbles an API note,
Async hops and RPC boats afloat,
Errors mapped in tidy rows,
Validation checks where MPT grows,
Hooray — the engine's ready to tote! 🥕

🚥 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: add morph engine api' directly summarizes the main change: introduction of a new morph-engine-api crate with its complete API surface including trait definitions, RPC handlers, error types, and validation utilities.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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

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

@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: 1

🤖 Fix all issues with AI agents
In `@crates/engine-api/src/validator.rs`:
- Line 10: Remove the unused import MorphHardforks from the top-level use
statement; keep MorphChainSpec only, since is_mpt_fork_active_at_timestamp
operates on MorphChainSpec without requiring the MorphHardforks trait in
scope—update the use line to import only MorphChainSpec and run cargo check to
confirm no further references to MorphHardforks remain.
🧹 Nitpick comments (2)
crates/engine-api/src/lib.rs (1)

7-7: Documentation inconsistency: "Emerald hardfork" vs "MPT fork"

The documentation references "Emerald hardfork support" but validator.rs and other code consistently refer to "MPT fork". Consider aligning the terminology for clarity.

📝 Suggested fix
-//! - [`MorphValidationContext`]: Validation context with Emerald hardfork support
+//! - [`MorphValidationContext`]: Validation context with MPT fork support
crates/engine-api/src/error.rs (1)

100-115: Consider expanding test coverage for remaining error variants.

Currently only DiscontinuousBlockNumber and InvalidTransaction are tested. Other variants like WrongParentHash, WithdrawTrieRootMismatch, and Database also have specific error codes that could benefit from verification.

//! because state root verification happens in the ZK proof instead (using ZK-trie).
//! After MPT fork, state root validation is performed in the node (using MPT).

use morph_chainspec::{MorphChainSpec, MorphHardforks};
Copy link

@coderabbitai coderabbitai bot Jan 23, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat crates/engine-api/src/validator.rs

Repository: morph-l2/morph-reth

Length of output: 4102


🏁 Script executed:

rg "MorphHardforks" crates/engine-api/src/validator.rs

Repository: morph-l2/morph-reth

Length of output: 117


🏁 Script executed:

rg "MorphHardforks" crates/engine-api/src/ -g "*.rs"

Repository: morph-l2/morph-reth

Length of output: 152


Remove unused import: MorphHardforks

The MorphHardforks trait is imported but never used in this file. The is_mpt_fork_active_at_timestamp method works on MorphChainSpec without requiring the trait to be in scope. Remove it from line 10:

-use morph_chainspec::{MorphChainSpec, MorphHardforks};
+use morph_chainspec::MorphChainSpec;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use morph_chainspec::{MorphChainSpec, MorphHardforks};
use morph_chainspec::MorphChainSpec;
🤖 Prompt for AI Agents
In `@crates/engine-api/src/validator.rs` at line 10, Remove the unused import
MorphHardforks from the top-level use statement; keep MorphChainSpec only, since
is_mpt_fork_active_at_timestamp operates on MorphChainSpec without requiring the
MorphHardforks trait in scope—update the use line to import only MorphChainSpec
and run cargo check to confirm no further references to MorphHardforks remain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The is_mpt_fork_active_at_timestamp function is MorphHardforks's trait function, so we need this trait import

Copy link

Choose a reason for hiding this comment

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

@panos-xyz, you're absolutely right! I apologize for the incorrect suggestion. In Rust, trait methods require the trait to be in scope for them to be callable on implementing types. Even though MorphHardforks isn't directly referenced in the code, it must be imported so that is_mpt_fork_active_at_timestamp() can be called on MorphChainSpec instances. Thank you for the clarification!

🐰📚


✏️ Learnings added
Learnt from: panos-xyz
Repo: morph-l2/morph-reth PR: 12
File: crates/engine-api/src/validator.rs:10-10
Timestamp: 2026-01-23T10:00:04.805Z
Learning: In Rust code within the morph-reth repository, trait imports are necessary even when not directly referenced if trait methods are being called on implementing types. For example, `MorphHardforks` must be imported to call `is_mpt_fork_active_at_timestamp()` on `MorphChainSpec` instances.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

- Add MorphL2EngineApi trait for block building and validation
- Add MorphL2EngineRpcServer for JSON-RPC implementation
- Add MorphValidationContext for state root validation
- Refactor hardfork code into separate modules (block/curie.rs, block/receipt.rs)
- Fix state root validation logic for MPT fork
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