enforce coinbase maturity rule, skip shielded-only rule instead

This commit is contained in:
Arya 2024-07-29 18:56:53 -04:00
parent 7db0de5e0c
commit 6574a561b5
4 changed files with 28 additions and 19 deletions

View File

@ -310,7 +310,7 @@ impl Transaction {
// because of other consensus rules
OnlyShieldedOutputs { spend_height }
} else {
SomeTransparentOutputs
SomeTransparentOutputs { spend_height }
}
}

View File

@ -126,7 +126,10 @@ impl OrderedUtxo {
)]
pub enum CoinbaseSpendRestriction {
/// The UTXO is spent in a transaction with one or more transparent outputs
SomeTransparentOutputs,
SomeTransparentOutputs {
/// The height at which the UTXO is spent
spend_height: block::Height,
},
/// The UTXO is spent in a transaction which only has shielded outputs
OnlyShieldedOutputs {

View File

@ -83,7 +83,10 @@ fn reject_unshielded_coinbase_utxo_spend() {
};
let ordered_utxo = transparent::OrderedUtxo::new(output, created_height, 0);
let spend_restriction = transparent::CoinbaseSpendRestriction::SomeTransparentOutputs;
let spend_restriction = transparent::CoinbaseSpendRestriction::SomeTransparentOutputs {
// Use some fake height, this is only used on Regtest
spend_height: Height::MIN,
};
let result = check::utxo::transparent_coinbase_spend(
outpoint,

View File

@ -204,12 +204,18 @@ pub fn transparent_coinbase_spend(
return Ok(());
}
match spend_restriction {
OnlyShieldedOutputs { spend_height } => {
let spend_height = match spend_restriction {
OnlyShieldedOutputs { spend_height } => spend_height,
SomeTransparentOutputs { spend_height } if network.is_regtest() => spend_height,
SomeTransparentOutputs { .. } => {
return Err(UnshieldedTransparentCoinbaseSpend { outpoint })
}
};
let min_spend_height = utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.into();
let min_spend_height =
min_spend_height.expect("valid UTXOs have coinbase heights far below Height::MAX");
if spend_height >= min_spend_height || network.is_regtest() {
if spend_height >= min_spend_height {
Ok(())
} else {
Err(ImmatureTransparentCoinbaseSpend {
@ -219,9 +225,6 @@ pub fn transparent_coinbase_spend(
created_height: utxo.height,
})
}
}
SomeTransparentOutputs => Err(UnshieldedTransparentCoinbaseSpend { outpoint }),
}
}
/// Reject negative remaining transaction value.