mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-09 02:59:31 +08:00
Merge bitcoin/bitcoin#32420: mining, ipc: omit dummy extraNonce from coinbase
d511adb664[miner] omit dummy extraNonce via IPC (Sjors Provoost)bf3b5d6d06test: clarify getCoinbaseRawTx() comparison (Sjors Provoost)78df9003d6[doc] Update comments on dummy extraNonces in tests (Anthony Towns) Pull request description: This PR changes the Mining IPC interface to stop including a dummy `extraNonce` in the coinbase `scriptSig` by default, exposing only the consensus-required BIP34 height. This simplifies downstream mining software (including Stratum v2), avoids forcing clients to strip or ignore data we generate, and reduces the risk of incompatibilities if future soft forks add required commitments to the `scriptSig`. Existing behavior is preserved for RPCs, tests, regtest, and internal mining by explicitly opting in to the dummy `extraNonce` where needed (e.g. to satisfy `bad-cb-length` at low heights), so consensus rules and test coverage are unchanged. The remainder of the PR consists of small comment fixes, naming clarifications, and test cleanups to make the intent and behavior clearer. ACKs for top commit: achow101: ACKd511adb664ryanofsky: Code review ACKd511adb664. Just rebased since last review and make suggested tweaks. I'd really like to see this PR merged for the cleanups and sanity it brings to this code. Needs another reviewer though. sedited: ACKd511adb664Tree-SHA512: d41fa813eb6b5626f4f475d8abc506b29090f4a2d218f2d6824db58b5ebe2ed7c584a903b44de18ccec142bb79c257b0aba6d6da073f56175aec88df96aaaaba
This commit is contained in:
@@ -20,10 +20,14 @@ from test_framework.messages import (
|
||||
ser_uint256,
|
||||
COIN,
|
||||
)
|
||||
from test_framework.script import (
|
||||
CScript,
|
||||
CScriptNum,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_not_equal
|
||||
assert_not_equal,
|
||||
)
|
||||
from test_framework.wallet import MiniWallet
|
||||
from typing import Optional
|
||||
@@ -144,7 +148,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
|
||||
block.deserialize(block_data)
|
||||
return block
|
||||
|
||||
async def parse_and_deserialize_coinbase_tx(self, block_template, ctx):
|
||||
async def get_coinbase_raw_tx(self, block_template, ctx):
|
||||
assert block_template is not None
|
||||
coinbase_data = BytesIO((await block_template.getCoinbaseRawTx(ctx)).result)
|
||||
tx = CTransaction()
|
||||
@@ -194,6 +198,12 @@ class IPCInterfaceTest(BitcoinTestFramework):
|
||||
coinbase_tx.vin = [CTxIn()]
|
||||
coinbase_tx.vin[0].prevout = NULL_OUTPOINT
|
||||
coinbase_tx.vin[0].nSequence = coinbase_res.sequence
|
||||
|
||||
# Verify there's no dummy extraNonce in the coinbase scriptSig
|
||||
current_block_height = self.nodes[0].getchaintips()[0]["height"]
|
||||
expected_scriptsig = CScript([CScriptNum(current_block_height + 1)])
|
||||
assert_equal(coinbase_res.scriptSigPrefix.hex(), expected_scriptsig.hex())
|
||||
|
||||
# Typically a mining pool appends its name and an extraNonce
|
||||
coinbase_tx.vin[0].scriptSig = coinbase_res.scriptSigPrefix
|
||||
|
||||
@@ -224,8 +234,9 @@ class IPCInterfaceTest(BitcoinTestFramework):
|
||||
|
||||
coinbase_tx.nLockTime = coinbase_res.lockTime
|
||||
|
||||
# Compare to dummy coinbase provided by the deprecated getCoinbaseTx()
|
||||
coinbase_legacy = await self.parse_and_deserialize_coinbase_tx(template, ctx)
|
||||
# Compare to dummy coinbase transaction provided by the deprecated
|
||||
# getCoinbaseRawTx()
|
||||
coinbase_legacy = await self.get_coinbase_raw_tx(template, ctx)
|
||||
assert_equal(coinbase_legacy.vout[0].nValue, coinbase_res.blockRewardRemaining)
|
||||
# Swap dummy output for our own
|
||||
coinbase_legacy.vout[0].scriptPubKey = coinbase_tx.vout[0].scriptPubKey
|
||||
@@ -282,10 +293,6 @@ class IPCInterfaceTest(BitcoinTestFramework):
|
||||
assert_equal(len(txfees.result), 0)
|
||||
txsigops = await template.getTxSigops(ctx)
|
||||
assert_equal(len(txsigops.result), 0)
|
||||
coinbase_data = BytesIO((await template.getCoinbaseRawTx(ctx)).result)
|
||||
coinbase = CTransaction()
|
||||
coinbase.deserialize(coinbase_data)
|
||||
assert_equal(coinbase.vin[0].prevout.hash, 0)
|
||||
|
||||
self.log.debug("Wait for a new template")
|
||||
waitoptions = self.capnp_modules['mining'].BlockWaitOptions()
|
||||
|
||||
@@ -164,7 +164,7 @@ def add_witness_commitment(block, nonce=0):
|
||||
def script_BIP34_coinbase_height(height):
|
||||
if height <= 16:
|
||||
res = CScriptOp.encode_op_n(height)
|
||||
# Append dummy to increase scriptSig size to 2 (see bad-cb-length consensus rule)
|
||||
# Append dummy extraNonce to increase scriptSig size to 2 (see bad-cb-length consensus rule)
|
||||
return CScript([res, OP_0])
|
||||
return CScript([CScriptNum(height)])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user