Skip to content

Allow local-env mocked nodes to sync from genesis via marked fork blocks - #2149

Open
justinfrevert wants to merge 5 commits into
mainfrom
feat/justin-fork-transition-runtime
Open

justinfrevert wants to merge 5 commits into
mainfrom
feat/justin-fork-transition-runtime

Conversation

@justinfrevert

@justinfrevert justinfrevert commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Resolves #2071. Works with new mock-authorities changes that mark fork blocks, so a node can sync a locally forked chain from true genesis.

A chain forked by mock-authorities convert contains one block that no honest proposer could have produced. Its seal is signed by a key that is not in the parent's authority set, and its state root reflects a hand-built delta. A node syncing from genesis therefore stops at the fork point.

This adds an off-by-default fork-transition cargo feature. It builds a runtime, supplied to the syncing node via the chain spec's codeSubstitutes, that relaxes exactly three things at exactly one compile-time height (MIDNIGHT_FORK_HEIGHT):

  • AuraApi::authorities reports the fork's mock set (MIDNIGHT_FORK_AURA_AUTHORITIES) at the fork block's parent, so the fork block's seal verifies.
  • check_inherents is skipped for the fork block only.
  • Core::execute_block applies the magic-prefixed storage delta carried in the block body, instead of running Executive. It still asserts the header's extrinsics root, requires the body to be exactly one well-formed delta blob, and the client checks the resulting state root against the header.

Without the feature (or without the env vars), the runtime is identical to stock: no pallet, call or metadata changes. A runtime built with this feature must never be released.

🗹 TODO before merging

  • Ready

📌 Submission Checklist

  • All commits are signed off (git commit -s) for the DCO
  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason:
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • Updated AGENTS.md if build commands, architecture, or workflows changed
  • No new todos introduced

🧪 Testing Evidence

  • cargo test -p midnight-node-runtime --features fork-transition --lib fork_transition — 6 passed. These cover inertness without configuration, parsing, strict delta decoding (including trailing bytes), and a golden blob shared byte-for-byte with mock-authorities' fork::GOLDEN_FORK_BLOB.

  • cargo clippy -p midnight-node-runtime --features fork-transition --lib --tests — clean.

  • Additional tests are provided (if possible)

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other: Feature-gated, off by default, never enabled in released runtimes. Only used as a codeSubstitutes runtime for local test forks.
  • N/A

Links

🤖 Generated with Claude Code

Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
@justinfrevert
justinfrevert requested a review from a team as a code owner September 15, 2026 02:55

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd0015fba0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread runtime/src/lib.rs
…sition-runtime

Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
Bypassing Executive for the fork block also bypassed its final_checks.
The client still checks the state root, but nothing tied the executed
body to the header's extrinsics root, and unrecognised body entries were
silently skipped.

Assert the extrinsics root, require exactly one well-formed delta blob,
and reject delta blobs with trailing bytes. Also fill in the change file's
PR and issue links, and fix clippy lints from the Rust 1.98 bump.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
@justinfrevert justinfrevert added the bot:ai-assisted Authored or substantially edited by an AI agent label Sep 23, 2026
@datadog-official

datadog-official Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Pipelines

⚠️ Warnings

Your PR has warnings. Please review the issues below.

🚦 2 Pipeline jobs failed

CI + E2E | SBOM/Scan Node / sbom-scan

View more details · View in GitHub Actions

CI + E2E | SBOM/Scan Toolkit / sbom-scan

View more details · View in GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bdf70b9 | Docs | View more details | Give us feedback!

justinfrevert and others added 2 commits September 24, 2026 12:44
An empty MIDNIGHT_FORK_HEIGHT parsed as height 0, so a build with the
variable set but blank looked configured instead of inert. Parse it with
str::parse, which rejects empty input, and drop the incorrect comment
claiming str::parse was unavailable.

Also untangle a module-doc paragraph that had been merged into the
spec_version failure-mode section.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:ai-assisted Authored or substantially edited by an AI agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mainnet-fork: sync-from-genesis cannot be exercised — validator fails to start after PVC deletion

1 participant