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

bitcoind: fix byte order of block hash from getrawblockbyheight#9494
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
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

1 participant