From 3e7b308b159d6b9f913a12c855d017a2742b9694 Mon Sep 17 00:00:00 2001 From: Marek Date: Wed, 4 Dec 2024 12:50:26 +0100 Subject: [PATCH] Remove `effective_version` --- zebra-chain/src/transaction.rs | 26 ++++++++++-------------- zebra-consensus/src/transaction/check.rs | 5 ++++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index ecf530e3cad..1c121130fcc 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -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]: pub fn version(&self) -> u32 { match self { Transaction::V1 { .. } => 1, @@ -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]: - 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 { let lock_time = match self { diff --git a/zebra-consensus/src/transaction/check.rs b/zebra-consensus/src/transaction/check.rs index 6dcf9ce571f..d3ddc460264 100644 --- a/zebra-consensus/src/transaction/check.rs +++ b/zebra-consensus/src/transaction/check.rs @@ -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]: /// [7.1.2 Transaction Consensus Rules]: pub fn consensus_branch_id( @@ -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(()); }