diff --git a/zebra-chain/src/block/arbitrary.rs b/zebra-chain/src/block/arbitrary.rs index 5a8a91d1700..4961c873b3e 100644 --- a/zebra-chain/src/block/arbitrary.rs +++ b/zebra-chain/src/block/arbitrary.rs @@ -650,7 +650,8 @@ where + 'static, { let has_shielded_outputs = transaction.has_shielded_outputs(); - let delete_transparent_outputs = CoinbaseSpendRestriction::OnlyShieldedOutputs { spend_height }; + let delete_transparent_outputs = + CoinbaseSpendRestriction::CheckCoinbaseMaturity { spend_height }; let mut attempts: usize = 0; // choose an arbitrary spendable UTXO, in hash set order diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 9d3135d239c..d29eadff8cf 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -307,11 +307,11 @@ impl Transaction { spend_height: block::Height, ) -> CoinbaseSpendRestriction { if self.outputs().is_empty() || network.should_allow_unshielded_coinbase_spends() { - // we know this transaction must have shielded outputs, - // because of other consensus rules - OnlyShieldedOutputs { spend_height } + // we know this transaction must have shielded outputs if it has no + // transparent outputs, because of other consensus rules. + CheckCoinbaseMaturity { spend_height } } else { - SomeTransparentOutputs + DisallowCoinbaseSpend } } diff --git a/zebra-chain/src/transparent/utxo.rs b/zebra-chain/src/transparent/utxo.rs index 0158165193a..1b5f49bcd89 100644 --- a/zebra-chain/src/transparent/utxo.rs +++ b/zebra-chain/src/transparent/utxo.rs @@ -126,10 +126,14 @@ impl OrderedUtxo { )] pub enum CoinbaseSpendRestriction { /// The UTXO is spent in a transaction with one or more transparent outputs - SomeTransparentOutputs, + /// on a network where coinbase outputs must not be spent by transactions + /// with transparent outputs. + DisallowCoinbaseSpend, - /// The UTXO is spent in a transaction which only has shielded outputs - OnlyShieldedOutputs { + /// The UTXO is spent in a transaction which only has shielded outputs, or + /// transactions spending coinbase outputs may have transparent outputs on + /// this network. + CheckCoinbaseMaturity { /// The height at which the UTXO is spent spend_height: block::Height, }, diff --git a/zebra-consensus/src/transaction/tests.rs b/zebra-consensus/src/transaction/tests.rs index d268358282e..bc0d9ec7898 100644 --- a/zebra-consensus/src/transaction/tests.rs +++ b/zebra-consensus/src/transaction/tests.rs @@ -848,7 +848,7 @@ async fn mempool_request_with_transparent_coinbase_spend_is_accepted_on_regtest( assert_eq!( spend_restriction, - CoinbaseSpendRestriction::OnlyShieldedOutputs { + CoinbaseSpendRestriction::CheckCoinbaseMaturity { spend_height: height } ); diff --git a/zebra-state/src/service/check/tests/utxo.rs b/zebra-state/src/service/check/tests/utxo.rs index acdc2d399a7..57d087c552d 100644 --- a/zebra-state/src/service/check/tests/utxo.rs +++ b/zebra-state/src/service/check/tests/utxo.rs @@ -48,7 +48,7 @@ fn accept_shielded_mature_coinbase_utxo_spend() { let ordered_utxo = transparent::OrderedUtxo::new(output, created_height, 0); let min_spend_height = Height(created_height.0 + MIN_TRANSPARENT_COINBASE_MATURITY); - let spend_restriction = transparent::CoinbaseSpendRestriction::OnlyShieldedOutputs { + let spend_restriction = transparent::CoinbaseSpendRestriction::CheckCoinbaseMaturity { spend_height: min_spend_height, }; @@ -78,7 +78,7 @@ 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::DisallowCoinbaseSpend; let result = check::utxo::transparent_coinbase_spend(outpoint, spend_restriction, ordered_utxo.as_ref()); @@ -104,7 +104,7 @@ fn reject_immature_coinbase_utxo_spend() { let min_spend_height = Height(created_height.0 + MIN_TRANSPARENT_COINBASE_MATURITY); let spend_height = Height(min_spend_height.0 - 1); let spend_restriction = - transparent::CoinbaseSpendRestriction::OnlyShieldedOutputs { spend_height }; + transparent::CoinbaseSpendRestriction::CheckCoinbaseMaturity { spend_height }; let result = check::utxo::transparent_coinbase_spend(outpoint, spend_restriction, ordered_utxo.as_ref()); diff --git a/zebra-state/src/service/check/utxo.rs b/zebra-state/src/service/check/utxo.rs index ef6c2533c8c..df3981ec0b8 100644 --- a/zebra-state/src/service/check/utxo.rs +++ b/zebra-state/src/service/check/utxo.rs @@ -197,7 +197,7 @@ pub fn transparent_coinbase_spend( } match spend_restriction { - OnlyShieldedOutputs { spend_height } => { + CheckCoinbaseMaturity { spend_height } => { 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"); @@ -212,7 +212,7 @@ pub fn transparent_coinbase_spend( }) } } - SomeTransparentOutputs => Err(UnshieldedTransparentCoinbaseSpend { outpoint }), + DisallowCoinbaseSpend => Err(UnshieldedTransparentCoinbaseSpend { outpoint }), } }