Rename `NetworkParameters` to `Parameters` and move it a new `testnet` module
This commit is contained in:
parent
86cd919135
commit
365b58ea3f
|
@ -21,7 +21,7 @@ mod transaction;
|
|||
pub mod arbitrary;
|
||||
|
||||
pub use genesis::*;
|
||||
pub use network::{Network, NetworkKind, NetworkParameters};
|
||||
pub use network::{testnet, Network, NetworkKind};
|
||||
pub use network_upgrade::*;
|
||||
pub use transaction::*;
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ use crate::{
|
|||
parameters::NetworkUpgrade::Canopy,
|
||||
};
|
||||
|
||||
pub mod testnet;
|
||||
|
||||
#[cfg(any(test, feature = "proptest-impl"))]
|
||||
use proptest_derive::Arbitrary;
|
||||
|
||||
|
@ -53,18 +55,6 @@ mod tests;
|
|||
/// after the grace period.
|
||||
const ZIP_212_GRACE_PERIOD_DURATION: HeightDiff = 32_256;
|
||||
|
||||
/// Network consensus parameters for test networks such as Regtest and the default Testnet.
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
|
||||
pub struct NetworkParameters {}
|
||||
|
||||
impl NetworkParameters {
|
||||
/// Returns true if the instance of [`NetworkParameters`] represents the default public Testnet.
|
||||
pub fn is_default_testnet(&self) -> bool {
|
||||
self == &Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// An enum describing the kind of network, whether it's the production mainnet or a testnet.
|
||||
// Note: The order of these variants is important for correct bincode (de)serialization
|
||||
// of history trees in the db format.
|
||||
|
@ -100,7 +90,7 @@ pub enum Network {
|
|||
|
||||
/// A test network such as the default public testnet,
|
||||
/// a configured testnet, or Regtest.
|
||||
Testnet(Arc<NetworkParameters>),
|
||||
Testnet(Arc<testnet::Parameters>),
|
||||
}
|
||||
|
||||
impl NetworkKind {
|
||||
|
@ -172,13 +162,13 @@ impl fmt::Display for Network {
|
|||
}
|
||||
|
||||
impl Network {
|
||||
/// Creates a new [`Network::Testnet`] with the default Testnet [`NetworkParameters`].
|
||||
/// Creates a new [`Network::Testnet`] with the default Testnet [`testnet::Parameters`].
|
||||
pub fn new_default_testnet() -> Self {
|
||||
Self::Testnet(Arc::new(NetworkParameters::default()))
|
||||
Self::Testnet(Arc::new(testnet::Parameters::default()))
|
||||
}
|
||||
|
||||
/// Creates a new configured [`Network::Testnet`] with the provided Testnet [`NetworkParameters`].
|
||||
pub fn new_configured_testnet(params: NetworkParameters) -> Self {
|
||||
/// Creates a new configured [`Network::Testnet`] with the provided Testnet [`testnet::Parameters`].
|
||||
pub fn new_configured_testnet(params: testnet::Parameters) -> Self {
|
||||
Self::Testnet(Arc::new(params))
|
||||
}
|
||||
|
||||
|
@ -217,7 +207,7 @@ impl Network {
|
|||
pub fn is_max_block_time_enforced(&self, height: block::Height) -> bool {
|
||||
match self {
|
||||
Network::Mainnet => true,
|
||||
// TODO: Move `TESTNET_MAX_TIME_START_HEIGHT` to a field on NetworkParameters (#8364)
|
||||
// TODO: Move `TESTNET_MAX_TIME_START_HEIGHT` to a field on testnet::Parameters (#8364)
|
||||
Network::Testnet(_params) => height >= super::TESTNET_MAX_TIME_START_HEIGHT,
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +216,7 @@ impl Network {
|
|||
pub fn default_port(&self) -> u16 {
|
||||
match self {
|
||||
Network::Mainnet => 8233,
|
||||
// TODO: Add a `default_port` field to `NetworkParameters` to return here. (zcashd uses 18344 for Regtest)
|
||||
// TODO: Add a `default_port` field to `testnet::Parameters` to return here. (zcashd uses 18344 for Regtest)
|
||||
Network::Testnet(_params) => 18233,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
//! Types and implementation for Testnet consensus parameters
|
||||
|
||||
#[cfg(any(test, feature = "proptest-impl"))]
|
||||
use proptest_derive::Arbitrary;
|
||||
|
||||
/// Network consensus parameters for test networks such as Regtest and the default Testnet.
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
|
||||
pub struct Parameters {}
|
||||
|
||||
impl Parameters {
|
||||
/// Returns true if the instance of [`Parameters`] represents the default public Testnet.
|
||||
pub fn is_default_testnet(&self) -> bool {
|
||||
self == &Self::default()
|
||||
}
|
||||
}
|
|
@ -271,7 +271,7 @@ impl Network {
|
|||
};
|
||||
match self {
|
||||
Mainnet => mainnet_heights,
|
||||
// TODO: Add an `activation_heights` field to `NetworkParameters` to return here. (#7970)
|
||||
// TODO: Add an `activation_heights` field to `testnet::Parameters` to return here. (#7970)
|
||||
Testnet(_params) => testnet_heights,
|
||||
}
|
||||
.iter()
|
||||
|
@ -395,7 +395,7 @@ impl NetworkUpgrade {
|
|||
height: block::Height,
|
||||
) -> Option<Duration> {
|
||||
match (network, height) {
|
||||
// TODO: Move `TESTNET_MINIMUM_DIFFICULTY_START_HEIGHT` to a field on NetworkParameters (#8364)
|
||||
// TODO: Move `TESTNET_MINIMUM_DIFFICULTY_START_HEIGHT` to a field on testnet::Parameters (#8364)
|
||||
(Network::Testnet(_params), height)
|
||||
if height < TESTNET_MINIMUM_DIFFICULTY_START_HEIGHT =>
|
||||
{
|
||||
|
|
|
@ -699,7 +699,7 @@ impl ParameterDifficulty for Network {
|
|||
/* 2^243 - 1 */
|
||||
Network::Mainnet => (U256::one() << 243) - 1,
|
||||
/* 2^251 - 1 */
|
||||
// TODO: Add a `target_difficulty_limit` field to `NetworkParameters` to return here.
|
||||
// TODO: Add a `target_difficulty_limit` field to `testnet::Parameters` to return here.
|
||||
Network::Testnet(_params) => (U256::one() << 251) - 1,
|
||||
};
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ impl ParameterCheckpoint for Network {
|
|||
// zcash-cli getblockhash 0
|
||||
Network::Mainnet => "00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08",
|
||||
// zcash-cli -testnet getblockhash 0
|
||||
// TODO: Add a `genesis_hash` field to `NetworkParameters` and return it here (#8366)
|
||||
// TODO: Add a `genesis_hash` field to `testnet::Parameters` and return it here (#8366)
|
||||
Network::Testnet(_params) => {
|
||||
"05a60a92d99d85997cce3b87616c089f6124d7342af37106edc76126334a2c38"
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ impl ParameterCheckpoint for Network {
|
|||
fn checkpoint_list(&self) -> CheckpointList {
|
||||
// parse calls CheckpointList::from_list
|
||||
// TODO:
|
||||
// - Add a `genesis_hash` field to `NetworkParameters` and return it here (#8366)
|
||||
// - Add a `genesis_hash` field to `testnet::Parameters` and return it here (#8366)
|
||||
// - Try to disable checkpoints entirely for regtest and custom testnets
|
||||
let checkpoint_list: CheckpointList = match self {
|
||||
Network::Mainnet => MAINNET_CHECKPOINTS
|
||||
|
|
|
@ -104,7 +104,7 @@ lazy_static! {
|
|||
/// as described in [protocol specification §7.10.1][7.10.1].
|
||||
///
|
||||
/// [7.10.1]: https://zips.z.cash/protocol/protocol.pdf#zip214fundingstreams
|
||||
// TODO: Move the value here to a field on `NetworkParameters` (#8367)
|
||||
// TODO: Move the value here to a field on `testnet::Parameters` (#8367)
|
||||
pub static ref FUNDING_STREAM_HEIGHT_RANGES: HashMap<NetworkKind, std::ops::Range<Height>> = {
|
||||
let mut hash_map = HashMap::new();
|
||||
hash_map.insert(NetworkKind::Mainnet, Height(1_046_400)..Height(2_726_400));
|
||||
|
@ -113,7 +113,7 @@ lazy_static! {
|
|||
};
|
||||
|
||||
/// Convenient storage for all addresses, for all receivers and networks
|
||||
// TODO: Move the value here to a field on `NetworkParameters` (#8367)
|
||||
// TODO: Move the value here to a field on `testnet::Parameters` (#8367)
|
||||
// There are no funding stream addresses on Regtest in zcashd, zebrad should do the same for compatibility.
|
||||
pub static ref FUNDING_STREAM_ADDRESSES: HashMap<NetworkKind, HashMap<FundingStreamReceiver, Vec<String>>> = {
|
||||
let mut addresses_by_network = HashMap::with_capacity(2);
|
||||
|
@ -231,7 +231,7 @@ impl ParameterSubsidy for Network {
|
|||
Network::Mainnet => NetworkUpgrade::Canopy
|
||||
.activation_height(self)
|
||||
.expect("canopy activation height should be available"),
|
||||
// TODO: Check what zcashd does here, consider adding a field to `NetworkParameters` to make this configurable.
|
||||
// TODO: Check what zcashd does here, consider adding a field to `testnet::Parameters` to make this configurable.
|
||||
Network::Testnet(_params) => FIRST_HALVING_TESTNET,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use tempfile::NamedTempFile;
|
|||
use tokio::{fs, io::AsyncWriteExt};
|
||||
use tracing::Span;
|
||||
|
||||
use zebra_chain::parameters::{Network, NetworkKind, NetworkParameters};
|
||||
use zebra_chain::parameters::{testnet, Network, NetworkKind};
|
||||
|
||||
use crate::{
|
||||
constants::{
|
||||
|
@ -630,7 +630,7 @@ impl<'de> Deserialize<'de> for Config {
|
|||
struct DConfig {
|
||||
listen_addr: String,
|
||||
network: NetworkKind,
|
||||
testnet_parameters: Option<NetworkParameters>,
|
||||
testnet_parameters: Option<testnet::Parameters>,
|
||||
initial_mainnet_peers: IndexSet<String>,
|
||||
initial_testnet_peers: IndexSet<String>,
|
||||
cache_dir: CacheDir,
|
||||
|
|
|
@ -393,7 +393,7 @@ lazy_static! {
|
|||
///
|
||||
/// The minimum network protocol version typically changes after Mainnet and
|
||||
/// Testnet network upgrades.
|
||||
// TODO: Move the value here to a field on `NetworkParameters` (#8367)
|
||||
// TODO: Move the value here to a field on `testnet::Parameters` (#8367)
|
||||
pub static ref INITIAL_MIN_NETWORK_PROTOCOL_VERSION: HashMap<NetworkKind, Version> = {
|
||||
let mut hash_map = HashMap::new();
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ impl ParameterMagic for Network {
|
|||
fn magic_value(&self) -> Magic {
|
||||
match self {
|
||||
Network::Mainnet => magics::MAINNET,
|
||||
// TODO: Move `Magic` struct definition to `zebra-chain`, add it as a field in `NetworkParameters`, and return it here.
|
||||
// TODO: Move `Magic` struct definition to `zebra-chain`, add it as a field in `testnet::Parameters`, and return it here.
|
||||
Network::Testnet(_params) => magics::TESTNET,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue