Skip to content

Add parent hash verification during block ingestion#954

Merged
zhangchiqing merged 3 commits intomainfrom
leo/validate-block-with-parent-hash
Feb 17, 2026
Merged

Add parent hash verification during block ingestion#954
zhangchiqing merged 3 commits intomainfrom
leo/validate-block-with-parent-hash

Conversation

@zhangchiqing
Copy link
Copy Markdown
Member

@zhangchiqing zhangchiqing commented Feb 12, 2026

Verify that each new block's parent hash matches the hash of the previous block when syncing from the access node. This ensures blockchain integrity by rejecting blocks with mismatched parent hashes.

Closes: #???

Description


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Block ingestion system now includes comprehensive parent hash validation to ensure all newly received blocks maintain proper sequential linkage with their previously processed blocks.
  • Bug Fixes

    • Improved error detection, validation, and reporting for blocks with invalid or mismatched parent hashes, providing specific error messages to help diagnose blockchain synchronization and consistency issues.

  Verify that each new block's parent hash matches the hash of the
  previous block when syncing from the access node. This ensures
  blockchain integrity by rejecting blocks with mismatched parent hashes.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

This change introduces parent block hash validation to the block ingestion pipeline. A new error type is defined, BlocksProvider validates incoming blocks reference the correct parent hash, and test infrastructure is expanded to support parent-linked block chains.

Changes

Cohort / File(s) Summary
Error Definitions
models/errors/errors.go
Added new exported error variable ErrInvalidParentHash for invalid parent block hash failures.
Replayer Implementation
services/replayer/blocks_provider.go
Added parent hash validation in OnBlockReceived that ensures incoming blocks reference the latest block's hash, returning an error on mismatch.
Block Testing Infrastructure
services/ingestion/engine_test.go, storage/mocks/mocks.go
Added helper functions newBlockWithParent and NewBlockWithParent to support creating parent-linked blocks for sequential chain testing.
Replayer Tests
services/replayer/blocks_provider_test.go
Refactored test coverage to validate parent hash linkage; renamed existing test, added cases for valid three-block chain and invalid parent hash detection with error assertion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Bugfix, EVM

Suggested reviewers

  • peterargue
  • janezpodhostnik

Poem

🐰 A bunny hops through blocks so grand,
Each parent hash now held in hand!
Chain linkage verified with care,
Invalid parents caught mid-air!

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (9 files):

⚔️ go.mod (content)
⚔️ go.sum (content)
⚔️ models/errors/errors.go (content)
⚔️ services/ingestion/engine_test.go (content)
⚔️ services/replayer/blocks_provider.go (content)
⚔️ services/replayer/blocks_provider_test.go (content)
⚔️ storage/mocks/mocks.go (content)
⚔️ tests/go.mod (content)
⚔️ tests/go.sum (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ 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 'Add parent hash verification during block ingestion' directly summarizes the main change: implementing validation that a block's parent hash matches the previous block's hash during ingestion.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch leo/validate-block-with-parent-hash
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch leo/validate-block-with-parent-hash
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
storage/mocks/mocks.go (1)

39-58: Silently discarded error from parent.Hash() may hide test failures.

On line 42, the error from parent.Hash() is silently discarded. If hash computation ever fails, the block will get a zero parent hash, causing confusing downstream test failures instead of a clear error. Consider returning an error or using t testing.TB to fail fast, similar to how newBlockWithParent in engine_test.go propagates the error.


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
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

Nice addition! 👏

@zhangchiqing zhangchiqing merged commit 8db2bd2 into main Feb 17, 2026
2 checks passed
@zhangchiqing zhangchiqing deleted the leo/validate-block-with-parent-hash branch February 17, 2026 16:10
@github-project-automation github-project-automation bot moved this from 👀 In Review to ✅ Done in 🌊 Flow 4D Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants