diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 6039866..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,18 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -### Deprecated - -### Added -- support for Zebra 4.1.0 -- support for Zebra 4 -### Changed - -### Removed - diff --git a/Cargo.lock b/Cargo.lock index 32adbf8..1b8ff9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3141,6 +3141,7 @@ dependencies = [ "zcash_transparent", "zebra-node-services", "zebra-rpc", + "zingo_common_components", "zip32", ] @@ -5409,10 +5410,7 @@ dependencies = [ [[package]] name = "zingo_common_components" version = "0.2.0" -source = "git+https://github.com/zingolabs/zingo-common.git?branch=dev#096a79e2b3eb8b12d642e3380044bac00e7c855d" -dependencies = [ - "zebra-chain", -] +source = "git+https://github.com/zingolabs/zingo-common.git?branch=dev#85a61dcedbccd01e26b6b07bad003770ad30ac1b" [[package]] name = "zingo_test_vectors" diff --git a/regtest-launcher/Cargo.toml b/regtest-launcher/Cargo.toml index 7e128d6..8a09182 100644 --- a/regtest-launcher/Cargo.toml +++ b/regtest-launcher/Cargo.toml @@ -20,6 +20,7 @@ zcash_transparent = "0.6.3" zebra-node-services = { workspace = true, features = ["rpc-client"] } zebra-rpc.workspace = true zip32 = "0.2.1" +zingo_common_components = { git = "https://github.com/zingolabs/zingo-common.git", branch = "dev" } [dev-dependencies] anyhow = "1.0.100" diff --git a/regtest-launcher/src/main.rs b/regtest-launcher/src/main.rs index 3c8b48d..1a2ebe0 100644 --- a/regtest-launcher/src/main.rs +++ b/regtest-launcher/src/main.rs @@ -38,13 +38,24 @@ use zebra_rpc::{ }, proposal_block_from_template, }; +use zingo_common_components::protocol::ActivationHeights; use crate::{cli::Cli, keygen::generate_regtest_transparent_keypair}; #[tokio::main] async fn main() { let cli = Cli::parse(); - let heights = cli.activation_heights; + let heights = ActivationHeights::builder() + .set_overwinter(cli.activation_heights.overwinter) + .set_sapling(cli.activation_heights.sapling) + .set_blossom(cli.activation_heights.blossom) + .set_heartwood(cli.activation_heights.heartwood) + .set_canopy(cli.activation_heights.canopy) + .set_nu5(cli.activation_heights.nu5) + .set_nu6(cli.activation_heights.nu6) + .set_nu6_1(cli.activation_heights.nu6_1) + .set_nu7(cli.activation_heights.nu7) + .build(); let (mnemonic_opt, sk_opt, taddr_str) = match cli.miner_address.as_deref() { Some(addr) => (None, None, addr.to_string()), @@ -94,7 +105,7 @@ async fn main() { let regtest_network = Network::Testnet(Arc::new( Parameters::new_regtest(RegtestParameters { - activation_heights: heights, + activation_heights: cli.activation_heights, funding_streams: None, lockbox_disbursements: None, checkpoints: None, diff --git a/zcash_local_net/CHANGELOG.md b/zcash_local_net/CHANGELOG.md new file mode 100644 index 0000000..04208fd --- /dev/null +++ b/zcash_local_net/CHANGELOG.md @@ -0,0 +1,34 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Deprecated + +### Added +- support for Zebra 4.1.0 +- support for Zebra 4 + +### Changed +- `validator::Validator` trait: + - `network`: now takes `ActivationHeights` instead of `ConfiguredActivationHeights`. + - `load_chain`: now takes `NetworkType` instead of `NetworkKind`. +- `validator::zcashd::ZcashdConfig`: changed `configured_activation_heights: ConfiguredActivationHeights` field to +`activation_heights: ActivationHeights`. Removing the zebra-chain type from the public API and replacing with new +zingo_common_components type. +- `validator::zebrad::ZebradConfig`: + - changed `network: NetworkKind` to `network_type: NetworkType`. Removing the +zebra-chain type from the public API and replacing with new zingo_common_components type. + - `with_regtest_enabled` method: now takes `ActivationHeights` instead of `ConfiguredActivationHeights`. + - `set_test_parameters` method: now takes `ActivationHeights` instead of `ConfiguredActivationHeights`. + +### Removed +- `validator::zebrad::ZebradConfig`: removed `configured_activation_heights: ConfiguredActivationHeights` field removing the +zebra-chain type from the public API. Replaced by new `network_type` field which includes activation heights. + +## [0.1.0] + diff --git a/zcash_local_net/Cargo.toml b/zcash_local_net/Cargo.toml index 7bbddd1..1dbae03 100644 --- a/zcash_local_net/Cargo.toml +++ b/zcash_local_net/Cargo.toml @@ -10,9 +10,7 @@ github = { repository = "zingolabs/infrastructure/services" } [dependencies] # zingo -zingo_common_components = { git = "https://github.com/zingolabs/zingo-common.git", branch = "dev", features = [ - "for_test", -] } +zingo_common_components = { git = "https://github.com/zingolabs/zingo-common.git", branch = "dev" } zingo_test_vectors = { workspace = true } # zcash diff --git a/zcash_local_net/src/config.rs b/zcash_local_net/src/config.rs index f15fafe..b57e1fb 100644 --- a/zcash_local_net/src/config.rs +++ b/zcash_local_net/src/config.rs @@ -6,15 +6,14 @@ use std::path::{Path, PathBuf}; use portpicker::Port; -use zebra_chain::parameters::testnet; -use zebra_chain::parameters::NetworkKind; +use zingo_common_components::protocol::{ActivationHeights, NetworkType}; /// Convert `NetworkKind` to its config string representation -fn network_kind_to_string(network: NetworkKind) -> &'static str { +fn network_type_to_string(network: NetworkType) -> &'static str { match network { - NetworkKind::Mainnet => "Mainnet", - NetworkKind::Testnet => "Testnet", - NetworkKind::Regtest => "Regtest", + NetworkType::Mainnet => "Mainnet", + NetworkType::Testnet => "Testnet", + NetworkType::Regtest(_) => "Regtest", } } @@ -29,44 +28,37 @@ pub(crate) const LIGHTWALLETD_FILENAME: &str = "lightwalletd.yml"; pub(crate) fn write_zcashd_config( config_dir: &Path, rpc_port: Port, - test_activation_heights: &testnet::ConfiguredActivationHeights, + activation_heights: ActivationHeights, miner_address: Option<&str>, ) -> std::io::Result { let config_file_path = config_dir.join(ZCASHD_FILENAME); let file = File::create(config_file_path.clone())?; let mut config_file = BufWriter::new(file); - let testnet::ConfiguredActivationHeights { - before_overwinter: _, // Skip pre-overwinter as noted - overwinter, - sapling, - blossom, - heartwood, - canopy, - nu5, - nu6, - nu6_1, - .. // Ignore any future fields like nu7 - } = test_activation_heights; - - let overwinter_activation_height = - overwinter.expect("overwinter activation height must be specified"); - let sapling_activation_height = sapling.expect("sapling activation height must be specified"); - let blossom_activation_height = blossom.expect("blossom activation height must be specified"); - let heartwood_activation_height = - heartwood.expect("heartwood activation height must be specified"); - let canopy_activation_height = canopy.expect("canopy activation height must be specified"); - let nu5_activation_height = nu5.expect("nu5 activation height must be specified"); - - let nu6_activation_height = *nu6; - let nu6_1_activation_height = *nu6_1; - - if nu6_activation_height.is_none() && nu6_1_activation_height.is_some() { - return Err(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "NU6.1 is set but NU6 is None; set NU6 or unset NU6.1", - )); - } + let overwinter_activation_height = activation_heights + .overwinter() + .expect("overwinter activation height must be specified"); + let sapling_activation_height = activation_heights + .sapling() + .expect("sapling activation height must be specified"); + let blossom_activation_height = activation_heights + .blossom() + .expect("blossom activation height must be specified"); + let heartwood_activation_height = activation_heights + .heartwood() + .expect("heartwood activation height must be specified"); + let canopy_activation_height = activation_heights + .canopy() + .expect("canopy activation height must be specified"); + let nu5_activation_height = activation_heights + .nu5() + .expect("nu5 activation height must be specified"); + let nu6_activation_height = activation_heights + .nu6() + .expect("nu6 activation height must be specified"); + let nu6_1_activation_height = activation_heights + .nu6_1() + .expect("nu6.1 activation height must be specified"); let mut cfg = format!( "\ @@ -77,20 +69,10 @@ nuparams=76b809bb:{sapling_activation_height} # Sapling nuparams=2bb40e60:{blossom_activation_height} # Blossom nuparams=f5b9230b:{heartwood_activation_height} # Heartwood nuparams=e9ff75a6:{canopy_activation_height} # Canopy -nuparams=c2d6d0b4:{nu5_activation_height} # NU5 (Orchard)" - ); - - if let Some(h) = nu6_activation_height { - cfg.push_str(&format!("\nnuparams=c8e71055:{h} # NU6")); - } - if let Some(h) = nu6_1_activation_height { - cfg.push_str(&format!( - "\nnuparams=4dec4df0:{h} # NU6_1 https://zips.z.cash/zip-0255#nu6.1deployment" - )); - } +nuparams=c2d6d0b4:{nu5_activation_height} # NU5 (Orchard) +nuparams=c8e71055:{nu6_activation_height} # NU6 +nuparams=4dec4df0:{nu6_1_activation_height} # NU6_1 https://zips.z.cash/zip-0255#nu6.1deployment - cfg.push_str(&format!( - "\n\n\ ### MetaData Storage and Retrieval # txindex: # https://zcash.readthedocs.io/en/latest/rtd_pages/zcash_conf_guide.html#miscellaneous-options @@ -113,7 +95,7 @@ rpcallowip=127.0.0.1 listen=0 i-am-aware-zcashd-will-be-replaced-by-zebrad-and-zallet-in-2025=1" - )); + ); if let Some(addr) = miner_address { cfg.push_str(&format!( @@ -141,32 +123,13 @@ pub(crate) fn write_zebrad_config( network_listen_port: Port, rpc_listen_port: Port, indexer_listen_port: Port, - activation_heights: &testnet::ConfiguredActivationHeights, miner_address: &str, - network: NetworkKind, + network: NetworkType, ) -> std::io::Result { let config_file_path = output_config_dir.join(ZEBRAD_FILENAME); let mut config_file = File::create(config_file_path.clone())?; - - assert!( - activation_heights.canopy.is_some(), - "canopy must be active for zebrad regtest mode. please set activation height to 1" - ); - - let nu5_activation_height = activation_heights.nu5.expect("nu5 activated"); - - let nu6_activation_height = activation_heights.nu6; - let nu6_1_activation_height = activation_heights.nu6_1; - - // Ordering is correct - assert!( - !(nu6_activation_height.is_none() && nu6_1_activation_height.is_some()), - "NU6.1 is set but NU6 is None; set NU6 or unset NU6.1" - ); - let chain_cache = cache_dir.to_str().unwrap(); - - let network_string = network_kind_to_string(network); + let network_string = network_type_to_string(network); let mut cfg = format!( "\ @@ -227,7 +190,22 @@ filter = \"debug\" use_journald = false", ); - if matches!(network, NetworkKind::Regtest) { + if let NetworkType::Regtest(activation_heights) = network { + assert!( + activation_heights.canopy().is_some(), + "canopy must be active for zebrad regtest mode. please set activation height to 1" + ); + + let nu5_activation_height = activation_heights + .nu5() + .expect("nu5 activation height must be specified"); + let nu6_activation_height = activation_heights + .nu6() + .expect("nu6 activation height must be specified"); + let nu6_1_activation_height = activation_heights + .nu6_1() + .expect("nu6.1 activation height must be specified"); + cfg.push_str(&format!( "\n\n\ [mining] @@ -238,15 +216,10 @@ miner_address = \"{miner_address}\" # block height 0 is reserved for the Genesis network upgrade in Zebra # pre-nu5 activation heights of greater than 1 are not currently supported for regtest mode Canopy = 1 -NU5 = {nu5_activation_height}" +NU5 = {nu5_activation_height} +NU6 = {nu6_activation_height} +\"NU6.1\" = {nu6_1_activation_height}" )); - - if let Some(nu6) = nu6_activation_height { - cfg.push_str(&format!("\nNU6 = {nu6}")); - } - if let Some(nu6_1) = nu6_1_activation_height { - cfg.push_str(&format!("\n\"NU6.1\" = {nu6_1}")); - } } config_file.write_all(cfg.as_bytes())?; @@ -263,7 +236,7 @@ pub(crate) fn write_zainod_config( validator_cache_dir: PathBuf, listen_port: Port, validator_port: Port, - network: NetworkKind, + network: NetworkType, ) -> std::io::Result { let config_file_path = config_dir.join(ZAINOD_FILENAME); let mut config_file = File::create(config_file_path.clone())?; @@ -271,7 +244,7 @@ pub(crate) fn write_zainod_config( let zaino_cache_dir = validator_cache_dir.join("zaino"); let chain_cache = zaino_cache_dir.to_str().unwrap(); - let network_string = network_kind_to_string(network); + let network_string = network_type_to_string(network); config_file.write_all( format!( @@ -330,8 +303,7 @@ zcash-conf-path: {zcashd_conf}" mod tests { use std::path::PathBuf; - use zebra_chain::parameters::NetworkKind; - use zingo_common_components::protocol::activation_heights::for_test; + use zingo_common_components::protocol::{ActivationHeights, NetworkType}; use crate::logs; @@ -370,13 +342,26 @@ listen=0 i-am-aware-zcashd-will-be-replaced-by-zebrad-and-zallet-in-2025=1"; + fn sequential_activation_heights() -> ActivationHeights { + ActivationHeights::builder() + .set_overwinter(Some(2)) + .set_sapling(Some(3)) + .set_blossom(Some(4)) + .set_heartwood(Some(5)) + .set_canopy(Some(6)) + .set_nu5(Some(7)) + .set_nu6(Some(8)) + .set_nu6_1(Some(9)) + .set_nu7(None) + .build() + } + #[test] fn zcashd() { let config_dir = tempfile::tempdir().unwrap(); - let test_activation_heights = for_test::sequential_height_nus(); + let test_activation_heights = sequential_activation_heights(); - super::write_zcashd_config(config_dir.path(), 1234, &test_activation_heights, None) - .unwrap(); + super::write_zcashd_config(config_dir.path(), 1234, test_activation_heights, None).unwrap(); assert_eq!( std::fs::read_to_string(config_dir.path().join(super::ZCASHD_FILENAME)).unwrap(), @@ -387,12 +372,12 @@ i-am-aware-zcashd-will-be-replaced-by-zebrad-and-zallet-in-2025=1"; #[test] fn zcashd_funded() { let config_dir = tempfile::tempdir().unwrap(); - let test_activation_heights = for_test::sequential_height_nus(); + let test_activation_heights = sequential_activation_heights(); super::write_zcashd_config( config_dir.path(), 1234, - &test_activation_heights, + test_activation_heights, Some("test_addr_1234"), ) .unwrap(); @@ -421,7 +406,7 @@ minetolocalwallet=0 # This is set to false so that we can mine to a wallet, othe zaino_cache_dir, 1234, 18232, - NetworkKind::Regtest, + NetworkType::Regtest(ActivationHeights::default()), ) .unwrap(); diff --git a/zcash_local_net/src/indexer/zainod.rs b/zcash_local_net/src/indexer/zainod.rs index 9eb4b65..7d42f0a 100644 --- a/zcash_local_net/src/indexer/zainod.rs +++ b/zcash_local_net/src/indexer/zainod.rs @@ -6,7 +6,7 @@ use getset::{CopyGetters, Getters}; use portpicker::Port; use tempfile::TempDir; -use zebra_chain::parameters::NetworkKind; +use zingo_common_components::protocol::{ActivationHeights, NetworkType}; use crate::logs::LogsToDir; use crate::logs::LogsToStdoutAndStderr as _; @@ -39,7 +39,7 @@ pub struct ZainodConfig { /// Chain cache path pub chain_cache: Option, /// Network type. - pub network: NetworkKind, + pub network: NetworkType, } impl Default for ZainodConfig { @@ -48,7 +48,7 @@ impl Default for ZainodConfig { listen_port: None, validator_port: 0, chain_cache: None, - network: NetworkKind::Regtest, + network: NetworkType::Regtest(ActivationHeights::default()), } } } diff --git a/zcash_local_net/src/utils.rs b/zcash_local_net/src/utils.rs index c31d74c..d95680d 100644 --- a/zcash_local_net/src/utils.rs +++ b/zcash_local_net/src/utils.rs @@ -4,6 +4,7 @@ use std::{env, path::PathBuf}; /// Functions for picking executables from env variables in the global runtime. pub mod executable_finder; +pub(crate) mod type_conversions; /// Returns path to cargo manifest directory (project root) pub(crate) fn cargo_manifest_dir() -> PathBuf { diff --git a/zcash_local_net/src/utils/type_conversions.rs b/zcash_local_net/src/utils/type_conversions.rs new file mode 100644 index 0000000..2bac0af --- /dev/null +++ b/zcash_local_net/src/utils/type_conversions.rs @@ -0,0 +1,19 @@ +use zebra_chain::parameters::testnet::ConfiguredActivationHeights; +use zingo_common_components::protocol::ActivationHeights; + +pub(crate) fn zingo_to_zebra_activation_heights( + value: ActivationHeights, +) -> ConfiguredActivationHeights { + ConfiguredActivationHeights { + before_overwinter: Some(1), + overwinter: value.overwinter(), + sapling: value.sapling(), + blossom: value.blossom(), + heartwood: value.heartwood(), + canopy: value.canopy(), + nu5: value.nu5(), + nu6: value.nu6(), + nu6_1: value.nu6_1(), + nu7: value.nu7(), + } +} diff --git a/zcash_local_net/src/validator.rs b/zcash_local_net/src/validator.rs index f972f65..d866312 100644 --- a/zcash_local_net/src/validator.rs +++ b/zcash_local_net/src/validator.rs @@ -4,8 +4,7 @@ use std::path::PathBuf; use portpicker::Port; use tempfile::TempDir; use zcash_protocol::PoolType; -use zebra_chain::parameters::testnet::ConfiguredActivationHeights; -use zebra_chain::parameters::NetworkKind; +use zingo_common_components::protocol::{ActivationHeights, NetworkType}; use crate::process::Process; @@ -15,7 +14,7 @@ pub mod zebrad; /// Parse activation heights from the upgrades object returned by getblockchaininfo RPC. fn parse_activation_heights_from_rpc( upgrades: &serde_json::Map, -) -> ConfiguredActivationHeights { +) -> ActivationHeights { // Helper function to extract activation height for a network upgrade by name let get_height = |name: &str| -> Option { upgrades.values().find_map(|upgrade| { @@ -30,19 +29,19 @@ fn parse_activation_heights_from_rpc( }) }; - let configured_activation_heights = ConfiguredActivationHeights { - before_overwinter: get_height("BeforeOverwinter"), - overwinter: get_height("Overwinter"), - sapling: get_height("Sapling"), - blossom: get_height("Blossom"), - heartwood: get_height("Heartwood"), - canopy: get_height("Canopy"), - nu5: get_height("NU5"), - nu6: get_height("NU6"), - nu6_1: get_height("NU6.1"), - nu7: get_height("NU7"), - }; + let configured_activation_heights = ActivationHeights::builder() + .set_overwinter(get_height("Overwinter")) + .set_sapling(get_height("Sapling")) + .set_blossom(get_height("Blossom")) + .set_heartwood(get_height("Heartwood")) + .set_canopy(get_height("Canopy")) + .set_nu5(get_height("NU5")) + .set_nu6(get_height("NU6")) + .set_nu6_1(get_height("NU6.1")) + .set_nu7(get_height("NU7")) + .build(); tracing::debug!("regtest validator reports the following activation heights: {configured_activation_heights:?}"); + configured_activation_heights } @@ -52,7 +51,7 @@ pub trait ValidatorConfig: Default { fn set_test_parameters( &mut self, mine_to_pool: PoolType, - configured_activation_heights: ConfiguredActivationHeights, + activation_heights: ActivationHeights, chain_cache: Option, ); } @@ -61,9 +60,8 @@ pub trait ValidatorConfig: Default { pub trait Validator: Process + std::fmt::Debug { /// A representation of the Network Upgrade Activation heights applied for this /// Validator's test configuration. - fn get_activation_heights( - &self, - ) -> impl std::future::Future + Send; + fn get_activation_heights(&self) + -> impl std::future::Future + Send; /// Generate `n` blocks. This implementation should also call [`Self::poll_chain_height`] so the chain is at the /// correct height when this function returns. @@ -94,7 +92,7 @@ pub trait Validator: Process + std::fmt::Debug { fn get_zcashd_conf_path(&self) -> PathBuf; /// Network type - fn network(&self) -> NetworkKind; + fn network(&self) -> NetworkType; /// Caches chain. This stops the zcashd process. fn cache_chain(&mut self, chain_cache: PathBuf) -> std::process::Output { @@ -119,7 +117,7 @@ pub trait Validator: Process + std::fmt::Debug { fn load_chain( chain_cache: PathBuf, validator_data_dir: PathBuf, - validator_network: NetworkKind, + validator_network: NetworkType, ) -> PathBuf; /// To reveal a port. diff --git a/zcash_local_net/src/validator/zcashd.rs b/zcash_local_net/src/validator/zcashd.rs index db5d229..90ded54 100644 --- a/zcash_local_net/src/validator/zcashd.rs +++ b/zcash_local_net/src/validator/zcashd.rs @@ -5,9 +5,10 @@ use std::{path::PathBuf, process::Child}; use getset::{CopyGetters, Getters}; use portpicker::Port; use tempfile::TempDir; + use zcash_protocol::PoolType; -use zebra_chain::parameters::testnet::ConfiguredActivationHeights; -use zebra_chain::parameters::NetworkKind; + +use zingo_common_components::protocol::{ActivationHeights, NetworkType}; use zingo_test_vectors::{ REG_O_ADDR_FROM_ABANDONART, REG_T_ADDR_FROM_ABANDONART, REG_Z_ADDR_FROM_ABANDONART, }; @@ -26,7 +27,6 @@ use crate::{ validator::Validator, ProcessId, }; -use zingo_common_components::protocol::activation_heights::for_test; /// Zcashd configuration /// @@ -45,7 +45,7 @@ pub struct ZcashdConfig { /// Zcashd RPC listen port pub rpc_listen_port: Option, /// Local network upgrade activation heights - pub configured_activation_heights: ConfiguredActivationHeights, + pub activation_heights: ActivationHeights, /// Miner address pub miner_address: Option<&'static str>, /// Chain cache path @@ -56,7 +56,7 @@ impl Default for ZcashdConfig { fn default() -> Self { Self { rpc_listen_port: None, - configured_activation_heights: for_test::all_height_one_nus(), + activation_heights: ActivationHeights::default(), miner_address: Some(REG_O_ADDR_FROM_ABANDONART), chain_cache: None, } @@ -67,7 +67,7 @@ impl ValidatorConfig for ZcashdConfig { fn set_test_parameters( &mut self, mine_to_pool: PoolType, - configured_activation_heights: ConfiguredActivationHeights, + activation_heights: ActivationHeights, chain_cache: Option, ) { self.miner_address = Some(match mine_to_pool { @@ -75,7 +75,7 @@ impl ValidatorConfig for ZcashdConfig { PoolType::SAPLING => REG_Z_ADDR_FROM_ABANDONART, PoolType::Transparent => REG_T_ADDR_FROM_ABANDONART, }); - self.configured_activation_heights = configured_activation_heights; + self.activation_heights = activation_heights; self.chain_cache = chain_cache; } } @@ -134,18 +134,24 @@ impl Process for Zcashd { let data_dir = tempfile::tempdir().unwrap(); if let Some(cache) = config.chain_cache.clone() { - Self::load_chain(cache, data_dir.path().to_path_buf(), NetworkKind::Regtest); + Self::load_chain( + cache, + data_dir.path().to_path_buf(), + NetworkType::Regtest(ActivationHeights::default()), + ); } - let configured_activation_heights = &config.configured_activation_heights; - tracing::info!("Configuring zcashd to regtest with these activation heights: {configured_activation_heights:?}"); + let activation_heights = config.activation_heights; + tracing::info!( + "Configuring zcashd to regtest with these activation heights: {activation_heights:?}" + ); let port = network::pick_unused_port(config.rpc_listen_port); let config_dir = tempfile::tempdir().unwrap(); let config_file_path = config::write_zcashd_config( config_dir.path(), port, - configured_activation_heights, + activation_heights, config.miner_address, ) .unwrap(); @@ -230,7 +236,7 @@ impl Process for Zcashd { } impl Validator for Zcashd { - async fn get_activation_heights(&self) -> ConfiguredActivationHeights { + async fn get_activation_heights(&self) -> ActivationHeights { let output = self .zcash_cli_command(&["getblockchaininfo"]) .expect("getblockchaininfo should succeed"); @@ -284,14 +290,14 @@ impl Validator for Zcashd { self.config_dir.path().join(config::ZCASHD_FILENAME) } - fn network(&self) -> NetworkKind { + fn network(&self) -> NetworkType { unimplemented!(); } fn load_chain( chain_cache: PathBuf, validator_data_dir: PathBuf, - _validator_network: NetworkKind, + _validator_network: NetworkType, ) -> PathBuf { let regtest_dir = chain_cache.clone().join("regtest"); assert!(regtest_dir.exists(), "regtest directory not found!"); diff --git a/zcash_local_net/src/validator/zebrad.rs b/zcash_local_net/src/validator/zebrad.rs index 4591a06..7028809 100644 --- a/zcash_local_net/src/validator/zebrad.rs +++ b/zcash_local_net/src/validator/zebrad.rs @@ -7,11 +7,15 @@ use crate::{ logs::{self, LogsToDir, LogsToStdoutAndStderr as _}, network, process::Process, - utils::executable_finder::{pick_command, trace_version_and_location, EXPECT_SPAWN}, + utils::{ + executable_finder::{pick_command, trace_version_and_location, EXPECT_SPAWN}, + type_conversions::zingo_to_zebra_activation_heights, + }, validator::{Validator, ValidatorConfig}, ProcessId, }; use zcash_protocol::PoolType; +use zingo_common_components::protocol::{ActivationHeights, NetworkType}; use zingo_test_vectors::ZEBRAD_DEFAULT_MINER; use std::{ @@ -23,7 +27,6 @@ use std::{ use getset::{CopyGetters, Getters}; use portpicker::Port; use tempfile::TempDir; -use zebra_chain::parameters::{self, testnet::ConfiguredActivationHeights, NetworkKind}; use zebra_chain::serialization::ZcashSerialize as _; use zebra_node_services::rpc_client::RpcRequestClient; use zebra_rpc::{ @@ -54,14 +57,12 @@ pub struct ZebradConfig { pub rpc_listen_port: Option, /// Zebrad gRPC listen port pub indexer_listen_port: Option, - /// Local network upgrade activation heights - pub configured_activation_heights: ConfiguredActivationHeights, /// Miner address pub miner_address: String, /// Chain cache path pub chain_cache: Option, /// Network type - pub network: NetworkKind, + pub network_type: NetworkType, } impl Default for ZebradConfig { @@ -70,21 +71,9 @@ impl Default for ZebradConfig { network_listen_port: None, rpc_listen_port: None, indexer_listen_port: None, - configured_activation_heights: ConfiguredActivationHeights { - before_overwinter: Some(1), - overwinter: Some(1), - sapling: Some(1), - blossom: Some(1), - heartwood: Some(1), - canopy: Some(1), - nu5: Some(1), - nu6: Some(1), - nu6_1: Some(1), - nu7: None, - }, miner_address: ZEBRAD_DEFAULT_MINER.to_string(), chain_cache: None, - network: NetworkKind::Regtest, + network_type: NetworkType::Regtest(ActivationHeights::default()), } } } @@ -97,9 +86,8 @@ impl ZebradConfig { } /// Sets the validator to run in regtest mode, with the specified activation heights. - pub fn with_regtest_enabled(mut self, activation_heights: ConfiguredActivationHeights) -> Self { - self.network = NetworkKind::Regtest; - self.configured_activation_heights = activation_heights; + pub fn with_regtest_enabled(mut self, activation_heights: ActivationHeights) -> Self { + self.network_type = NetworkType::Regtest(activation_heights); self } } @@ -108,11 +96,11 @@ impl ValidatorConfig for ZebradConfig { fn set_test_parameters( &mut self, mine_to_pool: PoolType, - configured_activation_heights: ConfiguredActivationHeights, + activation_heights: ActivationHeights, chain_cache: Option, ) { assert_eq!(mine_to_pool, PoolType::Transparent, "Zebra can only mine to transparent using this test infrastructure currently, but tried to set to {mine_to_pool}"); - self.configured_activation_heights = configured_activation_heights; + self.network_type = NetworkType::Regtest(activation_heights); self.chain_cache = chain_cache; } } @@ -141,13 +129,10 @@ pub struct Zebrad { logs_dir: TempDir, /// Data directory data_dir: TempDir, - /// Network upgrade activation heights - #[getset(skip)] - configured_activation_heights: ConfiguredActivationHeights, /// RPC request client client: RpcRequestClient, /// Network type - network: NetworkKind, + network: NetworkType, } impl LogsToDir for Zebrad { @@ -165,14 +150,14 @@ impl Process for Zebrad { let data_dir = tempfile::tempdir().unwrap(); assert!( - matches!(config.network, NetworkKind::Regtest) || config.chain_cache.is_some(), + matches!(config.network_type, NetworkType::Regtest(_)) || config.chain_cache.is_some(), "chain cache must be specified when not using a regtest network!" ); let working_cache_dir = data_dir.path().to_path_buf(); if let Some(src) = config.chain_cache.as_ref() { - Self::load_chain(src.clone(), working_cache_dir.clone(), config.network); + Self::load_chain(src.clone(), working_cache_dir.clone(), config.network_type); } let network_listen_port = network::pick_unused_port(config.network_listen_port); @@ -185,16 +170,19 @@ impl Process for Zebrad { network_listen_port, rpc_listen_port, indexer_listen_port, - &config.configured_activation_heights, &config.miner_address, - config.network, + config.network_type, ) .unwrap(); // create zcashd conf necessary for lightwalletd config::write_zcashd_config( config_dir.path(), rpc_listen_port, - &config.configured_activation_heights, + if let NetworkType::Regtest(activation_heights) = config.network_type { + activation_heights + } else { + ActivationHeights::default() + }, None, ) .unwrap(); @@ -257,12 +245,11 @@ impl Process for Zebrad { config_dir, logs_dir, data_dir, - configured_activation_heights: config.configured_activation_heights, client, - network: config.network, + network: config.network_type, }; - if config.chain_cache.is_none() && matches!(config.network, NetworkKind::Regtest) { + if config.chain_cache.is_none() && matches!(config.network_type, NetworkType::Regtest(_)) { // generate genesis block zebrad.generate_blocks(1).await.unwrap(); } @@ -282,7 +269,7 @@ impl Process for Zebrad { } impl Validator for Zebrad { - async fn get_activation_heights(&self) -> ConfiguredActivationHeights { + async fn get_activation_heights(&self) -> ActivationHeights { let response: serde_json::Value = self .client .json_result_from_call("getblockchaininfo", "[]".to_string()) @@ -300,6 +287,9 @@ impl Validator for Zebrad { async fn generate_blocks(&self, n: u32) -> std::io::Result<()> { let chain_height = self.get_chain_height().await; + let NetworkType::Regtest(activation_heights) = self.network() else { + panic!("Can only generate blocks on regtest networks!"); + }; for _ in 0..n { let block_template: BlockTemplateResponse = self @@ -308,20 +298,8 @@ impl Validator for Zebrad { .await .expect("response should be success output with a serialized `GetBlockTemplate`"); - let network = parameters::Network::new_regtest( - ConfiguredActivationHeights { - before_overwinter: self.configured_activation_heights.before_overwinter, - overwinter: self.configured_activation_heights.overwinter, - sapling: self.configured_activation_heights.sapling, - blossom: self.configured_activation_heights.blossom, - heartwood: self.configured_activation_heights.heartwood, - canopy: self.configured_activation_heights.canopy, - nu5: self.configured_activation_heights.nu5, - nu6: self.configured_activation_heights.nu6, - nu6_1: self.configured_activation_heights.nu6_1, - nu7: self.configured_activation_heights.nu7, - } - .into(), + let network = zebra_chain::parameters::Network::new_regtest( + zingo_to_zebra_activation_heights(*activation_heights).into(), ); let block_data = hex::encode( @@ -387,19 +365,19 @@ impl Validator for Zebrad { self.config_dir.path().join(config::ZCASHD_FILENAME) } - fn network(&self) -> NetworkKind { + fn network(&self) -> NetworkType { self.network } fn load_chain( chain_cache: PathBuf, validator_data_dir: PathBuf, - validator_network: NetworkKind, + validator_network: NetworkType, ) -> PathBuf { let state_dir = chain_cache.clone().join("state"); assert!(state_dir.exists(), "state directory not found!"); - if matches!(validator_network, NetworkKind::Regtest) { + if matches!(validator_network, NetworkType::Regtest(_)) { std::process::Command::new("cp") .arg("-r") .arg(state_dir)