Skip to content

[hackathon] enforce non-empty invariant on Extractable and Chain#211

Open
prestwich wants to merge 1 commit intofeat/extractable-metadatafrom
prestwich/eng-2040
Open

[hackathon] enforce non-empty invariant on Extractable and Chain#211
prestwich wants to merge 1 commit intofeat/extractable-metadatafrom
prestwich/eng-2040

Conversation

@prestwich
Copy link
Member

Summary

  • Remove is_empty() from Extractable trait — empty segments are unrepresentable
  • Change first_number() and tip_number() to return u64 instead of Option<u64>
  • Make Chain fields private, remove Default derive, add accessor methods
  • fake_chain(0) now panics to enforce the non-empty invariant at construction

Resolves ENG-2040.

Test plan

  • cargo clippy -p signet-extract --all-features --all-targets — clean
  • cargo clippy -p signet-extract --no-default-features --all-targets — clean
  • cargo clippy -p signet-test-utils --all-features --all-targets — clean
  • cargo clippy -p signet-test-utils --no-default-features --all-targets — clean
  • cargo 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

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>
@prestwich prestwich requested a review from a team as a code owner March 15, 2026 14:30
@prestwich
Copy link
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.

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.

1 participant