Skip to content

Commit

Permalink
fix: update parsing of num_mining_threads config field (#3081)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jul 14, 2021
2 parents a835032 + e81e830 commit 1f20252
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 3 additions & 5 deletions common/src/configuration/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,6 @@ fn convert_node_config(network: Network, cfg: Config) -> Result<GlobalConfig, Co
.get_bool(&key)
.map_err(|e| ConfigurationError::new(&key, &e.to_string()))?;

let key = config_string("base_node", &net_str, "num_mining_threads");
let num_mining_threads = cfg
.get_int(&key)
.map_err(|e| ConfigurationError::new(&key, &e.to_string()))? as usize;

let key = config_string("base_node", &net_str, "flood_ban_max_msg_count");
let flood_ban_max_msg_count = cfg
.get_int(&key)
Expand Down Expand Up @@ -603,6 +598,9 @@ fn convert_node_config(network: Network, cfg: Config) -> Result<GlobalConfig, Co
let key = config_string("merge_mining_proxy", &net_str, "proxy_submit_to_origin");
let proxy_submit_to_origin = cfg.get_bool(&key).unwrap_or(true);

let key = "mining_node.num_mining_threads";
let num_mining_threads = optional(cfg.get_int(&key))?.unwrap_or(1) as usize;

let key = "mining_node.mine_on_tip_only";
let mine_on_tip_only = cfg.get_bool(key).unwrap_or(true);

Expand Down
11 changes: 9 additions & 2 deletions common/src/configuration/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ pub fn load_configuration(bootstrap: &ConfigBootstrap) -> Result<Config, ConfigE
.to_str()
.ok_or_else(|| ConfigError::new("Invalid config file path", None))?;
let config_file = config::File::with_name(filename);

cfg.merge(config_file)
.map_err(|e| ConfigError::new("Failed to parse the configuration file", Some(e.to_string())))?;
info!(target: LOG_TARGET, "Configuration file loaded.");

Ok(cfg)
}

Expand Down Expand Up @@ -164,7 +166,6 @@ pub fn default_config(bootstrap: &ConfigBootstrap) -> Config {
cfg.set_default("base_node.mainnet.grpc_console_wallet_address", "127.0.0.1:18143")
.unwrap();
cfg.set_default("base_node.mainnet.enable_wallet", true).unwrap();
cfg.set_default("base_node.mainnet.num_mining_threads", 1).unwrap();
cfg.set_default("base_node.mainnet.flood_ban_max_msg_count", 10000)
.unwrap();

Expand Down Expand Up @@ -221,7 +222,6 @@ pub fn default_config(bootstrap: &ConfigBootstrap) -> Config {
cfg.set_default("base_node.weatherwax.grpc_console_wallet_address", "127.0.0.1:18143")
.unwrap();
cfg.set_default("base_node.weatherwax.enable_wallet", true).unwrap();
cfg.set_default("base_node.weatherwax.num_mining_threads", 1).unwrap();

cfg.set_default("base_node.weatherwax.dns_seeds_name_server", "1.1.1.1:53")
.unwrap();
Expand All @@ -234,6 +234,7 @@ pub fn default_config(bootstrap: &ConfigBootstrap) -> Config {

set_transport_defaults(&mut cfg);
set_merge_mining_defaults(&mut cfg);
set_mining_node_defaults(&mut cfg);

cfg
}
Expand Down Expand Up @@ -274,6 +275,12 @@ fn set_merge_mining_defaults(cfg: &mut Config) {
.unwrap();
}

fn set_mining_node_defaults(cfg: &mut Config) {
cfg.set_default("mining_node.num_mining_threads", 1).unwrap();
cfg.set_default("mining_node.mine_on_tip_only", true).unwrap();
cfg.set_default("mining_node.validate_tip_timeout_sec", 0).unwrap();
}

fn set_transport_defaults(cfg: &mut Config) {
// Mainnet
// Default transport for mainnet is tcp
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function baseEnvs(peerSeeds = []) {
TARI_BASE_NODE__LOCALNET__DNS_SEEDS_NAME_SERVER: "1.1.1.1:53",
TARI_BASE_NODE__LOCALNET__DNS_SEEDS_USE_DNSSEC: "false",
TARI_BASE_NODE__LOCALNET__BLOCK_SYNC_STRATEGY: "ViaBestChainMetadata",
TARI_BASE_NODE__LOCALNET__NUM_MINING_THREADS: "1",
TARI_BASE_NODE__LOCALNET__ORPHAN_DB_CLEAN_OUT_THRESHOLD: "0",
TARI_BASE_NODE__LOCALNET__MAX_RANDOMX_VMS: "1",
TARI_BASE_NODE__LOCALNET__AUTO_PING_INTERVAL: "15",
Expand All @@ -93,6 +92,7 @@ function baseEnvs(peerSeeds = []) {
TARI_BASE_NODE__LOCALNET__DB_RESIZE_THRESHOLD_MB: 10,
TARI_BASE_NODE__LOCALNET__DB_GROW_SIZE_MB: 20,
TARI_MERGE_MINING_PROXY__LOCALNET__WAIT_FOR_INITIAL_SYNC_AT_STARTUP: false,
TARI_MINING_NODE__NUM_MINING_THREADS: "1",
TARI_MINING_NODE__MINE_ON_TIP_ONLY: true,
TARI_MINING_NODE__VALIDATE_TIP_TIMEOUT_SEC: 2,
TARI_WALLET__SCAN_FOR_UTXO_INTERVAL: 5,
Expand Down

0 comments on commit 1f20252

Please sign in to comment.