RPC: getblock(header) returns the same target for every block #33440

issue gmart7t2 openend this issue on September 20, 2025
  1. gmart7t2 commented at 0:29 am on September 20, 2025: none

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    Run getblock or getblockheader for block 1 and you get the same “target” reported as for block 900000

    Expected behaviour

    I would expect the target to be different for different blocks

    Steps to reproduce

    Run getblock or getblockheader for block 1 and you get the same “target” reported as for block 900000

    Relevant log output

    No response

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    v29.0

    Operating system and version

    Debian Linux

    Machine specifications

    No response

  2. pinheadmz commented at 0:40 am on September 20, 2025: member

    Hm yeah…

    0pi@zippi:~ $ bitcoin-cli getblockheader `bitcoin-cli getblockhash 1` | jq .target
    1"00000000000000000001fa380000000000000000000000000000000000000000"
    2pi@zippi:~ $ bitcoin-cli getblockheader `bitcoin-cli getblockhash 100` | jq .target
    3"00000000000000000001fa380000000000000000000000000000000000000000"
    4pi@zippi:~ $ bitcoin-cli getblockheader `bitcoin-cli getblockhash 200000` | jq .target
    5"00000000000000000001fa380000000000000000000000000000000000000000"
    6pi@zippi:~ $ bitcoin-cli getblockheader `bitcoin-cli getblockhash 900000` | jq .target
    7"00000000000000000001fa380000000000000000000000000000000000000000"
    
  3. pinheadmz commented at 0:43 am on September 20, 2025: member
    I believe it’s always showing the current difficulty target for the next block
  4. gmart7t2 commented at 1:15 am on September 20, 2025: none

    Yes. It’s the same as reported by getblockchaininfo:

    0$ bitcoin-cli getblockchaininfo | jq .target
    1"00000000000000000001fa380000000000000000000000000000000000000000"
    
  5. pinheadmz commented at 1:36 am on September 20, 2025: member

    This is expected, see #31583 and https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-29.0.md#updated-rpcs

    getblock and getblockheader now return the current target in the target field (#31583)

  6. gmart7t2 commented at 4:25 am on September 20, 2025: none

    That looks like a release note error to me. Why would we want to know the current target when looking up information about an old block?

    The help text for the RPC calls says that it returns the difficulty target and difficulty of blockheader <hash>:

    Image

    It makes no sense to return the target for a different block’s difficulty. It means that the block header information returned for old blocks changes over time as the current difficulty changes.

  7. gmart7t2 commented at 4:38 am on September 20, 2025: none

    This tiny change changes both RPCs to return the target for the block of interest rather than the current target:

     0diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
     1index 8cbca51ccb..edda17d369 100644
     2--- a/src/rpc/blockchain.cpp
     3+++ b/src/rpc/blockchain.cpp
     4@@ -164,7 +164,7 @@ UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex
     5     result.pushKV("mediantime", blockindex.GetMedianTimePast());
     6     result.pushKV("nonce", blockindex.nNonce);
     7     result.pushKV("bits", strprintf("%08x", blockindex.nBits));
     8-    result.pushKV("target", GetTarget(tip, pow_limit).GetHex());
     9+    result.pushKV("target", GetTarget(blockindex, pow_limit).GetHex());
    10     result.pushKV("difficulty", GetDifficulty(blockindex));
    11     result.pushKV("chainwork", blockindex.nChainWork.GetHex());
    12     result.pushKV("nTx", blockindex.nTx);
    
  8. pinheadmz commented at 10:24 am on September 20, 2025: member

    Why would we want to know the current target when looking up information about an old block? @Sjors

  9. Sjors commented at 3:41 pm on September 20, 2025: member

    This is indeed a bug. The other commits in that PR use the tip, but that’s incorrect for these two RPC methods. See https://github.com/bitcoin/bitcoin/pull/31583/commits/2a7bfebd5e788e1d9e7e07a9f1b8e3625a0301cd#r2365643082

    I’ll PR a fix shortly, still working on adding test coverage.

  10. Sjors referenced this in commit 88fb025c83 on Sep 20, 2025
  11. Sjors commented at 4:53 pm on September 20, 2025: member
    #33446 fixes this
  12. fanquake closed this on Sep 24, 2025

  13. fanquake referenced this in commit d41b503ae1 on Sep 24, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-09-26 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me