Skip to content

Commit

Permalink
Renames CoinbaseSpendRestriction variants and updates their documenta…
Browse files Browse the repository at this point in the history
…tion.

Updates a comment.
  • Loading branch information
arya2 committed Dec 19, 2024
1 parent 1b69b49 commit 1662614
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
3 changes: 2 additions & 1 deletion zebra-chain/src/block/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
10 changes: 7 additions & 3 deletions zebra-chain/src/transparent/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
);
Expand Down
6 changes: 3 additions & 3 deletions zebra-state/src/service/check/tests/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions zebra-state/src/service/check/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -212,7 +212,7 @@ pub fn transparent_coinbase_spend(
})
}
}
SomeTransparentOutputs => Err(UnshieldedTransparentCoinbaseSpend { outpoint }),
DisallowCoinbaseSpend => Err(UnshieldedTransparentCoinbaseSpend { outpoint }),
}
}

Expand Down

0 comments on commit 1662614

Please sign in to comment.