Skip to content

refactor(framing): replace Sv2Frame dual-Option fields with FrameBody enum#2128

Open
ThomsenDrake wants to merge 1 commit intostratum-mining:mainfrom
ThomsenDrake:refactor-sv2frame-enum-fix-2111-2112-2113
Open

refactor(framing): replace Sv2Frame dual-Option fields with FrameBody enum#2128
ThomsenDrake wants to merge 1 commit intostratum-mining:mainfrom
ThomsenDrake:refactor-sv2frame-enum-fix-2111-2112-2113

Conversation

@ThomsenDrake
Copy link
Copy Markdown

Fixes #2111, #2112, #2113

Summary

Replaces Sv2Frame<T, B>'s dual Option<T> + Option<B> fields with a type-safe FrameBody<T, B> enum (Payload(T) | Serialized(B)). This makes the invariant that exactly one of payload/serialized is present impossible to violate by construction, eliminating 3 panic!("Impossible state") branches.

Changes

Core refactor (fixes #2111)

  • Added FrameBody<T, B> enum with Payload(T) and Serialized(B) variants
  • Sv2Frame<T, B> now uses a single body: FrameBody<T, B> field
  • serialize(), encoded_length() are now exhaustive matches (no panic branches)
  • map() updated to match on body variants

API soundness (fixes #2112)

  • Sv2Frame::get_header() now returns Header directly (was Option<Header> — always returned Some)
  • Updated all call sites (codec-sv2 decoder tests, examples)

API soundness (fixes #2113)

  • HandShakeFrame::from_bytes() now returns Self directly (was Result<Self, isize> — always returned Ok)

Testing

All 9 tests pass:

  • framing-sv2: 3/3 (default)
  • codec-sv2: 6/6 (default + with_buffer_pool features)

… enum (fixes stratum-mining#2111)

Eliminates the dual-Option pattern (payload + serialized) in Sv2Frame by
introducing a type-safe FrameBody enum (Payload(T) | Serialized(B)).
This removes 3 'Impossible state' panic branches from serialize(),
encoded_length(), and makes the internal state impossible by construction.

Also fixes stratum-mining#2112: get_header() now returns Header directly (always present).
Fixes stratum-mining#2113: HandShakeFrame::from_bytes() now returns Self directly
(always succeeded, Result was unnecessary).

All 9 tests pass (3 framing + 6 codec, default + with_buffer_pool).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant