Skip to content

Commit

Permalink
Remove effective_version
Browse files Browse the repository at this point in the history
  • Loading branch information
upbqdn committed Dec 4, 2024
1 parent c698507 commit 3e7b308
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
26 changes: 11 additions & 15 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,17 @@ impl Transaction {
}
}

/// Return the version of this transaction.
/// Returns the version of this transaction.
///
/// Note that the returned version is equal to `effectiveVersion`, described in [§ 7.1
/// Transaction Encoding and Consensus]:
///
/// > `effectiveVersion` [...] is equal to `min(2, version)` when `fOverwintered = 0` and to
/// > `version` otherwise.
///
/// Zebra handles the `fOverwintered` flag via the [`Self::is_overwintered`] method.
///
/// [§ 7.1 Transaction Encoding and Consensus]: <https://zips.z.cash/protocol/protocol.pdf#txnencoding>
pub fn version(&self) -> u32 {
match self {
Transaction::V1 { .. } => 1,
Expand All @@ -335,20 +345,6 @@ impl Transaction {
}
}

/// Returns `effectiveVersion` as described in [§ 7.1 Transaction Encoding and Consensus]:
///
/// > `effectiveVersion` [...] is equal to `min(2, version)` when `fOverwintered = 0` and to
/// > `version` otherwise.
///
/// [§ 7.1 Transaction Encoding and Consensus]: <https://zips.z.cash/protocol/protocol.pdf#txnencoding>
pub fn effective_version(&self) -> u32 {
if self.is_overwintered() {
self.version()
} else {
std::cmp::min(2, self.version())
}
}

/// Get this transaction's lock time.
pub fn lock_time(&self) -> Option<LockTime> {
let lock_time = match self {
Expand Down
5 changes: 4 additions & 1 deletion zebra-consensus/src/transaction/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ pub fn tx_transparent_coinbase_spends_maturity(
/// - When deserializing transactions, Zebra converts the `nConsensusBranchId` into
/// [`NetworkUpgrade`].
///
/// - The values returned by [`Transaction::version`] match `effectiveVersion` so we use them in
/// place of `effectiveVersion`. More details in [`Transaction::version`].
///
/// [ZIP-244]: <https://zips.z.cash/zip-0244>
/// [7.1.2 Transaction Consensus Rules]: <https://zips.z.cash/protocol/protocol.pdf#txnconsensus>
pub fn consensus_branch_id(
Expand All @@ -519,7 +522,7 @@ pub fn consensus_branch_id(
) -> Result<(), TransactionError> {
let current_nu = NetworkUpgrade::current(network, height);

if current_nu < NetworkUpgrade::Nu5 || tx.effective_version() < 5 {
if current_nu < NetworkUpgrade::Nu5 || tx.version() < 5 {
return Ok(());
}

Expand Down

0 comments on commit 3e7b308

Please sign in to comment.