Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local network to network enum #1276

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/zcash_protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this library adheres to Rust's notion of
### Added
- `zcash_protocol::memo`:
- `impl TryFrom<&MemoBytes> for Memo`
- `zcash_protocol::local_consensus`:
- `new`, `all_upgrades_active` and `canopy_active` methods to `LocalNetwork`

### Changed
- `zcash_protocol::consensus`:
- Added `LocalNetwork` variant to `Network` enum behind "local-consensus" feature

### Removed
- `unstable-nu6` and `zfuture` feature flags (use `--cfg zcash_unstable=\"nu6\"`
Expand Down
10 changes: 10 additions & 0 deletions components/zcash_protocol/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use std::ops::{Add, Bound, RangeBounds, Sub};

use crate::constants::{mainnet, regtest, testnet};

#[cfg(feature = "local-consensus")]
use crate::local_consensus::LocalNetwork;

/// A wrapper type representing blockchain heights.
///
/// Safe conversion from various integer types, as well as addition and subtraction, are
Expand Down Expand Up @@ -399,6 +402,9 @@ pub enum Network {
MainNetwork,
/// Zcash Testnet.
TestNetwork,
#[cfg(feature = "local-consensus")]
/// Zcash local network (regtest)
LocalNetwork(LocalNetwork),
}

memuse::impl_no_dynamic_usage!(Network);
Expand All @@ -408,13 +414,17 @@ impl Parameters for Network {
match self {
Network::MainNetwork => NetworkType::Main,
Network::TestNetwork => NetworkType::Test,
#[cfg(feature = "local-consensus")]
Network::LocalNetwork(ln) => ln.network_type(),
}
}

fn activation_height(&self, nu: NetworkUpgrade) -> Option<BlockHeight> {
match self {
Network::MainNetwork => MAIN_NETWORK.activation_height(nu),
Network::TestNetwork => TEST_NETWORK.activation_height(nu),
#[cfg(feature = "local-consensus")]
Network::LocalNetwork(ln) => ln.activation_height(nu),
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions components/zcash_protocol/src/local_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ pub struct LocalNetwork {
pub z_future: Option<BlockHeight>,
}

impl LocalNetwork {
pub fn new(
overwinter: u64,
sapling: u64,
blossom: u64,
heartwood: u64,
canopy: u64,
nu5: u64,
) -> Self {
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)),
}
}

/// Creates a `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
/// initally active.
pub fn canopy_active(nu5_activation_height: u64) -> Self {
Self::new(1, 1, 1, 1, 1, nu5_activation_height)
}
}

/// Parameters implementation for `LocalNetwork`
impl Parameters for LocalNetwork {
fn network_type(&self) -> NetworkType {
Expand Down