The BIP30 tests in feature_block.py only cover duplicate coinbase transactions, but the check applies to every transaction in a block.
Add coverage for a duplicate non-coinbase transaction:
- tx A spends coinbase C
- a duplicate of C is mined and matures, so A can be included again
- re-including A is rejected while A's outputs are unspent
- re-including A is accepted after A's outputs are spent
Kills the following mutant (https://mutanthub.space/mutants/4389):
diff --git a/src/validation.cpp b/src/validation.cpp
index 6bed39ba5f..a8a6b46b3d 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2538,12 +2538,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
// consensus change that ensures coinbases at those heights cannot
// duplicate earlier coinbases.
if (fEnforceBIP30 || pindex->nHeight >= BIP34_IMPLIES_BIP30_LIMIT) {
- for (const auto& tx : block.vtx) {
- for (size_t o = 0; o < tx->vout.size(); o++) {
- if (view.HaveCoin(COutPoint(tx->GetHash(), o))) {
- state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
- "tried to overwrite transaction");
- }
+ const CTransaction& coinbase{*block.vtx[0]};
+ for (size_t o = 0; o < coinbase.vout.size(); o++) {
+ if (view.HaveCoin(COutPoint(coinbase.GetHash(), o))) {
+ state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
+ "tried to overwrite transaction");
}
}
}