-
Notifications
You must be signed in to change notification settings - Fork 182
fix: drand verification failure on duplicate entries #6101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughUpdates CHANGELOG.md with a fix note. Modifies DrandBeacon::verify_entries (unchained path) to deduplicate by round using unique_by(|e| e.round()), processing each beacon round once. Chained path unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller as Caller
participant Drand as DrandBeacon
participant Entries as Entries (unchained)
Caller->>Drand: verify_entries(entries, unchained)
Note over Drand: Deduplicate entries by round
Drand->>Entries: iterate unique_by(round)
loop For each unique round
Drand->>Drand: verify entry (signature/round linkage)
alt verification fails
Drand-->>Caller: return Err
else verification succeeds
Note right of Drand: proceed to next unique round
end
end
Drand-->>Caller: Ok
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
174c29d to
2da7019
Compare
2da7019 to
5c7a88b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
CHANGELOG.md (1)
42-43: Clarify scope and casing of “Drand”; tighten phrasing.Make it explicit this affects unchained Drand (Quicknet) beacons typically used by new devnets, and use consistent “Drand” casing.
Apply this diff:
-- [#5055](https://github.com/ChainSafe/forest/issues/5055) Fixed an issue where Forest fails on duplicate drand entries. This would only happen on new devnets. +- [#5055](https://github.com/ChainSafe/forest/issues/5055) Fixed a failure on duplicate Drand entries for unchained beacons (Quicknet), typically affecting new devnets.src/beacon/drand.rs (1)
292-301: Good fix: deduping unchained rounds prevents batch-verify pitfalls on duplicates.This addresses the duplicate-rounds failure. Optional micro-optimization: since entries are documented as “sorted by round,” you can avoid a HashSet allocation in
unique_byand skip contiguous dups in O(1) extra space.Apply this diff:
- // Deduplicate by round. See Lotus issue: https://github.com/filecoin-project/lotus/issues/13349 - for entry in entries.iter().unique_by(|e| e.round()) { - if self.is_verified(entry) { - continue; - } - - messages.push(BeaconEntry::message_unchained(entry.round())); - signatures.push(SignatureOnG1::from_bytes(entry.signature())?); - validated.push(entry); - } + // Deduplicate contiguous duplicates (entries are sorted by round). + let mut last_round: Option<u64> = None; + for entry in entries { + let r = entry.round(); + if last_round == Some(r) || self.is_verified(entry) { + continue; + } + last_round = Some(r); + + messages.push(BeaconEntry::message_unchained(r)); + signatures.push(SignatureOnG1::from_bytes(entry.signature())?); + validated.push(entry); + }If you prefer to retain
unique_byfor non-contiguous dups, consider a quick early return whenmessages.is_empty()to skip a no-opverify_batch. I can also add a unit test that feeds duplicated unchained entries and assertsverify_entriesreturns true and caches once—say,drand::tests::verify_entries_unchained_dedups_duplicates. Want me to draft it?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.md(1 hunks)src/beacon/drand.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: LesnyRumcajs
PR: ChainSafe/forest#5907
File: src/rpc/methods/state.rs:523-570
Timestamp: 2025-08-06T15:44:33.467Z
Learning: LesnyRumcajs prefers to rely on BufWriter's Drop implementation for automatic flushing rather than explicit flush() calls in Forest codebase.
🧬 Code graph analysis (1)
src/beacon/drand.rs (1)
src/beacon/mock_beacon.rs (1)
entry(46-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: tests-release
- GitHub Check: tests
- GitHub Check: Build forest binaries on Linux AMD64
- GitHub Check: cargo-publish-dry-run
- GitHub Check: Build MacOS
- GitHub Check: Build Ubuntu
- GitHub Check: All lint checks
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #5055
Other information and links
Change checklist
Summary by CodeRabbit
Bug Fixes
Documentation