Skip to content

fix(node): restore StateRootValidator hook for pre-Jade state root ha… - #47

Merged
panos-xyz merged 2 commits into
mainfrom
panos/fix-state-root-validator
Mar 12, 2026
Merged

panos-xyz merged 2 commits into
mainfrom
panos/fix-state-root-validator

Conversation

@panos-xyz

@panos-xyz panos-xyz commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

PR #46 switched reth dependency to paradigmxyz/reth v1.10.0 which lacks the StateRootValidator trait, causing unconditional MPT state root validation that rejects all pre-Jade blocks (ZK-trie headers never match MPT roots).

This commit:

  • Switches reth dependency to morph-l2/reth@1dd7227 (v1.10.0 + state-root hook) which provides the StateRootValidator trait
  • Implements StateRootValidator for MorphEngineValidator: always computes MPT roots (keeps trie up-to-date from genesis), but skips validation against header pre-Jade since headers carry ZK-trie roots
  • Wires MorphEngineValidator as both PayloadValidator and StateRootValidator via BasicEngineValidator's 4th type parameter
  • Restores explanatory comment in validate_block_post_execution_with_hashed_state

Summary by CodeRabbit

  • Chores
    • Migrated many workspace dependencies to a single revisioned source to standardize upstream references.
  • Chores
    • Updated a VM/runtime dependency source and preserved feature flags.
  • New Features
    • Enhanced payload validation to include state-root verification with era-specific enforcement and mismatch reporting.

…ndling

PR #46 switched reth dependency to paradigmxyz/reth v1.10.0 which lacks
the StateRootValidator trait, causing unconditional MPT state root
validation that rejects all pre-Jade blocks (ZK-trie headers never match
MPT roots).

This commit:
- Switches reth dependency to morph-l2/reth@1dd7227 (v1.10.0 + state-root
  hook) which provides the StateRootValidator trait
- Implements StateRootValidator for MorphEngineValidator: always computes
  MPT roots (keeps trie up-to-date from genesis), but skips validation
  against header pre-Jade since headers carry ZK-trie roots
- Wires MorphEngineValidator as both PayloadValidator and StateRootValidator
  via BasicEngineValidator's 4th type parameter
- Restores explanatory comment in validate_block_post_execution_with_hashed_state
@coderabbitai

coderabbitai Bot commented Mar 12, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Workspace dependencies switched from paradigmxyz/reth tag v1.10.0 to morph-l2/reth at rev 1dd722773844d1a3c50a691dc09f6cdf8e6bd00e across many morph-* crates; MorphEngineValidator gained a StateRootValidator implementation and validator-builder wiring was extended to carry an extra validator parameter.

Changes

Cohort / File(s) Summary
Dependency Migration
Cargo.toml
Updated ~52 workspace dependency entries from https://github.com/paradigmxyz/reth (tag = "v1.10.0") to https://github.com/morph-l2/reth (rev = "1dd722773844d1a3c50a691dc09f6cdf8e6bd00e"), including reth-revm (features preserved) and multiple morph-* crates.
State Root Validation & Validator Wiring
crates/node/src/validator.rs
Added StateRootValidator implementation for MorphEngineValidator with Jade-era hardfork-aware checks; expanded EngineValidator type to include a second validator generic; updated PayloadValidator bounds and builder wiring to pass state-root-aware validator; adjusted imports (GotExpected, MorphHardforks).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • chengwenxi
  • anylots

Poem

🐰
I hopped through Cargo, changed each line,
Switched git roots to a single vine,
Built a validator, checked the state,
Jade-era rules now validate,
A tiny hop — the chain feels fine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 clearly summarizes the main change: restoring StateRootValidator hook for pre-Jade state root handling. It is specific and directly related to the primary objective of the changeset.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch panos/fix-state-root-validator

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/node/src/validator.rs`:
- Around line 201-226: The impl block for StateRootValidator on
MorphEngineValidator (fn validate_state_root) has formatting style issues
flagged by CI; run `cargo fmt` to auto-fix formatting for this block (and the
crate) so the impl, function signature, if/return blocks, and the
ConsensusError::BodyStateRootDiff/GotExpected construction are properly
formatted; focus on formatting the impl
StateRootValidator<morph_primitives::MorphPrimitives> for MorphEngineValidator
and the validate_state_root method to satisfy rustfmt.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ab79ff7-ebc8-4233-8aa7-a95c0bfdfcb6

📥 Commits

Reviewing files that changed from the base of the PR and between af311e3 and d7d9f0d.

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

Comment thread crates/node/src/validator.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/node/src/validator.rs (1)

201-233: Add regression tests around the Jade boundary.

This is the core fork-sensitive behavior in the PR, so I'd add tests for pre-Jade skip, exact Jade activation timestamp, and post-Jade mismatch returning BodyStateRootDiff. That will make future dependency bumps much safer.

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

In `@crates/node/src/validator.rs` around lines 201 - 233, Add unit/regression
tests that exercise MorphEngineValidator::validate_state_root around the Jade
fork boundary: create RecoveredBlock<morph_primitives::Block> instances with
timestamps before Jade (where chain_spec.is_jade_active_at_timestamp returns
false) and assert the method returns Ok (skip comparison), at the exact
activation timestamp and ensure behavior matches your spec (activation should
trigger strict checking), and after Jade ensure a mismatched computed_state_root
causes a ConsensusError::BodyStateRootDiff (GotExpected) to be returned; use or
mock chain_spec and block.header().state_root() to control expected vs computed
roots so tests cover pre-Jade skip, exact-timestamp behavior, and post-Jade
mismatch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/node/src/validator.rs`:
- Around line 201-233: Add unit/regression tests that exercise
MorphEngineValidator::validate_state_root around the Jade fork boundary: create
RecoveredBlock<morph_primitives::Block> instances with timestamps before Jade
(where chain_spec.is_jade_active_at_timestamp returns false) and assert the
method returns Ok (skip comparison), at the exact activation timestamp and
ensure behavior matches your spec (activation should trigger strict checking),
and after Jade ensure a mismatched computed_state_root causes a
ConsensusError::BodyStateRootDiff (GotExpected) to be returned; use or mock
chain_spec and block.header().state_root() to control expected vs computed roots
so tests cover pre-Jade skip, exact-timestamp behavior, and post-Jade mismatch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6eb13d6-d747-42b5-a8a7-7535d8b904de

📥 Commits

Reviewing files that changed from the base of the PR and between d7d9f0d and 8a41827.

📒 Files selected for processing (1)
  • crates/node/src/validator.rs

@panos-xyz
panos-xyz requested a review from chengwenxi March 12, 2026 07:08

@chengwenxi chengwenxi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@panos-xyz
panos-xyz merged commit 39a82a7 into main Mar 12, 2026
8 checks passed
@panos-xyz
panos-xyz deleted the panos/fix-state-root-validator branch March 12, 2026 07:18
panos-xyz added a commit that referenced this pull request Nov 24, 2026
… restarts

Extend PR 233's series-churn fix from State & History Growth to the rest of
the morph-reth Grafana dashboard so long time ranges (30d/60d/90d) render
accurately when pod restarts or redeploys change the instance label:

- Snapshot pie charts and bar gauge (#3, #45, #47, #51, #104): switch to
  instant queries and aggregate with max by (service, ...) (two-level sum/max
  for DB Pages) so historical dead instances no longer duplicate slices.
- Broken aggregations (#39 DB Average Commit Time, #41 DB Average Transaction
  Open Time, #120 CPU, #40/#62/#64 heatmaps): compute weighted averages via
  sum(rate(sum)) / sum(rate(count)) instead of summing/averaging per-series
  ratios, fix CPU from avg(rate(...[1m])) to sum(rate(...[$__rate_interval])),
  and use max for peak latency heatmaps.
- Unaggregated rate/increase panels (17 panels, e.g. Block Import Rate, Engine
  Tree, Proof History, TxPool, P2P) and rate(sum)/rate(count) panels (9 panels):
  aggregate with sum by (service[, segment]) to eliminate multi-hour 50% dips
  and duplicate legends at restart boundaries.
- Raw gauge sum-by-service panels (14 panels including Node Storage & Height,
  DB Growth, Static Files Growth, State Size, History Size, RPC Active
  Connections): replace raw sum by (service) with max by (service) or
  two-level sum by (service) (max by (service, table|segment)) to eliminate
  2x spikes during restart overlap.
- Remaining unaggregated gauge/summary/stat timeseries panels: wrap with
  max by (service, <legend labels>) (avg by (service) for avg_over_time) to
  preserve continuous single lines and clean legends across restarts.

Verified all 258 PromQL expressions against live Prometheus 3.5.0 (0 errors)
and compared before/after query outputs via Grafana 13.3.1 over a 30-day
synthetic dataset with 5 instance restarts and rolling overlap.
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