Skip to content

fix(blocks): validate all beacon entries for all covered epochs on quicknet - #7441

Open
EclesioMeloJunior wants to merge 14 commits into
mainfrom
eclesio/validate-block-drand
Open

fix(blocks): validate all beacon entries for all covered epochs on quicknet #7441
EclesioMeloJunior wants to merge 14 commits into
mainfrom
eclesio/validate-block-drand

Conversation

@EclesioMeloJunior

@EclesioMeloJunior EclesioMeloJunior commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary of changes

This PR fixes the RawBlockHeader::validate_block_drand method by checking correctly, for quicknet, if the current block header contains the beacon entries from parent_epoch + 1 till self.epoch, meaning that a block built after N null-epoch should have a beacon entry per skipped epoch

Changes introduced in this pull request:

  • src/blocks/header.rs: validate_block_drand now checks, for unchained beacons only, that the header carries exactly epoch - parent_epoch entries and that entry i is at max_beacon_round_for_epoch(parent_epoch + i + 1)

Reference issue to close (if applicable)

Closes #7413

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Quicknet block validation to require complete beacon coverage for every epoch between the parent and new block.
    • Beacon entries must appear in ascending epoch order and match each epoch’s maximum beacon round.
    • Blocks with missing, extra, incorrectly ordered, or mismatched beacon entries are now rejected with clear validation errors.
    • Validation now correctly handles epochs with null beacon rounds, improving reliability for affected blocks.

@EclesioMeloJunior
EclesioMeloJunior requested a review from a team as a code owner August 4, 2026 18:57
@EclesioMeloJunior
EclesioMeloJunior requested review from LesnyRumcajs and akaladarshi and removed request for a team August 4, 2026 18:58
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Quicknet unchained beacon validation now requires one ascending entry per epoch between the parent and block epochs. Each entry must use that epoch’s maximum beacon round. Public test helpers and coverage for contiguous and null-round epochs were added.

Changes

Quicknet beacon validation

Layer / File(s) Summary
Unchained beacon coverage validation
src/blocks/header.rs, src/beacon/mod.rs, src/beacon/tests/drand.rs, CHANGELOG.md
Validation rejects excessive, missing, unordered, or incorrectly matched beacon entries. Public Quicknet test helpers support contiguous and null-round validation tests. The changelog records the stricter validation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • ChainSafe/forest#7427: Both changes enforce correctly matched Quicknet beacon entries for every covered epoch.

Suggested reviewers: akaladarshi, lesnyrumcajs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: stricter validation of all Quicknet beacon entries across covered epochs.
Linked Issues check ✅ Passed The changes satisfy issue [#7413] by enforcing exact entry counts, per-epoch rounds, ordering, and coverage with tests.
Out of Scope Changes check ✅ Passed The changelog and public test helpers directly support the validation fix and its tests; no unrelated code changes are evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 eclesio/validate-block-drand
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch eclesio/validate-block-drand

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.

@EclesioMeloJunior EclesioMeloJunior changed the title Eclesio/validate block drand fix(blocks): validate all beacon entries for all covered epochs on quicknet Aug 4, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Line 44: Update the changelog entry for Quicknet block validation to reference
issue `#7413` instead of `#7412`, including the corresponding issue URL, while
preserving the existing description.

In `@src/blocks/header.rs`:
- Around line 188-223: Update src/beacon/drand.rs in
BeaconSchedule::beacon_entries_for_block to generate one unchained beacon entry
for every epoch in parent_epoch + 1..=epoch, matching the validator’s expected
count and rounds. In src/blocks/header.rs:188-223, retain validation against
that full range; in src/blocks/header.rs:481-517, construct the null-epoch
header using BeaconSchedule::beacon_entries_for_block so the test exercises the
producer-validator contract.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a9cb33ea-85fe-4045-b24e-403c651a75fd

📥 Commits

Reviewing files that changed from the base of the PR and between a379991 and ca53281.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/beacon/mod.rs
  • src/beacon/tests/drand.rs
  • src/blocks/header.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread CHANGELOG.md Outdated
Comment thread src/blocks/header.rs
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.12%. Comparing base (a188092) to head (c3dbe8b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
Files with missing lines Coverage Δ
src/blocks/header.rs 71.25% <100.00%> (+5.43%) ⬆️

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a188092...c3dbe8b. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/blocks/header.rs
Comment thread src/blocks/header.rs Outdated
Comment thread src/blocks/header.rs
Comment thread src/blocks/header.rs Outdated
@LesnyRumcajs

Copy link
Copy Markdown
Member

nit: there are some partially covered lines in the coverage you might want to cover (they're fairly trivial to reason about, so not a huge deal).

I'll approve once CI is green.

Comment thread src/blocks/header.rs Outdated
Comment thread src/blocks/header.rs Outdated
Comment thread src/blocks/header.rs
Comment thread src/blocks/header.rs Outdated
Comment thread src/blocks/header.rs Outdated
Comment thread src/blocks/header.rs
LesnyRumcajs
LesnyRumcajs previously approved these changes Aug 6, 2026

@LesnyRumcajs LesnyRumcajs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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.

validate_block_drand skips per-epoch round checks for unchained beacons

2 participants