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

Manually merged
yuvicc merged 1 commit from test-miner-double-spend into master 2026-11-09 11:55:37 +00:00 AGit
yuvicc commented 2026-11-07 11:47:20 +00:00 (Migrated from github.com)

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.

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.
DrahtBot commented 2026-11-07 11:47:28 +00:00 (Migrated from github.com)

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36798 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36798.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36798#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [jpk68](https://github.com/bitcoin/bitcoin/pull/36798#issuecomment-6714862476), [alexanderwiederin](https://github.com/bitcoin/bitcoin/pull/36798#issuecomment-6735619001), [maflcko](https://github.com/bitcoin/bitcoin/pull/36798#issuecomment-6739281367) | 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-->
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: b2c7f2545e9a · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:055d1cd96b176486294e0a3d052a7e506a00c1f0c7c35fbf579b09cfe6d615cd:237cc81563f53f26a84ba90acce49f0597b0e28b0a77aa425401db6e90431c0b --> <!-- ralph-base:5bf3bc5e263407a252c14a17afe04fc3bf24a889 --> <!-- ralph-head:b2c7f2545e9a902cb820311e4ff401091a9d620e --> <!-- ralph-case:dd663e3999000fde739ec6a1795cac67d60dd86bafd4ec99a1fcfc8742b84a9e --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`b2c7f2545e9a`](<https://git.fish.foo/bitcoin/bitcoin/commit/b2c7f2545e9a902cb820311e4ff401091a9d620e>) · [Full review report](<https://review.fish.foo/traces/36798-b2c7f2545e9a902cb820311e4ff401091a9d620e-2360-1.html>) · [Previous reports](<https://review.fish.foo/traces/36798/>) [permalink](<https://review.fish.foo/traces/36798-b2c7f2545e9a902cb820311e4ff401091a9d620e-2360-1.html>)
jpk68 commented 2026-11-08 00:09:43 +00:00 (Migrated from github.com)
ACK b2c7f2545e9a902cb820311e4ff401091a9d620e
alexanderwiederin commented 2026-11-09 08:29:49 +00:00 (Migrated from github.com)

ACK b2c7f2545e

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.

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.
alexanderwiederin commented 2026-11-09 08:37:14 +00:00 (Migrated from github.com)

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.

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.
maflcko commented 2026-11-09 11:47:08 +00:00 (Migrated from github.com)

lgtm ACK b2c7f2545e

lgtm ACK b2c7f2545e9a902cb820311e4ff401091a9d620e
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36798
No description provided.