Skip to content

Commit

Permalink
feat(node): enable mainnet environment
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubiorod committed Oct 2, 2020
1 parent 6e4beec commit 47cfd32
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 48 deletions.
36 changes: 17 additions & 19 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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()
);
}
}
38 changes: 13 additions & 25 deletions config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
}

Expand All @@ -298,15 +289,8 @@ pub trait Defaults {

/// First superblocks signing committee
fn consensus_constants_bootstrapping_committee(&self) -> Vec<String> {
// 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
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion data_structures/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub enum Environment {

impl Default for Environment {
fn default() -> Environment {
Environment::Testnet
Environment::Mainnet
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/tests/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
})
Expand Down
2 changes: 0 additions & 2 deletions witnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 47cfd32

Please sign in to comment.