Alternative: replace hand-written FullBlock Streamable with Option3<Program, Bytes> - #1463
Closed
richardkiss wants to merge 3 commits into
Closed
Alternative: replace hand-written FullBlock Streamable with Option3<Program, Bytes>#1463richardkiss wants to merge 3 commits into
richardkiss wants to merge 3 commits into
Conversation
…rator is just a buffer
richardkiss
force-pushed
the
option3-fullblock
branch
3 times, most recently
from
June 5, 2026 19:10
6dcb672 to
bc3c268
Compare
Add Option3<V1, V2> to chia-traits: a tri-state optional type with wire encoding 0x00/0x01/0x02. Use it for FullBlock.transactions_generator to cleanly express three states (no generator / v0 Program / v1 raw bytes) without hand-written serialization code. transactions_generator_ref_list changes from Vec<u32> to Option<Vec<u32>>: None signals v1 format (ref_list omitted), Some signals v0 format. This replaces the 145-line hand-written Streamable impl in PR #1456 with a #[streamable] derive and zero hand-written serialization code. The wire format differs by 1-2 bytes per block (negligible for a hard fork protocol change). Co-authored-by: Cursor <cursoragent@cursor.com>
richardkiss
force-pushed
the
option3-fullblock
branch
from
June 5, 2026 19:15
bc3c268 to
7d525c5
Compare
…rator field Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
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
This is an alternative design to #1456, proposed for discussion.
PR #1456 hand-writes 145 lines of
StreamableforFullBlockto bit-pack a version flag into theOptionprefix byte fortransactions_generator. This PR proposesOption3<V1, V2>— a generic tri-state optional type inchia-traits— that letsFullBlockkeep#[streamable]with zero hand-written serialization code.Key Insight
PR #1456 appears to have four states (0b00/0b01/0b10/0b11), but there are really only three meaningful states:
"v0 no generator" and "v1 no generator" are functionally identical at the wire level.
Changes
New type:
Option3<V1, V2>inchia-traitsWire encoding:
None→0x00Some1(V1)→0x01+ V1Some2(V2)→0x02+ V2Backward-compatible with
Option<T>for theNone/Somecases. New nodes are the only ones that ever see0x02, and they're hard-fork nodes.FullBlock fields:
Version detection:
is_v1()↔transactions_generator_ref_list.is_none()Wire Format
Differs from #1456 by +1 byte per block (the
Optionprefix onref_list). For a hard fork protocol change, this overhead is negligible — typical blocks are KB to MB.Trade-offs
Option3usable anywhereTests
10 Rust tests covering v0/v1 roundtrips, prefix byte encoding, and ref_list presence. All passing.
Opened as draft for discussion — would love your thoughts on the 1-byte overhead trade-off vs. eliminating the hand-written impl.
Made with Cursor