Skip to content

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

Closed

Description

@plebhash

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.

Activity

  1. ViniciusCestarii commented on Apr 20, 2026

    @ViniciusCestarii
    Contributor

    Sjors added a comment on #32420 that explicitly acknowledges this regression:

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

    #34860 hasn't been merged yet.

  2. Sjors commented on Apr 22, 2026

    @Sjors
    Member

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

    Your suggested workaround is correct, until then.

  3. added a commit that references this issue on May 17, 2026
    788f390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions