Skip to content

feat(consensus): SIP-5 speculative apply — block hash commits state root (Bug B, #751)#814

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/speculative-apply-state-root
Jun 21, 2026
Merged

feat(consensus): SIP-5 speculative apply — block hash commits state root (Bug B, #751)#814
github-actions[bot] merged 1 commit into
mainfrom
feat/speculative-apply-state-root

Conversation

@satyakwok

@satyakwok satyakwok commented Jun 14, 2026

Copy link
Copy Markdown
Member

Draft / WIP — not for merge. Block-executor core for SIP-5 (Bug B, #751): speculative apply at propose so the block hash commits the post-execution state_root, closing the block.hash != justification.block_hash inconsistency.

Design: SIP-5 (B1).

In this PR (block-executor side)

  • SPECULATIVE_APPLY_HEIGHT fork gate (default u64::MAX both nets — inert until activated by env)
  • Blockchain::speculative_apply_for_state_root — computes the state_root a candidate block would produce on a throwaway clone (justification gate is peer-only, so a propose-time block with no justification still applies)
  • Blockchain::is_speculative_apply_height wrapper
  • commit-gate: post-fork, a self-produced block with state_root = None is rejected instead of stamp+recompute (the Bug B H1→H2 divergence)

Builds clean (-p sentrix-fork-heights, -p sentrix-core).

Remaining (separate commits)

  • Propose-side stamp in bin/sentrix/src/main.rs (refactor build_or_reuse_proposal → single point that stamps state_root + recomputes hash before signing)
  • Verify-before-vote on the received-proposal path (re-derive state_root, refuse to prevote on divergence)
  • Full regression test (block.hash == justification.block_hash post-fork)

Activation

Fork-gated off. Activation = halt-all + state-root-alignment pre-flight + simul-start, testnet first, then mainnet at a coordinated height. Requires fresh-brain review + testnet bake before activation.

Summary by CodeRabbit

  • New Features

    • Added validation helpers for block state root analysis and fork height management.
  • Bug Fixes

    • Enforced stricter state root validation for self-produced blocks at/after a designated fork height.
    • Self-produced blocks without state roots are now properly rejected rather than being computed, improving block validation consistency.

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…SIP-5 Bug B, #751)

Adds the block-executor side of SIP-5 (speculative apply at propose so the
block hash commits the post-execution state_root):

- SPECULATIVE_APPLY_HEIGHT fork gate (default u64::MAX, env-activated; SIP-5)
- Blockchain::speculative_apply_for_state_root: computes the state_root a
  candidate block would produce on a throwaway clone, for the proposer to
  stamp at propose time and validators to verify before prevoting
- commit-gate: post-fork a self-produced block with state_root=None is
  rejected instead of stamp+recompute (the Bug B H1->H2 divergence)

Fork-gated off on both nets; inert until a height is set. Propose-side stamp
+ verify-before-vote wiring (main.rs) and the full regression test land
separately. Not for deploy without fresh-brain review + testnet bake.
@satyakwok satyakwok force-pushed the feat/speculative-apply-state-root branch from f650702 to b7b1ef0 Compare June 20, 2026 13:42
@satyakwok satyakwok marked this pull request as ready for review June 21, 2026 02:31
@github-actions github-actions Bot merged commit 457eee1 into main Jun 21, 2026
20 of 21 checks passed
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4c64e55d-009d-48f9-99c3-279fd7a9a9bc

📥 Commits

Reviewing files that changed from the base of the PR and between 90ccab3 and b7b1ef0.

📒 Files selected for processing (3)
  • crates/sentrix-core/src/block_executor.rs
  • crates/sentrix-core/src/blockchain.rs
  • crates/sentrix-fork-heights/src/lib.rs

📝 Walkthrough

Walkthrough

The PR implements SIP-5 / "Bug B" by adding a SPECULATIVE_APPLY_HEIGHT fork gate across three crates. In sentrix-fork-heights, a new compile-time constant SPECULATIVE_APPLY_HEIGHT_DEFAULT (set to u64::MAX, disabled) is added alongside get_speculative_apply_height() and is_speculative_apply_height(height) runtime helpers. Blockchain gains a delegating predicate method is_speculative_apply_height. In block_executor.rs, a new speculative_apply_for_state_root method clones the chain and applies a candidate block to extract the resulting state_root. The apply_block_pass2 state-root path is updated to reject self-produced blocks with state_root=None at or after the fork height with ChainValidationFailed instead of proceeding to the prior stamping behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • sentrix-labs/sentrix#801: Both PRs modify apply_block_pass2 in block_executor.rs in the state_root validation path — this PR adds a rejection rule for state_root=None self-produced blocks post-fork, while #801 changes handling of received_root != computed_root for justified peer blocks.
✨ 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/speculative-apply-state-root

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.

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