From 47cfd3222eb1c891de65aa1e04996015d2610417 Mon Sep 17 00:00:00 2001 From: Luis Rubio Date: Fri, 2 Oct 2020 17:56:03 +0200 Subject: [PATCH] feat(node): enable mainnet environment --- config/src/config.rs | 36 ++++++++++++++++------------------ config/src/defaults.rs | 38 ++++++++++++------------------------ data_structures/src/chain.rs | 2 +- node/tests/config_test.rs | 2 +- witnet.toml | 2 -- 5 files changed, 32 insertions(+), 48 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index 744afc038..5599afa01 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -43,7 +43,7 @@ use std::{collections::HashSet, net::SocketAddr, path::PathBuf, time::Duration}; use serde::{Deserialize, Deserializer, Serialize}; use crate::{ - defaults::{Defaults, Development, Testnet}, + defaults::{Defaults, Development, Mainnet, Testnet}, dirs, }; use partial_struct::PartialStruct; @@ -488,9 +488,7 @@ impl Config { pub fn from_partial(config: &PartialConfig) -> Self { let defaults: &dyn Defaults = match config.environment { Environment::Development => &Development, - Environment::Mainnet => { - panic!("Config with mainnet environment is currently not allowed"); - } + Environment::Mainnet => &Mainnet, Environment::Testnet => &Testnet, }; @@ -1203,59 +1201,59 @@ mod tests { let partial_config = PartialConfig::default(); let config = Config::from_partial(&partial_config); - assert_eq!(config.environment, Environment::Testnet); + assert_eq!(config.environment, Environment::Mainnet); assert_eq!( config.connections.server_addr, - Testnet.connections_server_addr() + Mainnet.connections_server_addr() ); assert_eq!( config.connections.inbound_limit, - Testnet.connections_inbound_limit() + Mainnet.connections_inbound_limit() ); assert_eq!( config.connections.outbound_limit, - Testnet.connections_outbound_limit() + Mainnet.connections_outbound_limit() ); assert_eq!( config.connections.known_peers, - Testnet.connections_known_peers() + Mainnet.connections_known_peers() ); assert_eq!( config.connections.bootstrap_peers_period, - Testnet.connections_bootstrap_peers_period() + Mainnet.connections_bootstrap_peers_period() ); assert_eq!( config.connections.storage_peers_period, - Testnet.connections_storage_peers_period() + Mainnet.connections_storage_peers_period() ); assert_eq!( config.connections.discovery_peers_period, - Testnet.connections_discovery_peers_period() + Mainnet.connections_discovery_peers_period() ); assert_eq!( config.connections.feeler_peers_period, - Testnet.connections_feeler_peers_period() + Mainnet.connections_feeler_peers_period() ); assert_eq!( config.connections.handshake_timeout, - Testnet.connections_handshake_timeout() + Mainnet.connections_handshake_timeout() ); - assert_eq!(config.storage.db_path, Testnet.storage_db_path()); + assert_eq!(config.storage.db_path, Mainnet.storage_db_path()); assert_eq!( config.jsonrpc.server_address, - Testnet.jsonrpc_server_address() + Mainnet.jsonrpc_server_address() ); assert_eq!( config.connections.blocks_timeout, - Testnet.connections_blocks_timeout() + Mainnet.connections_blocks_timeout() ); assert_eq!( config.connections.consensus_c, - Testnet.connections_consensus_c() + Mainnet.connections_consensus_c() ); assert_eq!( config.connections.bucketing_update_period, - Testnet.connections_bucketing_update_period() + Mainnet.connections_bucketing_update_period() ); } } diff --git a/config/src/defaults.rs b/config/src/defaults.rs index 2588dd5f6..7157a3599 100644 --- a/config/src/defaults.rs +++ b/config/src/defaults.rs @@ -128,23 +128,17 @@ pub trait Defaults { } /// Default Hash value for the auxiliary bootstrap block - // TODO Decide an appropriate default value fn consensus_constants_bootstrap_hash(&self) -> Hash { - // Hash::SHA256([0; 32]) - - // Testnet configuration + // FIXME(#1615) Decide an appropriate default value for Mainnet "00000000000000000000000000000000000000007769746e65742d302e392e33" .parse() .unwrap() } /// Default Hash value for the genesis block - // TODO Decide an appropriate default value fn consensus_constants_genesis_hash(&self) -> Hash { - // Hash::SHA256([1; 32]) - - // Testnet configuration - "d103ad5177230297ebe68b276e9e55a6c3abd168f1b671398903819b52f28cc8" + // FIXME(#1615) Decide an appropriate default value for Mainnet + "8b5bcbca3cf45943b550e16b901ad68d2887ee5198e39331c173593e57e0a857" .parse() .unwrap() } @@ -284,10 +278,7 @@ pub trait Defaults { /// Minimum input age of an UTXO for being a valid collateral fn consensus_constants_collateral_age(&self) -> u32 { - // FIXME(#1114): Choose a properly value - // 2000 blocks - - // Testnet configuration + // FIXME(#1615) Decide an appropriate default value for Mainnet 1000 } @@ -298,15 +289,8 @@ pub trait Defaults { /// First superblocks signing committee fn consensus_constants_bootstrapping_committee(&self) -> Vec { - // FIXME(#1114): Choose a proper value for the committee - // [] pkhs - - // Testnet configuration - vec![ - "twit1fulan0j78dmdfa3gx0779kszj5sc5j35feljv5".to_string(), - "twit1zutan0dwtfmfcnv34epvjyhwamny20vkx09zjc".to_string(), - "twit1mengan0dvms7tzcul9epxmat8dh6temdunwkm5".to_string(), - ] + // FIXME(#1615) Decide an appropriate default value for Mainnet + vec!["wit1mengan0dvms7tzcul9epxmat8dh6temdjx8jm9".to_string()] } /// Wallet server address @@ -434,10 +418,14 @@ impl Defaults for Mainnet { PathBuf::from(".witnet") } + fn connections_bootstrap_peers_period(&self) -> Duration { + Duration::from_secs(15) + } + fn consensus_constants_checkpoint_zero_timestamp(&self) -> i64 { - // A point far in the future, so the `EpochManager` will return an error - // `EpochZeroInTheFuture` - 19_999_999_999_999 + // FIXME(#1615) Decide an appropriate default value for Mainnet + // Wednesday, 23-Sept-2020, 09:00 UTC + 1_600_851_600 } } diff --git a/data_structures/src/chain.rs b/data_structures/src/chain.rs index 675c2af64..684b312b5 100644 --- a/data_structures/src/chain.rs +++ b/data_structures/src/chain.rs @@ -84,7 +84,7 @@ pub enum Environment { impl Default for Environment { fn default() -> Environment { - Environment::Testnet + Environment::Mainnet } } diff --git a/node/tests/config_test.rs b/node/tests/config_test.rs index 916349bfa..7f6310966 100644 --- a/node/tests/config_test.rs +++ b/node/tests/config_test.rs @@ -11,7 +11,7 @@ fn test_get_config() { let fut = config_mngr::get() .and_then(|config| { - assert_eq!(Environment::Testnet, config.environment); + assert_eq!(Environment::Mainnet, config.environment); Ok(()) }) diff --git a/witnet.toml b/witnet.toml index 904fc7bcd..ff0d35cbf 100644 --- a/witnet.toml +++ b/witnet.toml @@ -97,7 +97,5 @@ genesis_path = ".witnet/config/genesis_block.json" level = "info" [wallet] -# Tell the wallet component whether it is running on a testnet environment. -testnet = true # The address (IP and port) of a Witnet node's JSON-RPC server. This should normally match `json_rpc.server_address`. node_url = "127.0.0.1:21338"