From 4d6a810fd3c2b875e5505d7ffc65aee6ae37d6ec Mon Sep 17 00:00:00 2001 From: alexeykoren <2365507+alexeykoren@users.noreply.github.com> Date: Mon, 5 Aug 2024 22:00:36 +0200 Subject: [PATCH 1/4] Add regtest network --- components/zcash_protocol/src/consensus.rs | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index 56e41fb738..f89646a033 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -396,13 +396,43 @@ impl Parameters for TestNetwork { } } -/// The enumeration of known Zcash networks. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +/// Marker struct for the regtest network. +#[derive(PartialEq, Eq, Copy, Clone, Debug)] +pub struct RegtestNetwork; + +memuse::impl_no_dynamic_usage!(RegtestNetwork); + +pub const REGTEST_NETWORK: RegtestNetwork = RegtestNetwork; + +impl Parameters for RegtestNetwork { + fn network_type(&self) -> NetworkType { + NetworkType::Regtest + } + + fn activation_height(&self, nu: NetworkUpgrade) -> Option { + match nu { + NetworkUpgrade::Overwinter => Some(BlockHeight(1)), + NetworkUpgrade::Sapling => Some(BlockHeight(1)), + NetworkUpgrade::Blossom => Some(BlockHeight(1)), + NetworkUpgrade::Heartwood => Some(BlockHeight(1)), + NetworkUpgrade::Canopy => Some(BlockHeight(1)), + NetworkUpgrade::Nu5 => Some(BlockHeight(1)), + NetworkUpgrade::Nu6 => Some(BlockHeight(1)), + NetworkUpgrade::Nu7 => Some(BlockHeight(1)), + #[cfg(feature = "zfuture")] + NetworkUpgrade::ZFuture => None, + } + } +} + +#[derive(PartialEq, Eq, Copy, Clone, Debug)] pub enum Network { /// Zcash Mainnet. MainNetwork, /// Zcash Testnet. TestNetwork, + /// Zcash Regtest. + RegtestNetwork, } memuse::impl_no_dynamic_usage!(Network); @@ -412,6 +442,7 @@ impl Parameters for Network { match self { Network::MainNetwork => NetworkType::Main, Network::TestNetwork => NetworkType::Test, + Network::RegtestNetwork => NetworkType::Regtest, } } @@ -419,6 +450,7 @@ impl Parameters for Network { match self { Network::MainNetwork => MAIN_NETWORK.activation_height(nu), Network::TestNetwork => TEST_NETWORK.activation_height(nu), + Network::RegtestNetwork => REGTEST_NETWORK.activation_height(nu), } } } From 73b528a818e74e8ae584ae19775ca1aaea879cf7 Mon Sep 17 00:00:00 2001 From: alexeykoren <2365507+alexeykoren@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:46:32 +0100 Subject: [PATCH 2/4] Fix build warnings --- components/zcash_protocol/src/consensus.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index f89646a033..e8f45028fc 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -417,7 +417,9 @@ impl Parameters for RegtestNetwork { NetworkUpgrade::Heartwood => Some(BlockHeight(1)), NetworkUpgrade::Canopy => Some(BlockHeight(1)), NetworkUpgrade::Nu5 => Some(BlockHeight(1)), + #[cfg(zcash_unstable = "nu6")] NetworkUpgrade::Nu6 => Some(BlockHeight(1)), + #[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] NetworkUpgrade::Nu7 => Some(BlockHeight(1)), #[cfg(feature = "zfuture")] NetworkUpgrade::ZFuture => None, From 281f22d42a8690cfd10957ab1fd55ba006653227 Mon Sep 17 00:00:00 2001 From: alexeykoren <2365507+alexeykoren@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:59:44 +0100 Subject: [PATCH 3/4] Fix zfuture --- components/zcash_protocol/src/consensus.rs | 2 +- zcash_primitives/src/transaction/mod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index e8f45028fc..df6b6925b3 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -421,7 +421,7 @@ impl Parameters for RegtestNetwork { NetworkUpgrade::Nu6 => Some(BlockHeight(1)), #[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] NetworkUpgrade::Nu7 => Some(BlockHeight(1)), - #[cfg(feature = "zfuture")] + #[cfg(zcash_unstable = "zfuture")] NetworkUpgrade::ZFuture => None, } } diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index 6f0bc1c002..05d7e217f5 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -1215,6 +1215,7 @@ pub mod testing { #[cfg(zcash_unstable = "zfuture")] use super::components::tze::testing::{self as tze}; + #[cfg(not(zcash_unstable = "zfuture"))] use crate::transaction::components::issuance; pub fn arb_txid() -> impl Strategy { From b9360225a5551137f2d1fcac40b9ab4cdb0394e2 Mon Sep 17 00:00:00 2001 From: alexeykoren <2365507+alexeykoren@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:22:48 +0100 Subject: [PATCH 4/4] Return Hash to Network enum --- components/zcash_protocol/src/consensus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index df6b6925b3..721c27ef47 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -427,7 +427,7 @@ impl Parameters for RegtestNetwork { } } -#[derive(PartialEq, Eq, Copy, Clone, Debug)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] pub enum Network { /// Zcash Mainnet. MainNetwork,