mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-18 05:13:21 +01:00
[miner] omit dummy extraNonce via IPC
Previously the coinbase transaction generated by our miner code was not used downstream, because the getblocktemplate RPC excludes it. Since the Mining IPC interface was introduced in #30200 we do expose this dummy coinbase transaction. In Stratum v2 several parts of it are communicated downstream, including the scriptSig. This commit removes the dummy extraNonce from the coinbase scriptSig in block templates requested via IPC. This limits the scriptSig to what is essential for consensus (BIP34) and removes the need for external mining software to remove the dummy, or even ignore the scriptSig we provide and generate it some other way. This could cause problems if a future soft fork requires additional data to be committed here. A test is added to verify the new IPC behavior. It achieves this by introducing an include_dummy_extranonce option which defaults to false with all test code updated to set it to true. Because this option is not exposed via IPC, callers will no longer see it. The caller needs to ensure that for blocks 1 through 16 they pad the scriptSig in order to avoid bad-cb-length. Co-authored-by: Anthony Towns <aj@erisian.com.au>
This commit is contained in:
@@ -177,11 +177,17 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
|
||||
coinbase_tx.block_reward_remaining = block_reward;
|
||||
|
||||
// Start the coinbase scriptSig with the block height as required by BIP34.
|
||||
// The trailing OP_0 (historically an extranonce) is optional padding and
|
||||
// could be removed without a consensus change. Mining clients are expected
|
||||
// to append extra data to this prefix, so increasing its length would reduce
|
||||
// the space they can use and may break existing clients.
|
||||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
// Mining clients are expected to append extra data to this prefix, so
|
||||
// increasing its length would reduce the space they can use and may break
|
||||
// existing clients.
|
||||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight;
|
||||
if (m_options.include_dummy_extranonce) {
|
||||
// For blocks at heights <= 16, the BIP34-encoded height alone is only
|
||||
// one byte. Consensus requires coinbase scriptSigs to be at least two
|
||||
// bytes long (bad-cb-length), so tests and regtest include a dummy
|
||||
// extraNonce (OP_0)
|
||||
coinbaseTx.vin[0].scriptSig << OP_0;
|
||||
}
|
||||
coinbase_tx.script_sig_prefix = coinbaseTx.vin[0].scriptSig;
|
||||
Assert(nHeight > 0);
|
||||
coinbaseTx.nLockTime = static_cast<uint32_t>(nHeight - 1);
|
||||
@@ -212,6 +218,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
|
||||
pblock->nNonce = 0;
|
||||
|
||||
if (m_options.test_block_validity) {
|
||||
// if nHeight <= 16, and include_dummy_extranonce=false this will fail due to bad-cb-length.
|
||||
if (BlockValidationState state{TestBlockValidity(m_chainstate, *pblock, /*check_pow=*/false, /*check_merkle_root=*/false)}; !state.IsValid()) {
|
||||
throw std::runtime_error(strprintf("TestBlockValidity failed: %s", state.ToString()));
|
||||
}
|
||||
|
||||
@@ -67,6 +67,10 @@ struct BlockCreateOptions {
|
||||
* coinbase_max_additional_weight and coinbase_output_max_additional_sigops.
|
||||
*/
|
||||
CScript coinbase_output_script{CScript() << OP_TRUE};
|
||||
/**
|
||||
* Whether to include an OP_0 as a dummy extraNonce in the template's coinbase
|
||||
*/
|
||||
bool include_dummy_extranonce{false};
|
||||
};
|
||||
|
||||
struct BlockWaitOptions {
|
||||
|
||||
Reference in New Issue
Block a user