Skip to content

refactor(qbft): make MessageType/UponRule enums and remove panic - #685

Merged
iamquang95 merged 4 commits into
mainfrom
feat/fix-637
Sep 4, 2026
Merged

refactor(qbft): make MessageType/UponRule enums and remove panic#685
iamquang95 merged 4 commits into
mainfrom
feat/fix-637

Conversation

@iamquang95

Copy link
Copy Markdown
Collaborator

Fix #637

MessageType and UponRule were i64 newtypes, so no match was exhaustive and the catch-all arms panicked. They are now #[repr(i64)] enums with unchanged discriminants; the MSG_* / UPON_* consts stay as aliases so call sites and the parity suites are untouched.

  • TryFrom<i64> for MessageType accepts 1..=5 and is now the single admission check at the wire boundary.
  • All 11 panic!("bug: …") sites return QbftError::SanityCheck, mirroring charon's qbft sanity check: %v recovery. Payloads match charon byte-for-byte.
  • Both catch_unwind calls removed from internal_test.rs; the 14 .expect() sites are untouched.

The nested-justification panic from the issue was already unreachable from the wire (proto cannot express nesting, constructor flattens, verify_msg type-gates). The gain is that the one wire-reachable sanity failure now surfaces as a typed error with a metric instead of an untyped Error::Join.

@varex83 varex83 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Comment thread crates/core/src/qbft/internal_test.rs Outdated
Comment thread crates/core/src/qbft/mod.rs Outdated
@iamquang95
iamquang95 merged commit d5de3ff into main Sep 4, 2026
15 checks passed
@iamquang95
iamquang95 deleted the feat/fix-637 branch September 4, 2026 03:37
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.

Refactor QBFT constants to enums; return errors instead of panicking

2 participants