Skip to content

fix(consensus): prev hash byron genesis support#1630

Merged
wolf31o2 merged 1 commit intomainfrom
fix/prev-header-improvements
Mar 10, 2026
Merged

fix(consensus): prev hash byron genesis support#1630
wolf31o2 merged 1 commit intomainfrom
fix/prev-header-improvements

Conversation

@wolf31o2
Copy link
Member

@wolf31o2 wolf31o2 commented Mar 10, 2026

This replaces #1623 and enhances #1628's implementation


Summary by cubic

Fixes previous-hash validation and header handling for Byron genesis transitions. Non-genesis blocks now require a previous header hash; genesis transitions may omit it, with consistent mismatch errors.

  • Bug Fixes
    • In consensus/byron, detect genesis via PrevBlockNumber; require PrevHeaderHash only for non-genesis; set prev header fields only when prevHeader != nil in ValidateByronBlockHeader.
    • In consensus, enforce the same rule via BlockNumber and keep a single error message.
    • Tests cover matching, missing, mismatched, and genesis transition cases with exact message checks.

Written for commit bc42598. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Added validation to ensure the previous header hash is required for non-genesis blocks, preventing incomplete block validation.
  • Tests

    • Enhanced test coverage with additional validation scenarios, including explicit handling of missing previous header hash cases and improved error message assertions.

@wolf31o2 wolf31o2 requested a review from a team as a code owner March 10, 2026 13:34
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

The pull request introduces validation logic to require the presence of PrevHeaderHash for non-genesis blocks across the consensus validation code. Changes are made in both the Byron-specific and generic validate modules, with corresponding test cases added to verify the new validation behavior. The validation now returns an explicit error when non-genesis blocks lack a PrevHeaderHash, while genesis blocks remain unaffected. Code formatting adjustments collapse multi-line statements into single-line format without altering functionality.

Possibly related issues

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding validation safeguards for the previous header hash in Byron consensus, with specific handling for genesis blocks.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/prev-header-improvements

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
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Copy link
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@consensus/byron/validate.go`:
- Around line 231-234: The exported Byron header wrappers
(ValidateByronBlockHeader / ValidateByronMainBlockHeader /
ValidateByronEBBHeader) still assume a non-nil prevHeader and unconditionally
call prevHeader.SlotNumber(), prevHeader.BlockNumber(), and prevHeader.Hash(),
preventing genesis/no-prev validation; update these wrappers to accept a nil
prevHeader when input represents genesis (e.g., PrevBlockNumber == 0 or empty
PrevHeaderHash) and short-circuit any reads from prevHeader (skip
slot/number/hash comparisons) so the lower-level validatePrevHash path can
handle the no-prev case; ensure ValidateHeaderInput can carry a nil PrevHeader
and that callers pass nil instead of a dummy header so validatePrevHash and
related checks operate correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f67780cb-1758-422e-b898-75e49b76650f

📥 Commits

Reviewing files that changed from the base of the PR and between b410b00 and b5c12d1.

📒 Files selected for processing (4)
  • consensus/byron/validate.go
  • consensus/byron/validate_test.go
  • consensus/validate.go
  • consensus/validate_test.go

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@wolf31o2 wolf31o2 force-pushed the fix/prev-header-improvements branch from b5c12d1 to bc42598 Compare March 10, 2026 14:18
@wolf31o2 wolf31o2 merged commit a8121f8 into main Mar 10, 2026
12 checks passed
@wolf31o2 wolf31o2 deleted the fix/prev-header-improvements branch March 10, 2026 14:28
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