Mining IPC `createNewBlock` fails with `bad-cb-length` on low-height regtest chains #35126

issue plebhash opened this issue on April 20, 2026
  1. plebhash commented at 9:51 PM on April 20, 2026: none

    I’m not sure whether this is expected after #32420, but I’m seeing Mining.createNewBlock over IPC fail on low-height regtest chains before the IPC client can receive a template and construct its own coinbase.

    Observed behavior

    On Bitcoin Core v31.0, when using the Mining IPC interface on regtest at low block heights, Mining.createNewBlock can throw:

    remote exception: std::exception: TestBlockValidity failed: bad-cb-length, Transaction check failed
    

    In my case this happens with a regtest node after mining one initial block through RPC, so the next template height is 2.

    Potential root cause

    (according to my clanker, @Sjors please sanity check?)

    BlockAssembler::CreateNewBlock() builds an internal coinbase with:

    coinbaseTx.vin[0].scriptSig = CScript() << nHeight;
    

    For heights 1 through 16, the BIP34 height is encoded as a one-byte OP_1 through OP_16. That is below the consensus minimum coinbase scriptSig length of 2 bytes, so TestBlockValidity() rejects the internally assembled block with bad-cb-length.

    RPC mining paths appear to avoid this by setting include_dummy_extranonce = true, but that option does not seem to be exposed in the IPC BlockCreateOptions schema.

    Workaround

    Pre-mine 16 regtest blocks before using the IPC Mining interface. Then the next template height is 17, the BIP34 height encoding is no longer one byte, and createNewBlock succeeds.

  2. plebhash referenced this in commit 5ad03ba765 on Apr 20, 2026
  3. plebhash referenced this in commit ccd0b3cf34 on Apr 20, 2026
  4. ViniciusCestarii commented at 10:27 PM on April 20, 2026: contributor

    Sjors added a comment on [#32420](/github-metadata-backup-bitcoin-bitcoin/32420/) that explicitly acknowledges this regression:

    createNewBlock() now fails at heights <= 16 for IPC clients, which #34860 fixes.

    #34860 hasn't been merged yet.

  5. plebhash referenced this in commit d52c95e099 on Apr 20, 2026
  6. Sjors commented at 9:07 AM on April 22, 2026: member

    I updated the #34860 description to point out that it fixes this issue.

    Your suggested workaround is correct, until then.

  7. plebhash referenced this in commit 92c2a1a2d6 on Apr 24, 2026
  8. plebhash referenced this in commit 493a352959 on Apr 24, 2026
  9. plebhash referenced this in commit e35467a0d6 on Apr 28, 2026
  10. plebhash referenced this in commit d725320c93 on May 1, 2026
  11. ryanofsky closed this on May 17, 2026

  12. pull[bot] referenced this in commit 7802e578c3 on May 17, 2026

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: 2026-05-20 06:52 UTC