From 6d4b1458cfc9ffa220c4f8b51d38fcdfb9b27a5f Mon Sep 17 00:00:00 2001 From: Andezion <245122@edu.p.lodz.pl> Date: Thu, 10 Sep 2026 22:22:58 +0200 Subject: [PATCH] bitcoind: fix byte order of block hash from getrawblockbyheight Changelog-None --- lightningd/bitcoind.c | 2 +- tests/test_db.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index c1f461f7f25e..8872a4295e58 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -446,7 +446,7 @@ getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks, } err = json_scan(tmpctx, buf, resulttok, "{blockhash:%,block:%}", - JSON_SCAN(json_to_sha256, &blkid.shad.sha), + JSON_SCAN(json_to_bitcoin_blkid, &blkid), JSON_SCAN_TAL(tmpctx, json_strdup, &block_str)); if (err) bitcoin_plugin_error(call->bitcoind, buf, resulttok, diff --git a/tests/test_db.py b/tests/test_db.py index be2300a11ff0..d5ad4e1a5cfe 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -87,6 +87,9 @@ def test_block_backfill(node_factory, bitcoind, chainparams): heights = [r['height'] for r in l3.db_query("SELECT height FROM blocks")] assert(103 in heights) + stored_hash = only_one(l3.db_query("SELECT hash FROM blocks WHERE height = 103"))['hash'] + assert bytes(stored_hash) == bytes.fromhex(bitcoind.rpc.getblockhash(103))[::-1] + # Make sure we also have the needle we added to the haystack above assert(31337 in [r['satoshis'] for r in l3.db_query("SELECT satoshis FROM utxoset")])