Skip to content

Commit

Permalink
Changes requested: Fixed and documented constructor and added panic i…
Browse files Browse the repository at this point in the history
…f NU ordering is changed
  • Loading branch information
Oscar-Pepper committed Apr 8, 2024
1 parent f668e1f commit 68d2add
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions components/zcash_protocol/src/local_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub struct LocalNetwork {
}

impl LocalNetwork {
/// Construct a new `LocalNetwork` where all network upgrade activation heights are specified.
///
/// Sequential network upgrades may share the same activation height but this constructor will
/// panic if the order in which network upgrades activate is changed.
pub fn new(
overwinter: u64,
sapling: u64,
Expand All @@ -52,22 +56,35 @@ impl LocalNetwork {
canopy: u64,
nu5: u64,
) -> Self {
assert!(
overwinter <= sapling
&& sapling <= blossom
&& blossom <= heartwood
&& heartwood <= canopy
&& canopy <= nu5,
"Network upgrade activation heights must be in ascending order"
);

LocalNetwork {
overwinter: Some(BlockHeight::from_u32(overwinter as u32)),
sapling: Some(BlockHeight::from_u32(sapling as u32)),
blossom: Some(BlockHeight::from_u32(blossom as u32)),
heartwood: Some(BlockHeight::from_u32(heartwood as u32)),
canopy: Some(BlockHeight::from_u32(canopy as u32)),
nu5: Some(BlockHeight::from_u32(nu5 as u32)),
#[cfg(zcash_unstable = "nu6")]
nu6: None,
#[cfg(zcash_unstable = "zfuture")]
z_future: None,
}
}

/// Creates a `LocalNetwork` with all network upgrades initially active.
/// Construct a new `LocalNetwork` with all network upgrades initially active.
pub fn all_upgrades_active() -> Self {
Self::new(1, 1, 1, 1, 1, 1)
}

/// Creates a `LocalNetwork` with all network upgrades up to and including canopy
/// Construct a new `LocalNetwork` with all network upgrades up to and including canopy
/// initally active.
pub fn canopy_active(nu5_activation_height: u64) -> Self {
Self::new(1, 1, 1, 1, 1, nu5_activation_height)
Expand Down

0 comments on commit 68d2add

Please sign in to comment.