Skip to content

Fix native protocol reorganized handler: extract header_t not height_t#784

Merged
evoskuil merged 2 commits into
libbitcoin:masterfrom
echennells:native-reorganized-header-t-fix
Jun 9, 2026
Merged

Fix native protocol reorganized handler: extract header_t not height_t#784
evoskuil merged 2 commits into
libbitcoin:masterfrom
echennells:native-reorganized-header-t-fix

Conversation

@echennells

Copy link
Copy Markdown
Contributor

Fixes #783

protocol_native::handle_chase's reorganized case extracted the event payload as node::height_t, but chaser_confirm::set_reorganized posts a header_link (node::header_t), as documented in chase.hpp and as the sibling organized case and do_top(node::header_t) already assume.

node::header_t (header_link::integer = uint32_t) and node::height_t (size_t) are distinct alternatives of the event_value variant, so std::getnode::height_t on a header_t-holding variant throws std::bad_variant_access. handle_chase is NOEXCEPT, so the throw becomes std::terminate: any chain reorganization while a client holds a native top subscription crashes the node.

Extract node::header_t instead, matching the emitter, the chase.hpp doc comment, the organized sibling, and do_top's signature.

Adds two regression tests to test/protocols/native/native_block.cpp:

  • a non-throwing get_if guard that the reorganized payload is header_t;
  • a behavioral test driving the reorganized event through the running server (mirrors native__ws_top_subscribe__progressive_notify__expected). Pre-fix the behavioral case aborts via bad_variant_access; post-fix it passes, so the fix and test land in the same commit.

protocol_native::handle_chase's `reorganized` case extracted the event
payload as node::height_t, but chaser_confirm::set_reorganized posts a
header_link (node::header_t), as documented in chase.hpp and as the
sibling `organized` case and do_top(node::header_t) already assume.

node::header_t (header_link::integer = uint32_t) and node::height_t
(size_t) are distinct alternatives of the event_value variant, so
std::get<node::height_t> on a header_t-holding variant throws
std::bad_variant_access. handle_chase is NOEXCEPT, so the throw becomes
std::terminate: any chain reorganization while a client holds a native
`top` subscription crashes the node.

Extract node::header_t instead, matching the emitter, the chase.hpp doc
comment, the organized sibling, and do_top's signature.

Adds two regression tests to test/protocols/native/native_block.cpp:
- a non-throwing get_if guard that the reorganized payload is header_t;
- a behavioral test driving the reorganized event through the running
  server (mirrors native__ws_top_subscribe__progressive_notify__expected).
  Pre-fix the behavioral case aborts via bad_variant_access; post-fix it
  passes, so the fix and test land in the same commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@evoskuil evoskuil self-assigned this Jun 7, 2026
@evoskuil evoskuil added the bug label Jun 7, 2026
Comment thread test/protocols/native/native_block.cpp Outdated
Comment thread test/protocols/native/native_block.cpp Outdated
@evoskuil evoskuil merged commit b8d5740 into libbitcoin:master Jun 9, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native handle_chase reads chase::reorganized as height_t instead of header_t, crashing the node (std::terminate) on reorg with a top subscriber

2 participants