test: mining: add coverage for GBT’s “coinbasevalue” result field #34958

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202603-test-getblocktemplate-coinbasevalue_full_block_reward changing 1 files +6 −1
  1. theStack commented at 5:13 pm on March 30, 2026: contributor

    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:

     0diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
     1index a935810d91..ba9ac9dadb 100644
     2--- a/src/rpc/mining.cpp
     3+++ b/src/rpc/mining.cpp
     4@@ -998,7 +998,7 @@ static RPCHelpMan getblocktemplate()
     5     result.pushKV("previousblockhash", block.hashPrevBlock.GetHex());
     6     result.pushKV("transactions", std::move(transactions));
     7     result.pushKV("coinbaseaux", std::move(aux));
     8-    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue);
     9+    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue - 1);
    10     result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast));
    11     result.pushKV("target", hashTarget.GetHex());
    12     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.

  2. test: mining: add coverage for GBT's "coinbasevalue" result field
    Add missing test coverage for the `getblocktemplate` RPC call
    "coinbasevalue" field, specifically that it is set to claim the
    full block reward.
    12c3c3f81d
  3. DrahtBot added the label Tests on Mar 30, 2026
  4. DrahtBot commented at 5:14 pm on March 30, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, Sjors

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  5. bitcoin deleted a comment on Mar 30, 2026
  6. maflcko commented at 7:05 am on March 31, 2026: member
    lgtm ACK 12c3c3f81d52b852cf51b549a5de4d55b0ed624b
  7. Sjors commented at 7:13 am on March 31, 2026: member

    ACK 12c3c3f81d52b852cf51b549a5de4d55b0ed624b

    You could also make this cover the IPC CoinbaseTx struct:

     0--- a/src/rpc/mining.cpp
     1+++ b/src/rpc/mining.cpp
     2@@ -999,5 +999,6 @@ static RPCHelpMan getblocktemplate()
     3     result.pushKV("transactions", std::move(transactions));
     4     result.pushKV("coinbaseaux", std::move(aux));
     5-    result.pushKV("coinbasevalue", block.vtx[0]->vout[0].nValue);
     6+    const auto coinbase{block_template->getCoinbaseTx()};
     7+    result.pushKV("coinbasevalue", coinbase.block_reward_remaining);
     8     result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast));
     9     result.pushKV("target", hashTarget.GetHex());
    10@@ -1026,5 +1027,5 @@ static RPCHelpMan getblocktemplate()
    11     }
    12
    13-    if (auto coinbase{block_template->getCoinbaseTx()}; coinbase.required_outputs.size() > 0) {
    14+    if (coinbase.required_outputs.size() > 0) {
    15         CHECK_NONFATAL(coinbase.required_outputs.size() == 1); // Only one output is currently expected
    16         result.pushKV("default_witness_commitment", HexStr(coinbase.required_outputs[0].scriptPubKey));
    

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-03-31 12:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me