Merge branch 'main' into impl-Params-from-zcash-protocol

This commit is contained in:
Marek 2024-04-24 17:30:23 +02:00
commit 8a7dcedca7
21 changed files with 230 additions and 116 deletions

View File

@ -78,8 +78,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
# TODO: Windows was removed for now, see https://github.com/ZcashFoundation/zebra/issues/3801 os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
rust: [stable, beta] rust: [stable, beta]
# TODO: When vars.EXPERIMENTAL_FEATURES has features in it, add it here. # 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. # Or work out a way to trim the space from the variable: GitHub doesn't allow empty variables.

View File

@ -239,7 +239,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -250,7 +250,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -415,7 +415,7 @@ dependencies = [
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
"syn 2.0.59", "syn 2.0.60",
"which", "which",
] ]
@ -811,7 +811,7 @@ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -1072,14 +1072,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
name = "cxx" name = "cxx"
version = "1.0.107" version = "1.0.113"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe98ba1789d56fb3db3bee5e032774d4f421b685de7ba703643584ba24effbe" checksum = "048948e14bc2c2652ec606c8e3bb913407f0187288fb351a0b2d972beaf12070"
dependencies = [ dependencies = [
"cc", "cc",
"cxxbridge-flags", "cxxbridge-flags",
@ -1089,31 +1089,31 @@ dependencies = [
[[package]] [[package]]
name = "cxx-gen" name = "cxx-gen"
version = "0.7.117" version = "0.7.121"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54b629c0d006c7e44c1444dd17d18a458c9390d32276b758ac7abd21a75c99b0" checksum = "383ecb9f96a536a1c7a2a61c5786f583da84f9240da149d78d005a4413c9a71e"
dependencies = [ dependencies = [
"codespan-reporting", "codespan-reporting",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
name = "cxxbridge-flags" name = "cxxbridge-flags"
version = "1.0.107" version = "1.0.113"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20888d9e1d2298e2ff473cee30efe7d5036e437857ab68bbfea84c74dba91da2" checksum = "af40b0467c68d3d9fb7550ef984edc8ad47252f703ef0f1f2d1052e0e4af8793"
[[package]] [[package]]
name = "cxxbridge-macro" name = "cxxbridge-macro"
version = "1.0.107" version = "1.0.113"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fa16a70dd58129e4dfffdff535fb1bce66673f7bbeec4a5a1765a504e1ccd84" checksum = "7743446286141c9f6d4497c493c01234eb848e14d2e20866ae9811eae0630cb9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -1161,7 +1161,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim 0.10.0", "strsim 0.10.0",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -1183,7 +1183,7 @@ checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be"
dependencies = [ dependencies = [
"darling_core 0.20.6", "darling_core 0.20.6",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -1256,7 +1256,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -1561,7 +1561,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -2629,7 +2629,7 @@ checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -3064,7 +3064,7 @@ dependencies = [
"pest_meta", "pest_meta",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -3105,7 +3105,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -3206,7 +3206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -3329,7 +3329,7 @@ dependencies = [
"prost", "prost",
"prost-types", "prost-types",
"regex", "regex",
"syn 2.0.59", "syn 2.0.60",
"tempfile", "tempfile",
"which", "which",
] ]
@ -3344,7 +3344,7 @@ dependencies = [
"itertools 0.12.1", "itertools 0.12.1",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -4028,9 +4028,9 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.197" version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -4046,20 +4046,20 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.197" version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.115" version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
dependencies = [ dependencies = [
"indexmap 2.2.6", "indexmap 2.2.6",
"itoa", "itoa",
@ -4137,7 +4137,7 @@ dependencies = [
"darling 0.20.6", "darling 0.20.6",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -4366,9 +4366,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.59" version = "2.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4452,29 +4452,29 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
name = "thread-priority" name = "thread-priority"
version = "0.16.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a617e9eeeb20448b01a8e2427fb80dfbc9c49d79a1de3b11f25731edbf547e3c" checksum = "599e8e829c2314b750ecade9309ecc6cf9a48c2e62fe25680b6c1d2172463ca3"
dependencies = [ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"cfg-if 1.0.0", "cfg-if 1.0.0",
@ -4590,7 +4590,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -4774,7 +4774,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"prost-build", "prost-build",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -4787,7 +4787,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"prost-build", "prost-build",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -4917,7 +4917,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -5355,7 +5355,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -5389,7 +5389,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -5670,9 +5670,9 @@ dependencies = [
[[package]] [[package]]
name = "zcash_client_backend" name = "zcash_client_backend"
version = "0.10.0-rc.4" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc33f71747a93d509f7e1c047961e359a271bdf4869cc07f7f65ee1ba7df8c2" checksum = "d6a382af39be9ee5a3788157145c404b7cd19acc440903f6c34b09fb44f0e991"
dependencies = [ dependencies = [
"base64 0.21.7", "base64 0.21.7",
"bech32", "bech32",
@ -5737,9 +5737,9 @@ dependencies = [
[[package]] [[package]]
name = "zcash_primitives" name = "zcash_primitives"
version = "0.13.0-rc.1" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc4391d9325e0a51a7cbff02b5c4b5472d66087bd9c903ddb12dea7ec22f3e0" checksum = "d17e4c94ca8d69d2fcf2be97522da5732a580eb2125cda3b150761952f8df8e6"
dependencies = [ dependencies = [
"aes", "aes",
"bip0039", "bip0039",
@ -5773,9 +5773,9 @@ dependencies = [
[[package]] [[package]]
name = "zcash_proofs" name = "zcash_proofs"
version = "0.13.0-rc.1" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48f22eff3bdc382327ef28f809024ddc89ec6d903ba71be629b2cbea34afdda2" checksum = "df0c99f65a840ff256c106b28d67d702d9759d206112473d4982c92003262406"
dependencies = [ dependencies = [
"bellman", "bellman",
"blake2b_simd", "blake2b_simd",
@ -5804,9 +5804,9 @@ dependencies = [
[[package]] [[package]]
name = "zcash_script" name = "zcash_script"
version = "0.1.14" version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8deff8ea47cbe2a008abefedc1a2d9c0e48a87844379759ace270a0b53353c71" checksum = "9e3de6aece21108f502f724183955d244e02338613eaa4f9010386c63618a3a8"
dependencies = [ dependencies = [
"bellman", "bellman",
"bindgen", "bindgen",
@ -6188,7 +6188,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
"structopt", "structopt",
"syn 2.0.59", "syn 2.0.60",
"thiserror", "thiserror",
"tinyvec", "tinyvec",
"tokio", "tokio",
@ -6289,7 +6289,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]
[[package]] [[package]]
@ -6309,5 +6309,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.59", "syn 2.0.60",
] ]

View File

@ -97,7 +97,7 @@ orchard = "0.6.0"
zcash_encoding = "0.2.0" zcash_encoding = "0.2.0"
zcash_history = "0.4.0" zcash_history = "0.4.0"
zcash_note_encryption = "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"] }
zcash_protocol = { version = "0.1.1" } zcash_protocol = { version = "0.1.1" }
zcash_address = { version = "0.3.2" } zcash_address = { version = "0.3.2" }
@ -108,12 +108,12 @@ humantime = "2.1.0"
# Error Handling & Formatting # Error Handling & Formatting
displaydoc = "0.2.4" displaydoc = "0.2.4"
static_assertions = "1.1.0" static_assertions = "1.1.0"
thiserror = "1.0.58" thiserror = "1.0.59"
tracing = "0.1.39" tracing = "0.1.39"
# Serialization # Serialization
hex = { version = "0.4.3", features = ["serde"] } hex = { version = "0.4.3", features = ["serde"] }
serde = { version = "1.0.196", features = ["serde_derive", "rc"] } serde = { version = "1.0.198", features = ["serde_derive", "rc"] }
serde_with = "3.7.0" serde_with = "3.7.0"
serde-big-array = "0.5.1" serde-big-array = "0.5.1"
@ -128,7 +128,7 @@ redjubjub = "0.7.0"
reddsa = "0.5.1" reddsa = "0.5.1"
# Production feature json-conversion # Production feature json-conversion
serde_json = { version = "1.0.115", optional = true } serde_json = { version = "1.0.116", optional = true }
# Production feature async-error and testing feature proptest-impl # Production feature async-error and testing feature proptest-impl
tokio = { version = "1.37.0", optional = true } tokio = { version = "1.37.0", optional = true }

View File

@ -140,15 +140,13 @@ impl fmt::Display for NetworkKind {
} }
} }
impl From<&Network> for &'static str { impl<'a> From<&'a Network> for &'a str {
fn from(network: &Network) -> &'static str { fn from(network: &'a Network) -> &'a str {
match network { match network {
Network::Mainnet => "Mainnet", Network::Mainnet => "Mainnet",
// TODO: // TODO:
// - Add a `name` field to use here instead of checking `is_default_testnet()`
// - zcashd calls the Regtest cache dir 'regtest' (#8327). // - zcashd calls the Regtest cache dir 'regtest' (#8327).
Network::Testnet(params) if params.is_default_testnet() => "Testnet", Network::Testnet(params) => params.network_name(),
Network::Testnet(_params) => "UnknownTestnet",
} }
} }
} }

View File

@ -1,5 +1,5 @@
//! Types and implementation for Testnet consensus parameters //! Types and implementation for Testnet consensus parameters
use std::collections::BTreeMap; use std::{collections::BTreeMap, fmt};
use zcash_primitives::constants as zp_constants; 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. /// Configurable activation heights for Regtest and configured Testnets.
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]
#[serde(rename_all = "PascalCase")] #[serde(rename_all = "PascalCase")]
@ -35,6 +48,8 @@ pub struct ConfiguredActivationHeights {
/// Builder for the [`Parameters`] struct. /// Builder for the [`Parameters`] struct.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct ParametersBuilder { 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. /// The network upgrade activation heights for this network, see [`Parameters::activation_heights`] for more details.
activation_heights: BTreeMap<Height, NetworkUpgrade>, activation_heights: BTreeMap<Height, NetworkUpgrade>,
/// Sapling extended spending key human-readable prefix for this network /// Sapling extended spending key human-readable prefix for this network
@ -48,6 +63,7 @@ pub struct ParametersBuilder {
impl Default for ParametersBuilder { impl Default for ParametersBuilder {
fn default() -> Self { fn default() -> Self {
Self { Self {
network_name: "UnknownTestnet".to_string(),
// # Correctness // # Correctness
// //
// `Genesis` network upgrade activation height must always be 0 // `Genesis` network upgrade activation height must always be 0
@ -69,9 +85,33 @@ impl Default for ParametersBuilder {
} }
impl 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 /// Checks that the provided network upgrade activation heights are in the correct order, then
/// sets them as the new network upgrade activation heights. /// sets them as the new network upgrade activation heights.
pub fn activation_heights( pub fn with_activation_heights(
mut self, mut self,
ConfiguredActivationHeights { ConfiguredActivationHeights {
// TODO: Find out if `BeforeOverwinter` is required at Height(1), allow for // 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(heartwood.into_iter().map(|h| (h, Heartwood)))
.chain(canopy.into_iter().map(|h| (h, Canopy))) .chain(canopy.into_iter().map(|h| (h, Canopy)))
.chain(nu5.into_iter().map(|h| (h, Nu5))) .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)) .map(|(h, nu)| (h.try_into().expect("activation height must be valid"), nu))
.collect(); .collect();
@ -136,12 +175,14 @@ impl ParametersBuilder {
/// Converts the builder to a [`Parameters`] struct /// Converts the builder to a [`Parameters`] struct
pub fn finish(self) -> Parameters { pub fn finish(self) -> Parameters {
let Self { let Self {
network_name,
activation_heights, activation_heights,
hrp_sapling_extended_spending_key, hrp_sapling_extended_spending_key,
hrp_sapling_extended_full_viewing_key, hrp_sapling_extended_full_viewing_key,
hrp_sapling_payment_address, hrp_sapling_payment_address,
} = self; } = self;
Parameters { Parameters {
network_name,
activation_heights, activation_heights,
hrp_sapling_extended_spending_key, hrp_sapling_extended_spending_key,
hrp_sapling_extended_full_viewing_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. /// Network consensus parameters for test networks such as Regtest and the default Testnet.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Parameters { 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. /// The network upgrade activation heights for this network.
/// ///
/// Note: This value is ignored by `Network::activation_list()` when `zebra-chain` is /// 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`]. /// Returns an instance of the default public testnet [`Parameters`].
fn default() -> Self { fn default() -> Self {
Self { Self {
network_name: "Testnet".to_string(),
activation_heights: TESTNET_ACTIVATION_HEIGHTS.iter().cloned().collect(), activation_heights: TESTNET_ACTIVATION_HEIGHTS.iter().cloned().collect(),
hrp_sapling_extended_spending_key: ..Self::build().finish()
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(),
} }
} }
} }
@ -198,6 +237,11 @@ impl Parameters {
self == &Self::default() self == &Self::default()
} }
/// Returns the network name
pub fn network_name(&self) -> &str {
&self.network_name
}
/// Returns the network upgrade activation heights /// Returns the network upgrade activation heights
pub fn activation_heights(&self) -> &BTreeMap<Height, NetworkUpgrade> { pub fn activation_heights(&self) -> &BTreeMap<Height, NetworkUpgrade> {
&self.activation_heights &self.activation_heights

View File

@ -5,7 +5,9 @@ use zcash_primitives::consensus::{self as zp_consensus, Parameters};
use crate::{ use crate::{
block::Height, block::Height,
parameters::{ parameters::{
testnet::{self, ConfiguredActivationHeights}, testnet::{
self, ConfiguredActivationHeights, MAX_NETWORK_NAME_LENGTH, RESERVED_NETWORK_NAMES,
},
Network, NetworkUpgrade, NETWORK_UPGRADES_IN_ORDER, Network, NetworkUpgrade, NETWORK_UPGRADES_IN_ORDER,
}, },
}; };
@ -97,7 +99,7 @@ fn check_parameters_impl() {
fn activates_network_upgrades_correctly() { fn activates_network_upgrades_correctly() {
let expected_activation_height = 1; let expected_activation_height = 1;
let network = testnet::Parameters::build() let network = testnet::Parameters::build()
.activation_heights(ConfiguredActivationHeights { .with_activation_heights(ConfiguredActivationHeights {
nu5: Some(expected_activation_height), nu5: Some(expected_activation_height),
..Default::default() ..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"
);
}

View File

@ -47,12 +47,12 @@ chrono = { version = "0.4.38", default-features = false, features = ["clock", "s
displaydoc = "0.2.4" displaydoc = "0.2.4"
lazy_static = "1.4.0" lazy_static = "1.4.0"
once_cell = "1.18.0" once_cell = "1.18.0"
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
futures = "0.3.30" futures = "0.3.30"
futures-util = "0.3.28" futures-util = "0.3.28"
metrics = "0.22.3" metrics = "0.22.3"
thiserror = "1.0.58" thiserror = "1.0.59"
tokio = { version = "1.37.0", features = ["time", "sync", "tracing", "rt-multi-thread"] } tokio = { version = "1.37.0", features = ["time", "sync", "tracing", "rt-multi-thread"] }
tower = { version = "0.4.13", features = ["timeout", "util", "buffer"] } tower = { version = "0.4.13", features = ["timeout", "util", "buffer"] }
tracing = "0.1.39" tracing = "0.1.39"

View File

@ -20,13 +20,13 @@ futures-util = "0.3.28"
tonic = "0.11.0" tonic = "0.11.0"
tonic-reflection = "0.11.0" tonic-reflection = "0.11.0"
prost = "0.12.4" prost = "0.12.4"
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = "0.1.15" tokio-stream = "0.1.15"
tower = { version = "0.4.13", features = ["util", "buffer"] } tower = { version = "0.4.13", features = ["util", "buffer"] }
color-eyre = "0.6.3" 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-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" } zebra-chain = { path = "../zebra-chain" , version = "1.0.0-beta.36" }

View File

@ -56,9 +56,9 @@ pin-project = "1.1.5"
rand = "0.8.5" rand = "0.8.5"
rayon = "1.10.0" rayon = "1.10.0"
regex = "1.10.4" regex = "1.10.4"
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
tempfile = "3.10.1" tempfile = "3.10.1"
thiserror = "1.0.58" thiserror = "1.0.59"
futures = "0.3.30" futures = "0.3.30"
tokio = { version = "1.37.0", features = ["fs", "io-util", "net", "time", "tracing", "macros", "rt-multi-thread"] } tokio = { version = "1.37.0", features = ["fs", "io-util", "net", "time", "tracing", "macros", "rt-multi-thread"] }

View File

@ -629,8 +629,9 @@ impl<'de> Deserialize<'de> for Config {
{ {
#[derive(Deserialize)] #[derive(Deserialize)]
struct DTestnetParameters { struct DTestnetParameters {
network_name: Option<String>,
#[serde(default)] #[serde(default)]
pub(super) activation_heights: ConfiguredActivationHeights, activation_heights: ConfiguredActivationHeights,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -678,15 +679,25 @@ impl<'de> Deserialize<'de> for Config {
} = DConfig::deserialize(deserializer)?; } = DConfig::deserialize(deserializer)?;
// TODO: Panic here if the initial testnet peers are the default initial testnet peers. // 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!( assert_eq!(
network_kind, network_kind,
NetworkKind::Testnet, NetworkKind::Testnet,
"set network to 'Testnet' to use configured testnet parameters" "set network to 'Testnet' to use configured testnet parameters"
); );
testnet::Parameters::build() let mut params_builder = testnet::Parameters::build();
.activation_heights(activation_heights)
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() .to_network()
} else { } else {
// Convert to default `Network` for a `NetworkKind` if there are no testnet parameters. // Convert to default `Network` for a `NetworkKind` if there are no testnet parameters.

View File

@ -46,8 +46,8 @@ color-eyre = { version = "0.6.3", optional = true }
jsonrpc-core = { version = "18.0.0", optional = true } jsonrpc-core = { version = "18.0.0", optional = true }
# Security: avoid default dependency on openssl # Security: avoid default dependency on openssl
reqwest = { version = "0.11.26", default-features = false, features = ["rustls-tls"], optional = true } reqwest = { version = "0.11.26", default-features = false, features = ["rustls-tls"], optional = true }
serde = { version = "1.0.196", optional = true } serde = { version = "1.0.198", optional = true }
serde_json = { version = "1.0.115", optional = true } serde_json = { version = "1.0.116", optional = true }
tokio = { version = "1.37.0", features = ["time"], optional = true } tokio = { version = "1.37.0", features = ["time"], optional = true }
[dev-dependencies] [dev-dependencies]
@ -55,5 +55,5 @@ tokio = { version = "1.37.0", features = ["time"], optional = true }
color-eyre = "0.6.3" color-eyre = "0.6.3"
jsonrpc-core = "18.0.0" jsonrpc-core = "18.0.0"
reqwest = { version = "0.11.26", default-features = false, features = ["rustls-tls"] } reqwest = { version = "0.11.26", default-features = false, features = ["rustls-tls"] }
serde = "1.0.196" serde = "1.0.198"
serde_json = "1.0.115" serde_json = "1.0.116"

View File

@ -53,7 +53,7 @@ jsonrpc-derive = "18.0.0"
jsonrpc-http-server = "18.0.0" jsonrpc-http-server = "18.0.0"
# zebra-rpc needs the preserve_order feature in serde_json, which is a dependency of jsonrpc-core # zebra-rpc needs the preserve_order feature in serde_json, which is a dependency of jsonrpc-core
serde_json = { version = "1.0.115", features = ["preserve_order"] } serde_json = { version = "1.0.116", features = ["preserve_order"] }
indexmap = { version = "2.2.6", features = ["serde"] } indexmap = { version = "2.2.6", features = ["serde"] }
tokio = { version = "1.37.0", features = ["time", "rt-multi-thread", "macros", "tracing"] } tokio = { version = "1.37.0", features = ["time", "rt-multi-thread", "macros", "tracing"] }
@ -62,7 +62,7 @@ tower = "0.4.13"
tracing = "0.1.39" tracing = "0.1.39"
hex = { version = "0.4.3", features = ["serde"] } hex = { version = "0.4.3", features = ["serde"] }
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
# Experimental feature getblocktemplate-rpcs # Experimental feature getblocktemplate-rpcs
rand = { version = "0.8.5", optional = true } rand = { version = "0.8.5", optional = true }
@ -84,7 +84,7 @@ insta = { version = "1.38.0", features = ["redactions", "json", "ron"] }
proptest = "1.4.0" proptest = "1.4.0"
thiserror = "1.0.58" thiserror = "1.0.59"
tokio = { version = "1.37.0", features = ["full", "tracing", "test-util"] } tokio = { version = "1.37.0", features = ["full", "tracing", "test-util"] }
zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36", features = ["proptest-impl"] } zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36", features = ["proptest-impl"] }

View File

@ -23,13 +23,14 @@ use super::super::*;
/// Test that the JSON-RPC server spawns when configured with a single thread. /// Test that the JSON-RPC server spawns when configured with a single thread.
#[test] #[test]
#[cfg(not(target_os = "windows"))]
fn rpc_server_spawn_single_thread() { fn rpc_server_spawn_single_thread() {
rpc_server_spawn(false) rpc_server_spawn(false)
} }
/// Test that the JSON-RPC server spawns when configured with multiple threads. /// Test that the JSON-RPC server spawns when configured with multiple threads.
#[test] #[test]
fn rpc_sever_spawn_parallel_threads() { fn rpc_server_spawn_parallel_threads() {
rpc_server_spawn(true) rpc_server_spawn(true)
} }

View File

@ -45,14 +45,14 @@ color-eyre = "0.6.3"
indexmap = { version = "2.2.6", features = ["serde"] } indexmap = { version = "2.2.6", features = ["serde"] }
itertools = "0.12.1" itertools = "0.12.1"
semver = "1.0.22" semver = "1.0.22"
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
tokio = { version = "1.37.0", features = ["time"] } tokio = { version = "1.37.0", features = ["time"] }
tower = "0.4.13" tower = "0.4.13"
tracing = "0.1.39" tracing = "0.1.39"
futures = "0.3.30" futures = "0.3.30"
zcash_client_backend = "0.10.0-rc.1" 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-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"] } zebra-state = { path = "../zebra-state", version = "1.0.0-beta.36", features = ["shielded-scan"] }

View File

@ -15,11 +15,11 @@ keywords = ["zebra", "zcash"]
categories = ["api-bindings", "cryptography::cryptocurrencies"] categories = ["api-bindings", "cryptography::cryptocurrencies"]
[dependencies] [dependencies]
zcash_script = "0.1.14" zcash_script = "0.1.15"
zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36" } zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36" }
thiserror = "1.0.58" thiserror = "1.0.59"
displaydoc = "0.2.4" displaydoc = "0.2.4"
[dev-dependencies] [dev-dependencies]

View File

@ -63,9 +63,9 @@ regex = "1.10.4"
rlimit = "0.10.1" rlimit = "0.10.1"
rocksdb = { version = "0.22.0", default-features = false, features = ["lz4"] } rocksdb = { version = "0.22.0", default-features = false, features = ["lz4"] }
semver = "1.0.22" semver = "1.0.22"
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
tempfile = "3.10.1" tempfile = "3.10.1"
thiserror = "1.0.58" thiserror = "1.0.59"
rayon = "1.10.0" rayon = "1.10.0"
tokio = { version = "1.37.0", features = ["rt-multi-thread", "sync", "tracing"] } tokio = { version = "1.37.0", features = ["rt-multi-thread", "sync", "tracing"] }
@ -75,7 +75,7 @@ tracing = "0.1.39"
# elasticsearch specific dependencies. # elasticsearch specific dependencies.
# Security: avoid default dependency on openssl # Security: avoid default dependency on openssl
elasticsearch = { version = "8.5.0-alpha.1", default-features = false, features = ["rustls-tls"], optional = true } elasticsearch = { version = "8.5.0-alpha.1", default-features = false, features = ["rustls-tls"], optional = true }
serde_json = { version = "1.0.115", package = "serde_json", optional = true } serde_json = { version = "1.0.116", package = "serde_json", optional = true }
zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36", features = ["async-error"] } zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36", features = ["async-error"] }

View File

@ -37,7 +37,7 @@ tinyvec = { version = "1.6.0", features = ["rustc_1_55"] }
humantime = "2.1.0" humantime = "2.1.0"
owo-colors = "4.0.0" owo-colors = "4.0.0"
spandoc = "0.2.2" spandoc = "0.2.2"
thiserror = "1.0.58" thiserror = "1.0.59"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-error = "0.2.0" tracing-error = "0.2.0"

View File

@ -95,10 +95,10 @@ tinyvec = { version = "1.6.0", features = ["rustc_1_55"] }
structopt = "0.3.26" structopt = "0.3.26"
hex = "0.4.3" hex = "0.4.3"
serde_json = "1.0.115" serde_json = "1.0.116"
tracing-error = "0.2.0" tracing-error = "0.2.0"
tracing-subscriber = "0.3.18" tracing-subscriber = "0.3.18"
thiserror = "1.0.58" thiserror = "1.0.59"
zebra-node-services = { path = "../zebra-node-services", version = "1.0.0-beta.36" } zebra-node-services = { path = "../zebra-node-services", version = "1.0.0-beta.36" }
zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36" } zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.36" }
@ -120,11 +120,11 @@ tokio = { version = "1.37.0", features = ["full"], optional = true }
jsonrpc = { version = "0.18.0", 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} zcash_client_backend = {version = "0.10.0-rc.1", optional = true}
# For the openapi generator # For the openapi generator
syn = { version = "2.0.58", features = ["full"], optional = true } syn = { version = "2.0.60", features = ["full"], optional = true }
quote = { version = "1.0.36", optional = true } quote = { version = "1.0.36", optional = true }
serde_yaml = { version = "0.9.34+deprecated", optional = true } serde_yaml = { version = "0.9.34+deprecated", optional = true }
serde = { version = "1.0.196", features = ["serde_derive"], optional = true } serde = { version = "1.0.198", features = ["serde_derive"], optional = true }

View File

@ -178,7 +178,7 @@ humantime-serde = "1.1.1"
indexmap = "2.2.6" indexmap = "2.2.6"
lazy_static = "1.4.0" lazy_static = "1.4.0"
semver = "1.0.22" semver = "1.0.22"
serde = { version = "1.0.196", features = ["serde_derive"] } serde = { version = "1.0.198", features = ["serde_derive"] }
toml = "0.8.11" toml = "0.8.11"
futures = "0.3.30" futures = "0.3.30"
@ -193,7 +193,7 @@ color-eyre = { version = "0.6.3", default-features = false, features = ["issue-u
# Enable a feature that makes tinyvec compile much faster. # Enable a feature that makes tinyvec compile much faster.
tinyvec = { version = "1.6.0", features = ["rustc_1_55"] } tinyvec = { version = "1.6.0", features = ["rustc_1_55"] }
thiserror = "1.0.58" thiserror = "1.0.59"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-appender = "0.2.3" tracing-appender = "0.2.3"
@ -210,7 +210,7 @@ num-integer = "0.1.46"
rand = "0.8.5" rand = "0.8.5"
# prod feature internal-miner # prod feature internal-miner
thread-priority = { version = "0.16.0", optional = true } thread-priority = { version = "1.0.0", optional = true }
# prod feature sentry # prod feature sentry
sentry = { version = "0.32.2", default-features = false, features = ["backtrace", "contexts", "reqwest", "rustls", "tracing"], optional = true } sentry = { version = "0.32.2", default-features = false, features = ["backtrace", "contexts", "reqwest", "rustls", "tracing"], optional = true }
@ -261,7 +261,7 @@ regex = "1.10.4"
insta = { version = "1.38.0", features = ["json"] } insta = { version = "1.38.0", features = ["json"] }
# zebra-rpc needs the preserve_order feature, it also makes test results more stable # zebra-rpc needs the preserve_order feature, it also makes test results more stable
serde_json = { version = "1.0.115", features = ["preserve_order"] } serde_json = { version = "1.0.116", features = ["preserve_order"] }
tempfile = "3.10.1" tempfile = "3.10.1"
hyper = { version = "0.14.28", features = ["http1", "http2", "server"]} hyper = { version = "0.14.28", features = ["http1", "http2", "server"]}

View File

@ -622,6 +622,7 @@ fn config_tests() -> Result<()> {
invalid_generated_config()?; invalid_generated_config()?;
// Check that we have a current version of the config stored // Check that we have a current version of the config stored
#[cfg(not(target_os = "windows"))]
last_config_is_stored()?; last_config_is_stored()?;
// Check that Zebra's previous configurations still work // Check that Zebra's previous configurations still work

View File

@ -60,6 +60,9 @@ max_connections_per_ip = 1
network = "Testnet" network = "Testnet"
peerset_initial_target_size = 25 peerset_initial_target_size = 25
[network.testnet_parameters]
network_name = "ConfiguredTestnet_1"
[network.testnet_parameters.activation_heights] [network.testnet_parameters.activation_heights]
BeforeOverwinter = 1 BeforeOverwinter = 1
Overwinter = 207_500 Overwinter = 207_500