[hackathon] enforce non-empty invariant on Extractable and Chain#211
Open
prestwich wants to merge 1 commit intofeat/extractable-metadatafrom
Open
[hackathon] enforce non-empty invariant on Extractable and Chain#211prestwich wants to merge 1 commit intofeat/extractable-metadatafrom
prestwich wants to merge 1 commit intofeat/extractable-metadatafrom
Conversation
Remove `is_empty()` from `Extractable` trait, change `first_number()` and `tip_number()` to return `u64` instead of `Option<u64>`, and document the non-empty guarantee on `blocks_and_receipts()`. Make `Chain` fields private, remove `Default` derive, and panic in `fake_chain(0)` to enforce the invariant at construction time. Resolves ENG-2040. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
|
[Claude Code] Note: This is titled as a hackathon PR, but is likely valuable work regardless — enforcing the non-empty invariant removes a class of impossible states from the API. |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_empty()fromExtractabletrait — empty segments are unrepresentablefirst_number()andtip_number()to returnu64instead ofOption<u64>Chainfields private, removeDefaultderive, add accessor methodsfake_chain(0)now panics to enforce the non-empty invariant at constructionResolves ENG-2040.
Test plan
cargo clippy -p signet-extract --all-features --all-targets— cleancargo clippy -p signet-extract --no-default-features --all-targets— cleancargo clippy -p signet-test-utils --all-features --all-targets— cleancargo clippy -p signet-test-utils --no-default-features --all-targets— cleancargo t -p signet-test-utils— all 3 chain tests pass (including#[should_panic]for zero)cargo t -p signet-extract— doc test passes🤖 Generated with Claude Code