Merge bitcoin/bitcoin#34958: test: mining: add coverage for GBT's "coinbasevalue" result field

12c3c3f81d test: mining: add coverage for GBT's "coinbasevalue" result field (Sebastian Falbesoner)

Pull request description:

  This PR adds missing coverage for the "coinbasevalue" result field of the `getblocktemplate` RPC call. Specifically, the introduced test checks that the value is set to claim the full block reward (subsidy plus fees). Can be verified with the following patch, which succeeds on master and fails on the PR branch:

  ```diff
  diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
  index a935810d91..ba9ac9dadb 100644
  --- a/src/rpc/mining.cpp
  +++ b/src/rpc/mining.cpp
  @@ -998,7 +998,7 @@ static RPCHelpMan getblocktemplate()
       result.pushKV("previousblockhash", block.hashPrevBlock.GetHex());
       result.pushKV("transactions", std::move(transactions));
       result.pushKV("coinbaseaux", std::move(aux));
  -    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue);
  +    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue - 1);
       result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast));
       result.pushKV("target", hashTarget.GetHex());
       result.pushKV("mintime", GetMinimumTime(pindexPrev, consensusParams.DifficultyAdjustmentInterval()));

  ```

  I'm not sure how relevant this field is nowadays in real-world mining scenarios (we use it for the signet miner at least), but it seems useful to have a test for it anyways. Stumbled upon this while looking at https://github.com/bitcoin-inquisition/bitcoin/pull/111.

ACKs for top commit:
  maflcko:
    lgtm ACK 12c3c3f81d
  Sjors:
    ACK 12c3c3f81d

Tree-SHA512: ae10f63c99b21cf7771feefe3d0e47b2e0d511aceb344cf11efa9182d78f2960f1e079797b8a36db110a3c54acb27a3706413a710a74bf56aed29ea162a6aab2
This commit is contained in:
merge-script
2026-03-31 23:57:26 +08:00

View File

@@ -122,7 +122,8 @@ class MiningTest(BitcoinTestFramework):
tx_d = self.wallet.send_self_transfer(from_node=node,
fee_rate=Decimal("0.00100"))
block_template_txs = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)['transactions']
block_template = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
block_template_txs = block_template['transactions']
block_template_fees = [tx['fee'] for tx in block_template_txs]
assert_equal(block_template_fees, [
@@ -131,6 +132,10 @@ class MiningTest(BitcoinTestFramework):
tx_b["fee"] * COIN,
tx_c["fee"] * COIN
])
# verify that coinbasevalue field is set to claim full block reward (subsidy + fees)
expected_block_reward = create_coinbase(
height=int(block_template["height"]), fees=sum(block_template_fees)).vout[0].nValue
assert_equal(block_template["coinbasevalue"], expected_block_reward)
block_template_sigops = [tx['sigops'] for tx in block_template_txs]
assert_equal(block_template_sigops, [0, 4, 4, 4])