test: spend an existing output in `TestBasicMining` double spend case #36798

pull yuvicc wants to merge 1 commits into bitcoin:master from yuvicc:test-miner-double-spend changing 1 files +1 −0
  1. yuvicc commented at 11:47 AM on November 7, 2026: contributor

    The double spend case in TestBasicMining is meant to check that block template creation fails when two mempool transactions spend the same coin. It reuses the transaction from the preceding coinbase case, whose prevout was cleared with SetNull(), and only overwrites the prevout hash. The output index therefore stays COutPoint::NULL_INDEX, so both transactions spend an output of txFirst[0] that does not exist.

    Set the output index to 0, so the first transaction is a valid spend and only the second one makes template creation fail.

    Found while working on #36692 and https://github.com/yuvicc/bitcoin/pull/19.

  2. test: spend an existing output in TestBasicMining double spend case
    The double spend pair reuses the transaction of the preceding coinbase
    case, whose prevout was cleared with SetNull(). Only the prevout hash
    was overwritten, so both transactions spent output index
    COutPoint::NULL_INDEX, which does not exist. Template creation
    therefore failed on a missing input even without a second spend.
    
    Set the output index to 0 so the first transaction is valid and only
    the double spend makes template creation fail.
    b2c7f2545e
  3. DrahtBot added the label Tests on Nov 7, 2026
  4. DrahtBot commented at 11:47 AM on November 7, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK jpk68, alexanderwiederin, maflcko

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. jpk68 commented at 12:09 AM on November 8, 2026: contributor

    ACK b2c7f2545e9a902cb820311e4ff401091a9d620e

  6. alexanderwiederin commented at 8:29 AM on November 9, 2026: contributor

    ACK b2c7f2545e9a902cb820311e4ff401091a9d620e

    Verified by commenting out the second TryAddToMempool:

    • master: test still passes
    • this PR: fails with exception std::runtime_error expected but not raised (miner_tests.cpp:557), as expected

    Clean run on this PR passes.

  7. alexanderwiederin commented at 8:37 AM on November 9, 2026: contributor

    The case lost its valid prevout.n in 18e071841e, which moved the p2sh case (which set n = 0) after this check, so the double-spend case started inheriting NULL_INDEX from the coinbase case.

  8. maflcko commented at 11:47 AM on November 9, 2026: member

    lgtm ACK b2c7f2545e9a902cb820311e4ff401091a9d620e

  9. fanquake merged this on Nov 9, 2026
  10. fanquake closed this on Nov 9, 2026

  11. yuvicc deleted the branch on Nov 9, 2026

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-11-18 16:51 UTC

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