From 74319ec47746656c09b48c23e97de7580ddb893a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 19:32:06 +0000 Subject: [PATCH 1/3] build(deps): bump rustls from 0.21.10 to 0.21.11 in the cargo group (#8418) Bumps the cargo group with 1 update: [rustls](https://github.com/rustls/rustls). Updates `rustls` from 0.21.10 to 0.21.11 - [Release notes](https://github.com/rustls/rustls/releases) - [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustls/rustls/compare/v/0.21.10...v/0.21.11) --- updated-dependencies: - dependency-name: rustls dependency-type: indirect dependency-group: cargo ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e33c79bc1..a4a1730f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3809,9 +3809,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.21.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" dependencies = [ "log", "ring 0.17.8", From 8cf0b7a36a1089441c099cfb8d5acad57c92b076 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 22 Apr 2024 19:07:04 -0300 Subject: [PATCH 2/3] bump(zcash_script): Bump zcash script v0.1.15 and restore Windows support (#8393) * update zcash_script and zcash_primitives * restore windows support * add a windows config file * try exact output from CI * ignore config test in windows * disable test for windows * remove test for windows * change zcash_script branch to release * bump top the last zcash_script release version * restore `rejection_restores_internal_state_genesis` test * fix typo in test name and enable single thread on windows * disable single thread --- .github/workflows/ci-unit-tests-os.yml | 3 +-- Cargo.lock | 32 +++++++++++++------------- zebra-chain/Cargo.toml | 2 +- zebra-grpc/Cargo.toml | 2 +- zebra-rpc/src/server/tests/vectors.rs | 3 ++- zebra-scan/Cargo.toml | 2 +- zebra-script/Cargo.toml | 2 +- zebra-utils/Cargo.toml | 2 +- zebrad/tests/acceptance.rs | 1 + 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci-unit-tests-os.yml b/.github/workflows/ci-unit-tests-os.yml index c75c7e3e4..1d332e4d1 100644 --- a/.github/workflows/ci-unit-tests-os.yml +++ b/.github/workflows/ci-unit-tests-os.yml @@ -78,8 +78,7 @@ jobs: strategy: fail-fast: false matrix: - # TODO: Windows was removed for now, see https://github.com/ZcashFoundation/zebra/issues/3801 - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] rust: [stable, beta] # TODO: When vars.EXPERIMENTAL_FEATURES has features in it, add it here. # Or work out a way to trim the space from the variable: GitHub doesn't allow empty variables. diff --git a/Cargo.lock b/Cargo.lock index a4a1730f1..baab5fced 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1077,9 +1077,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.107" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe98ba1789d56fb3db3bee5e032774d4f421b685de7ba703643584ba24effbe" +checksum = "048948e14bc2c2652ec606c8e3bb913407f0187288fb351a0b2d972beaf12070" dependencies = [ "cc", "cxxbridge-flags", @@ -1089,9 +1089,9 @@ dependencies = [ [[package]] name = "cxx-gen" -version = "0.7.117" +version = "0.7.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b629c0d006c7e44c1444dd17d18a458c9390d32276b758ac7abd21a75c99b0" +checksum = "383ecb9f96a536a1c7a2a61c5786f583da84f9240da149d78d005a4413c9a71e" dependencies = [ "codespan-reporting", "proc-macro2", @@ -1101,15 +1101,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.107" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20888d9e1d2298e2ff473cee30efe7d5036e437857ab68bbfea84c74dba91da2" +checksum = "af40b0467c68d3d9fb7550ef984edc8ad47252f703ef0f1f2d1052e0e4af8793" [[package]] name = "cxxbridge-macro" -version = "1.0.107" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fa16a70dd58129e4dfffdff535fb1bce66673f7bbeec4a5a1765a504e1ccd84" +checksum = "7743446286141c9f6d4497c493c01234eb848e14d2e20866ae9811eae0630cb9" dependencies = [ "proc-macro2", "quote", @@ -5670,9 +5670,9 @@ dependencies = [ [[package]] name = "zcash_client_backend" -version = "0.10.0-rc.4" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc33f71747a93d509f7e1c047961e359a271bdf4869cc07f7f65ee1ba7df8c2" +checksum = "d6a382af39be9ee5a3788157145c404b7cd19acc440903f6c34b09fb44f0e991" dependencies = [ "base64 0.21.7", "bech32", @@ -5737,9 +5737,9 @@ dependencies = [ [[package]] name = "zcash_primitives" -version = "0.13.0-rc.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc4391d9325e0a51a7cbff02b5c4b5472d66087bd9c903ddb12dea7ec22f3e0" +checksum = "d17e4c94ca8d69d2fcf2be97522da5732a580eb2125cda3b150761952f8df8e6" dependencies = [ "aes", "bip0039", @@ -5773,9 +5773,9 @@ dependencies = [ [[package]] name = "zcash_proofs" -version = "0.13.0-rc.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f22eff3bdc382327ef28f809024ddc89ec6d903ba71be629b2cbea34afdda2" +checksum = "df0c99f65a840ff256c106b28d67d702d9759d206112473d4982c92003262406" dependencies = [ "bellman", "blake2b_simd", @@ -5804,9 +5804,9 @@ dependencies = [ [[package]] name = "zcash_script" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8deff8ea47cbe2a008abefedc1a2d9c0e48a87844379759ace270a0b53353c71" +checksum = "9e3de6aece21108f502f724183955d244e02338613eaa4f9010386c63618a3a8" dependencies = [ "bellman", "bindgen", diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index 2abde7524..bcc7430e8 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -97,7 +97,7 @@ orchard = "0.6.0" zcash_encoding = "0.2.0" zcash_history = "0.4.0" zcash_note_encryption = "0.4.0" -zcash_primitives = { version = "0.13.0-rc.1", features = ["transparent-inputs"] } +zcash_primitives = { version = "0.13.0", features = ["transparent-inputs"] } # Time chrono = { version = "0.4.38", default-features = false, features = ["clock", "std", "serde"] } diff --git a/zebra-grpc/Cargo.toml b/zebra-grpc/Cargo.toml index 1d3203b7c..44a0fbc46 100644 --- a/zebra-grpc/Cargo.toml +++ b/zebra-grpc/Cargo.toml @@ -26,7 +26,7 @@ tokio-stream = "0.1.15" tower = { version = "0.4.13", features = ["util", "buffer"] } color-eyre = "0.6.3" -zcash_primitives = { version = "0.13.0-rc.1" } +zcash_primitives = { version = "0.13.0" } zebra-node-services = { path = "../zebra-node-services", version = "1.0.0-beta.36", features = ["shielded-scan"] } zebra-chain = { path = "../zebra-chain" , version = "1.0.0-beta.36" } diff --git a/zebra-rpc/src/server/tests/vectors.rs b/zebra-rpc/src/server/tests/vectors.rs index 2622b84ba..0f4aca010 100644 --- a/zebra-rpc/src/server/tests/vectors.rs +++ b/zebra-rpc/src/server/tests/vectors.rs @@ -23,13 +23,14 @@ use super::super::*; /// Test that the JSON-RPC server spawns when configured with a single thread. #[test] +#[cfg(not(target_os = "windows"))] fn rpc_server_spawn_single_thread() { rpc_server_spawn(false) } /// Test that the JSON-RPC server spawns when configured with multiple threads. #[test] -fn rpc_sever_spawn_parallel_threads() { +fn rpc_server_spawn_parallel_threads() { rpc_server_spawn(true) } diff --git a/zebra-scan/Cargo.toml b/zebra-scan/Cargo.toml index 2cd00ac59..5d05c0f0c 100644 --- a/zebra-scan/Cargo.toml +++ b/zebra-scan/Cargo.toml @@ -52,7 +52,7 @@ tracing = "0.1.39" futures = "0.3.30" zcash_client_backend = "0.10.0-rc.1" -zcash_primitives = "0.13.0-rc.1" +zcash_primitives = "0.13.0" zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36", features = ["shielded-scan"] } zebra-state = { path = "../zebra-state", version = "1.0.0-beta.36", features = ["shielded-scan"] } diff --git a/zebra-script/Cargo.toml b/zebra-script/Cargo.toml index 9e95e1797..da6932cdc 100644 --- a/zebra-script/Cargo.toml +++ b/zebra-script/Cargo.toml @@ -15,7 +15,7 @@ keywords = ["zebra", "zcash"] categories = ["api-bindings", "cryptography::cryptocurrencies"] [dependencies] -zcash_script = "0.1.14" +zcash_script = "0.1.15" zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36" } diff --git a/zebra-utils/Cargo.toml b/zebra-utils/Cargo.toml index 88a99c2dc..658e6789d 100644 --- a/zebra-utils/Cargo.toml +++ b/zebra-utils/Cargo.toml @@ -120,7 +120,7 @@ tokio = { version = "1.37.0", features = ["full"], optional = true } jsonrpc = { version = "0.18.0", optional = true } -zcash_primitives = { version = "0.13.0-rc.1", optional = true } +zcash_primitives = { version = "0.13.0", optional = true } zcash_client_backend = {version = "0.10.0-rc.1", optional = true} # For the openapi generator diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index eb6a27917..6c9115d9e 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -622,6 +622,7 @@ fn config_tests() -> Result<()> { invalid_generated_config()?; // Check that we have a current version of the config stored + #[cfg(not(target_os = "windows"))] last_config_is_stored()?; // Check that Zebra's previous configurations still work From 275e99ec72efe444d258f6db86e27d0dc5d0d747 Mon Sep 17 00:00:00 2001 From: Arya Date: Wed, 24 Apr 2024 07:03:37 -0400 Subject: [PATCH 3/3] add(chain): Adds a `network_name` field to `testnet::Parameters` (#8411) * minor cleanup and rename * Adds an empty NetworkParameters struct to Network::Testnet variant, updates production code. * Updates tests * Adds `NetworkKind` and uses it instead of `Network` in `HistoryTreeParts` and `transparent::Address` * Adds a [network.testnet_parameters] section to the config, uses `NetworkKind` as zebra_network::Config::network field type, and converts 'Network' to `NetworkKind` before serializing * Applies some suggestions from code review * Applies suggestions from code review * returns b58 prefix constants directly to remove From impl for zcash_primitives::consensus::Network * Applies more suggestions from code review. * moves conversions to zcash_primitives::consensus::Network to where they're used. * Apply suggestions from code review Co-authored-by: Marek * rename `network` variables and method names typed as NetworkKind to `network_kind` * use only test block heights for the network associated with them * Applies more suggestions from code review. * Rename `NetworkParameters` to `Parameters` and move it a new `testnet` module * adds activation heights field * updates stored test config, adds a quicker test for checking that stored configs can be parsed, adds an intermediate representation of activation heights * implement Parameters for Network * Passes &Network directly instead of converting to zp_consensus::Network where there were conversions * fixes a bad merge (removes a network conversion in zcash_note_encryption) * Adds a test for the Parameters impl for zebra_chain::Network * fixes doc links * - Makes the `activation_heights` config field optional by adding a #[serde(default)] - Panics if a non-zero activation height is provided for the `Genesis` network upgrade - Always sets the `Genesis` and `BeforeOverwinter` network upgrade activation heights to 0 and 1, `BeforeOverwinter` could be overwritten by a later network upgrade - Makes the `activation_heights` field on `Parameters` private, adds/uses an accessor method instead, and adds a builder struct and `build()` method * small refactor of activation_heights() method * check that activation heights are in the right order * Updates `NetworkUpgrade::activation_height()` to return the height of the next NetworkUpgrade if it doesn't find the activation height of `&self` * checks that the miner address is of TestnetKind on Regtest and update assertion message * Adds a DNetworkUpgradeActivationHeights struct for better control over how activation heights can be configured * moves all ordered network upgrades to a constant, adds a no_duplicates test, moves struct with activation heights outside deserialization impl and accepts it in `ParametersBuilder::activation_heights()` instead of a Vec * panics if any network upgrades are configured to activate at Height(0) because it's reserved for Genesis * Simplifies the `ParametersBuilder::activation_heights()` method and removes an unnecessary test. * Adds Sapling HRPs as fields on testnet params. (#8398) * Applies suggestions from code review. * Update zebra-chain/src/parameters/network_upgrade.rs Co-authored-by: Marek * Adds `network_name` field and accessor method on `Parameters`, uses it in the `Display` impl for `Network` * Removes unnecessary `.filter()` * adds constraints on valid network names and a test * adds config field for setting network name, adds "with_" prefix to ParameterBuilder setter methods * Adds `MainnetKind`, `TestnetKind`, and `RegtestKind` to reserved network names * updates stored test configs and fixes `network_name()` docs --------- Co-authored-by: Marek --- zebra-chain/src/parameters/network.rs | 8 +-- zebra-chain/src/parameters/network/testnet.rs | 62 ++++++++++++++++--- .../src/parameters/network/tests/vectors.rs | 61 +++++++++++++++++- zebra-network/src/config.rs | 19 ++++-- zebrad/tests/common/configs/v1.7.0.toml | 3 + 5 files changed, 133 insertions(+), 20 deletions(-) diff --git a/zebra-chain/src/parameters/network.rs b/zebra-chain/src/parameters/network.rs index 47bcf68e8..e346e28e6 100644 --- a/zebra-chain/src/parameters/network.rs +++ b/zebra-chain/src/parameters/network.rs @@ -138,15 +138,13 @@ impl fmt::Display for NetworkKind { } } -impl From<&Network> for &'static str { - fn from(network: &Network) -> &'static str { +impl<'a> From<&'a Network> for &'a str { + fn from(network: &'a Network) -> &'a str { match network { Network::Mainnet => "Mainnet", // TODO: - // - Add a `name` field to use here instead of checking `is_default_testnet()` // - zcashd calls the Regtest cache dir 'regtest' (#8327). - Network::Testnet(params) if params.is_default_testnet() => "Testnet", - Network::Testnet(_params) => "UnknownTestnet", + Network::Testnet(params) => params.network_name(), } } } diff --git a/zebra-chain/src/parameters/network/testnet.rs b/zebra-chain/src/parameters/network/testnet.rs index 1a1b47001..7cc936927 100644 --- a/zebra-chain/src/parameters/network/testnet.rs +++ b/zebra-chain/src/parameters/network/testnet.rs @@ -1,5 +1,5 @@ //! Types and implementation for Testnet consensus parameters -use std::collections::BTreeMap; +use std::{collections::BTreeMap, fmt}; use zcash_primitives::constants as zp_constants; @@ -11,6 +11,19 @@ use crate::{ }, }; +/// Reserved network names that should not be allowed for configured Testnets. +pub const RESERVED_NETWORK_NAMES: [&str; 6] = [ + "Mainnet", + "Testnet", + "Regtest", + "MainnetKind", + "TestnetKind", + "RegtestKind", +]; + +/// Maximum length for a configured network name. +pub const MAX_NETWORK_NAME_LENGTH: usize = 30; + /// Configurable activation heights for Regtest and configured Testnets. #[derive(Deserialize, Default)] #[serde(rename_all = "PascalCase")] @@ -35,6 +48,8 @@ pub struct ConfiguredActivationHeights { /// Builder for the [`Parameters`] struct. #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] pub struct ParametersBuilder { + /// The name of this network to be used by the `Display` trait impl. + network_name: String, /// The network upgrade activation heights for this network, see [`Parameters::activation_heights`] for more details. activation_heights: BTreeMap, /// Sapling extended spending key human-readable prefix for this network @@ -48,6 +63,7 @@ pub struct ParametersBuilder { impl Default for ParametersBuilder { fn default() -> Self { Self { + network_name: "UnknownTestnet".to_string(), // # Correctness // // `Genesis` network upgrade activation height must always be 0 @@ -69,9 +85,33 @@ impl Default for ParametersBuilder { } impl ParametersBuilder { + /// Sets the network name to be used in the [`Parameters`] being built. + pub fn with_network_name(mut self, network_name: impl fmt::Display) -> Self { + self.network_name = network_name.to_string(); + + assert!( + !RESERVED_NETWORK_NAMES.contains(&self.network_name.as_str()), + "cannot use reserved network name '{network_name}' as configured Testnet name, reserved names: {RESERVED_NETWORK_NAMES:?}" + ); + + assert!( + self.network_name.len() <= MAX_NETWORK_NAME_LENGTH, + "network name {network_name} is too long, must be {MAX_NETWORK_NAME_LENGTH} characters or less" + ); + + assert!( + self.network_name + .chars() + .all(|x| x.is_alphanumeric() || x == '_'), + "network name must include only alphanumeric characters or '_'" + ); + + self + } + /// Checks that the provided network upgrade activation heights are in the correct order, then /// sets them as the new network upgrade activation heights. - pub fn activation_heights( + pub fn with_activation_heights( mut self, ConfiguredActivationHeights { // TODO: Find out if `BeforeOverwinter` is required at Height(1), allow for @@ -99,7 +139,6 @@ impl ParametersBuilder { .chain(heartwood.into_iter().map(|h| (h, Heartwood))) .chain(canopy.into_iter().map(|h| (h, Canopy))) .chain(nu5.into_iter().map(|h| (h, Nu5))) - .filter(|&(_, nu)| nu != NetworkUpgrade::BeforeOverwinter) .map(|(h, nu)| (h.try_into().expect("activation height must be valid"), nu)) .collect(); @@ -136,12 +175,14 @@ impl ParametersBuilder { /// Converts the builder to a [`Parameters`] struct pub fn finish(self) -> Parameters { let Self { + network_name, activation_heights, hrp_sapling_extended_spending_key, hrp_sapling_extended_full_viewing_key, hrp_sapling_payment_address, } = self; Parameters { + network_name, activation_heights, hrp_sapling_extended_spending_key, hrp_sapling_extended_full_viewing_key, @@ -158,6 +199,8 @@ impl ParametersBuilder { /// Network consensus parameters for test networks such as Regtest and the default Testnet. #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] pub struct Parameters { + /// The name of this network to be used by the `Display` trait impl. + network_name: String, /// The network upgrade activation heights for this network. /// /// Note: This value is ignored by `Network::activation_list()` when `zebra-chain` is @@ -176,13 +219,9 @@ impl Default for Parameters { /// Returns an instance of the default public testnet [`Parameters`]. fn default() -> Self { Self { + network_name: "Testnet".to_string(), activation_heights: TESTNET_ACTIVATION_HEIGHTS.iter().cloned().collect(), - hrp_sapling_extended_spending_key: - zp_constants::testnet::HRP_SAPLING_EXTENDED_SPENDING_KEY.to_string(), - hrp_sapling_extended_full_viewing_key: - zp_constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY.to_string(), - hrp_sapling_payment_address: zp_constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS - .to_string(), + ..Self::build().finish() } } } @@ -198,6 +237,11 @@ impl Parameters { self == &Self::default() } + /// Returns the network name + pub fn network_name(&self) -> &str { + &self.network_name + } + /// Returns the network upgrade activation heights pub fn activation_heights(&self) -> &BTreeMap { &self.activation_heights diff --git a/zebra-chain/src/parameters/network/tests/vectors.rs b/zebra-chain/src/parameters/network/tests/vectors.rs index b6fca27c2..1d619aa5e 100644 --- a/zebra-chain/src/parameters/network/tests/vectors.rs +++ b/zebra-chain/src/parameters/network/tests/vectors.rs @@ -5,7 +5,9 @@ use zcash_primitives::consensus::{self as zp_consensus, Parameters}; use crate::{ block::Height, parameters::{ - testnet::{self, ConfiguredActivationHeights}, + testnet::{ + self, ConfiguredActivationHeights, MAX_NETWORK_NAME_LENGTH, RESERVED_NETWORK_NAMES, + }, Network, NetworkUpgrade, NETWORK_UPGRADES_IN_ORDER, }, }; @@ -97,7 +99,7 @@ fn check_parameters_impl() { fn activates_network_upgrades_correctly() { let expected_activation_height = 1; let network = testnet::Parameters::build() - .activation_heights(ConfiguredActivationHeights { + .with_activation_heights(ConfiguredActivationHeights { nu5: Some(expected_activation_height), ..Default::default() }) @@ -125,3 +127,58 @@ fn activates_network_upgrades_correctly() { ); } } + +/// Checks that configured testnet names are validated and used correctly. +#[test] +fn check_network_name() { + // Sets a no-op panic hook to avoid long output. + std::panic::set_hook(Box::new(|_| {})); + + // Checks that reserved network names cannot be used for configured testnets. + for reserved_network_name in RESERVED_NETWORK_NAMES { + std::panic::catch_unwind(|| { + testnet::Parameters::build().with_network_name(reserved_network_name) + }) + .expect_err("should panic when attempting to set network name as a reserved name"); + } + + // Check that max length is enforced, and that network names may only contain alphanumeric characters and '_'. + for invalid_network_name in [ + "a".repeat(MAX_NETWORK_NAME_LENGTH + 1), + "!!!!non-alphanumeric-name".to_string(), + ] { + std::panic::catch_unwind(|| { + testnet::Parameters::build().with_network_name(invalid_network_name) + }) + .expect_err("should panic when setting network name that's too long or contains non-alphanumeric characters (except '_')"); + } + + // Checks that network names are displayed correctly + assert_eq!( + Network::new_default_testnet().to_string(), + "Testnet", + "default testnet should be displayed as 'Testnet'" + ); + assert_eq!( + Network::Mainnet.to_string(), + "Mainnet", + "Mainnet should be displayed as 'Mainnet'" + ); + + // TODO: Check Regtest + + // Check that network name can contain alphanumeric characters and '_'. + let expected_name = "ConfiguredTestnet_1"; + let network = testnet::Parameters::build() + // Check that network name can contain `MAX_NETWORK_NAME_LENGTH` characters + .with_network_name("a".repeat(MAX_NETWORK_NAME_LENGTH)) + .with_network_name(expected_name) + .to_network(); + + // Check that configured network name is displayed + assert_eq!( + network.to_string(), + expected_name, + "network must be displayed as configured network name" + ); +} diff --git a/zebra-network/src/config.rs b/zebra-network/src/config.rs index fa1e20568..e32f6c138 100644 --- a/zebra-network/src/config.rs +++ b/zebra-network/src/config.rs @@ -629,8 +629,9 @@ impl<'de> Deserialize<'de> for Config { { #[derive(Deserialize)] struct DTestnetParameters { + network_name: Option, #[serde(default)] - pub(super) activation_heights: ConfiguredActivationHeights, + activation_heights: ConfiguredActivationHeights, } #[derive(Deserialize)] @@ -678,15 +679,25 @@ impl<'de> Deserialize<'de> for Config { } = DConfig::deserialize(deserializer)?; // TODO: Panic here if the initial testnet peers are the default initial testnet peers. - let network = if let Some(DTestnetParameters { activation_heights }) = testnet_parameters { + let network = if let Some(DTestnetParameters { + network_name, + activation_heights, + }) = testnet_parameters + { assert_eq!( network_kind, NetworkKind::Testnet, "set network to 'Testnet' to use configured testnet parameters" ); - testnet::Parameters::build() - .activation_heights(activation_heights) + let mut params_builder = testnet::Parameters::build(); + + if let Some(network_name) = network_name { + params_builder = params_builder.with_network_name(network_name) + } + + params_builder + .with_activation_heights(activation_heights) .to_network() } else { // Convert to default `Network` for a `NetworkKind` if there are no testnet parameters. diff --git a/zebrad/tests/common/configs/v1.7.0.toml b/zebrad/tests/common/configs/v1.7.0.toml index 58aed232f..00438213d 100644 --- a/zebrad/tests/common/configs/v1.7.0.toml +++ b/zebrad/tests/common/configs/v1.7.0.toml @@ -60,6 +60,9 @@ max_connections_per_ip = 1 network = "Testnet" peerset_initial_target_size = 25 +[network.testnet_parameters] +network_name = "ConfiguredTestnet_1" + [network.testnet_parameters.activation_heights] BeforeOverwinter = 1 Overwinter = 207_500