Skip to content

bitcoind: fix byte order of block hash from getrawblockbyheight - #9494

Open
Andezion wants to merge 1 commit into
ElementsProject:masterfrom
Andezion:fix/blockhash-endianness-9465
Open

Andezion wants to merge 1 commit into
ElementsProject:masterfrom
Andezion:fix/blockhash-endianness-9465

Conversation

@Andezion

Copy link
Copy Markdown
Collaborator

Fixes #9465

Summary

getrawblockbyheight_callback() parsed the plugin s blockhash field with json_to_sha256(), which hex-decodes without reversing bytes. Every other block hash / txid parser in the codebase (like bitcoin_blkid_from_hex, bitcoin_txid_from_hex, json_to_bitcoin_blkid) reverses the bytes after decoding, since bitcoind displays hashes in rpc/json in the opposite byte order to the internal representation used for hashing and db storage

Most callers of bitcoind_getrawblockbyheight() ignore the parsed blkid and recompute it from the block header instead, so they were unaffected. But process_getfilteredblock_step1() (used for on-demand gossip block backfill) trusts the parsed value directly, and wallet_filteredblock_add() writes it straight into blocks.hash - producing rows with inconsistent endianness relative to rows written by normal chain-tip sync

Fix

Parse blockhash with json_to_bitcoin_blkid() instead, matching every other blkid parser in the codebase

Changelog-None

Important

26.09 FREEZE August 5th: Non-bugfix PRs not ready by this date will wait for 26.12.

RC1 is scheduled on August 17th

The final release is scheduled for September 7th.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

@Andezion Andezion self-assigned this Sep 10, 2026
@Andezion Andezion added the Status::Ready for Review The work has been completed and is now awaiting evaluation or approval. label Sep 10, 2026
@Andezion
Andezion force-pushed the fix/blockhash-endianness-9465 branch from 6d4b145 to 4b01482 Compare October 26, 2026 13:29
@Andezion
Andezion force-pushed the fix/blockhash-endianness-9465 branch 2 times, most recently from 78b9750 to d227f75 Compare November 3, 2026 13:48
@sangbida
sangbida force-pushed the fix/blockhash-endianness-9465 branch from d227f75 to deafa2e Compare November 23, 2026 07:13

@sangbida sangbida 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.

The change is good but I think it needs a changelog!

@Andezion
Andezion force-pushed the fix/blockhash-endianness-9465 branch from deafa2e to 3a8846e Compare November 23, 2026 19:12

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status::Ready for Review The work has been completed and is now awaiting evaluation or approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Endianness of Blocks Table Hash Column inconsistent

2 participants