Skip to content

fix(parsers-sv2): keep extension type in TLV frame header - #2433

Open
Christopherdominic wants to merge 2 commits into
stratum-mining:mainfrom
Christopherdominic:fix/2355-tlv-frame-extension-type
Open

Christopherdominic wants to merge 2 commits into
stratum-mining:mainfrom
Christopherdominic:fix/2355-tlv-frame-extension-type

Conversation

@Christopherdominic

Copy link
Copy Markdown
Contributor

Closes #2355

TlvList::build_frame_bytes_with_tlvs wrote the frame header's extension_type from the channel bit alone and ignored message.extension_type(). Any message from a non-zero extension namespace was framed as a core message, so the receiver parsed its payload under the wrong protocol.

The header now combines IsSv2Message::extension_type() with the channel bit in the most significant bit, as the issue suggests.

Changes

  • sv2/parsers-sv2/src/tlv/list.rs: use message.extension_type() | ((message.channel_bit() as u16) << 15) for the header.
  • Regression test that frames an Extensions Negotiation message (extension type 0x0001) and checks the header carries that extension type. It fails on main and passes with this change.

Compatibility

No public API changes, so no companion sv2-apps PR is needed. Core messages are unaffected because their extension_type() is 0.

@Christopherdominic
Christopherdominic force-pushed the fix/2355-tlv-frame-extension-type branch from 0aa7b95 to 735f6af Compare October 28, 2026 15:33
@Christopherdominic

Copy link
Copy Markdown
Contributor Author

@bit-aloo here's the PR for #2355, as discussed on the issue. build_frame_bytes_with_tlvs now carries message.extension_type() in the frame header alongside the channel bit, with a regression test for an extension message. Ready for review whenever you have time.

@Christopherdominic
Christopherdominic force-pushed the fix/2355-tlv-frame-extension-type branch from 735f6af to eab19b1 Compare October 28, 2026 15:37
Comment on lines -107 to 110
let extension_type: u16 = (message.channel_bit() as u16) << 15;
let extension_type = message.extension_type() | ((message.channel_bit() as u16) << 15);
let message_type = message.message_type();

// Serialize the base message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bit 15 is reserved for channel_msg. Could we clear it from
extension_type() before combining it with channel_bit(), matching
update_extension_type?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tACK eab19b1, all 20 tests passed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, done. extension_type() is now masked with 0x7fff before the channel bit is OR-ed in, so the channel_msg flag comes from channel_bit() alone, same as update_extension_type in framing-sv2. Folded into the existing commit.

TlvList::build_frame_bytes_with_tlvs built the header's extension_type
from the channel bit alone, so a message from a non-zero extension
namespace was framed as a core message and the receiver parsed its
payload under the wrong protocol.

The header now combines IsSv2Message::extension_type() with the channel
bit in the most significant bit. Bit 15 is cleared from
extension_type() first, so the channel_msg flag comes from
channel_bit() alone, matching framing-sv2's update_extension_type.

Closes stratum-mining#2355
@Christopherdominic
Christopherdominic force-pushed the fix/2355-tlv-frame-extension-type branch from eab19b1 to d1a9dd0 Compare October 28, 2026 21:47
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.

build_frame_bytes_with_tlvs frames every message as extension type 0

2 participants