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.