Skip to content

Commit

Permalink
feat: make all apps non interactive (#6049)
Browse files Browse the repository at this point in the history
Description
---
make all applications hnour the` non-interactive` flag 
Make base node non mining config default, and disable grpc server

How Has This Been Tested?
---
manual
  • Loading branch information
SWvheerden authored Dec 14, 2023
1 parent a6929df commit bafd7e7
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 43 deletions.
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() {
fn main_inner() -> Result<(), ExitError> {
let cli = Cli::parse();

let cfg = load_configuration(cli.common.config_path(), true, &cli)?;
let cfg = load_configuration(cli.common.config_path(), true, cli.non_interactive_mode, &cli)?;
initialize_logging(
&cli.common.log_config_path("wallet"),
&cli.common.get_base_path(),
Expand Down
2 changes: 2 additions & 0 deletions applications/minotari_merge_mining_proxy/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use tari_common::configuration::{ConfigOverrideProvider, Network};
pub struct Cli {
#[clap(flatten)]
pub common: CommonCliArgs,
#[clap(short, long, alias = "non-interactive", env = "TARI_NON_INTERACTIVE")]
pub non_interactive_mode: bool,
}

impl ConfigOverrideProvider for Cli {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const LOG_TARGET: &str = "minotari_mm_proxy::proxy";

pub async fn start_merge_miner(cli: Cli) -> Result<(), anyhow::Error> {
let config_path = cli.common.config_path();
let cfg = load_configuration(&config_path, true, &cli)?;
let cfg = load_configuration(&config_path, true, cli.non_interactive_mode, &cli)?;
let mut config = MergeMiningProxyConfig::load_from(&cfg)?;
config.set_base_path(cli.common.get_base_path());

Expand Down
2 changes: 2 additions & 0 deletions applications/minotari_miner/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct Cli {
pub miner_min_diff: Option<u64>,
#[clap(long, alias = "max-difficulty")]
pub miner_max_diff: Option<u64>,
#[clap(short, long, alias = "non-interactive", env = "TARI_NON_INTERACTIVE")]
pub non_interactive_mode: bool,
}

impl ConfigOverrideProvider for Cli {
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub const LOG_TARGET_FILE: &str = "minotari::logging::miner::main";
#[allow(clippy::too_many_lines)]
pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
let config_path = cli.common.config_path();
let cfg = load_configuration(config_path.as_path(), true, &cli)?;
let cfg = load_configuration(config_path.as_path(), true, cli.non_interactive_mode, &cli)?;
let mut config = MinerConfig::load_from(&cfg).expect("Failed to load config");
config.set_base_path(cli.common.get_base_path());

Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn main() {
fn main_inner() -> Result<(), ExitError> {
let cli = Cli::parse();
let config_path = cli.common.config_path();
let cfg = load_configuration(config_path, true, &cli)?;
let cfg = load_configuration(config_path, true, cli.non_interactive_mode, &cli)?;

if cli.profile_with_tokio_console {
console_subscriber::init();
Expand Down
17 changes: 0 additions & 17 deletions common/config/presets/c_base_node_a.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
# help maintain the security of the Minotari token and are the surest way to preserve your privacy and be 100% sure that
# no-one is cheating you out of your money.

[dibbler.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_dibbler.json"

[igor.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_igor.json"
Expand All @@ -28,16 +24,3 @@ identity_file = "config/base_node_id_stagenet.json"
[nextnet.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_nextnet.json"

[base_node]
# Set to false to disable the base node GRPC server (default = true)
#grpc_enabled = true

# The socket to expose for the gRPC base node server (default = "/ip4/127.0.0.1/tcp/18142")
#grpc_address = "/ip4/127.0.0.1/tcp/18142"

# gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# Use gRPC over TLS (default = false)
#grpc_tls_enabled = false
13 changes: 13 additions & 0 deletions common/config/presets/c_base_node_b_mining_deny_methods.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@

[base_node]
# Set to false to disable the base node GRPC server (default = true)
grpc_enabled = true

# The socket to expose for the gRPC base node server (default = "/ip4/127.0.0.1/tcp/18142")
#grpc_address = "/ip4/127.0.0.1/tcp/18142"

# gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# Use gRPC over TLS (default = false)
#grpc_tls_enabled = false

# Uncomment all gRPC server methods that should be denied default (only active when `grpc_enabled = true`)
grpc_server_deny_methods = [
"get_version",
Expand Down
46 changes: 30 additions & 16 deletions common/config/presets/c_base_node_b_non_mining_deny_methods.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@

[base_node]
# Set to false to disable the base node GRPC server (default = true)
grpc_enabled = false

# The socket to expose for the gRPC base node server (default = "/ip4/127.0.0.1/tcp/18142")
#grpc_address = "/ip4/127.0.0.1/tcp/18142"

# gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# Use gRPC over TLS (default = false)
#grpc_tls_enabled = false

# Uncomment all gRPC server methods that should be denied default (only active when `grpc_enabled = true`)
grpc_server_deny_methods = [
"get_version",
Expand All @@ -7,31 +21,31 @@ grpc_server_deny_methods = [
"get_tip_info",
"identify",
"get_network_status",
#"list_headers",
"list_headers",
"get_header_by_hash",
"get_blocks",
"get_block_timing",
"get_constants",
"get_block_size",
"get_block_fees",
#"get_tokens_in_circulation",
#"get_network_difficulty",
"get_tokens_in_circulation",
"get_network_difficulty",
"get_new_block_template",
"get_new_block",
"get_new_block_blob",
#"submit_block",
#"submit_block_blob",
#"submit_transaction",
#"search_kernels,"
#"search_utxos",
#"fetch_matching_utxos",
"submit_block",
"submit_block_blob",
"submit_transaction",
"search_kernels",
"search_utxos",
"fetch_matching_utxos",
"get_peers",
"get_mempool_transactions",
#"transaction_state",
#"list_connected_peers",
#"get_mempool_stats",
#"get_active_validator_nodes",
#"get_shard_key",
#"get_template_registrations",
#"get_side_chain_utxos",
"transaction_state",
"list_connected_peers",
"get_mempool_stats",
"get_active_validator_nodes",
"get_shard_key",
"get_template_registrations",
"get_side_chain_utxos",
]
17 changes: 11 additions & 6 deletions common/src/configuration/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
pub fn load_configuration<P: AsRef<Path>, TOverride: ConfigOverrideProvider>(
config_path: P,
create_if_not_exists: bool,
non_interactive: bool,
overrides: &TOverride,
) -> Result<Config, ConfigError> {
debug!(
Expand All @@ -31,7 +32,7 @@ pub fn load_configuration<P: AsRef<Path>, TOverride: ConfigOverrideProvider>(
config_path.as_ref().to_str().unwrap_or("[??]")
);
if !config_path.as_ref().exists() && create_if_not_exists {
write_default_config_to(&config_path)
write_default_config_to(&config_path, non_interactive)
.map_err(|io| ConfigError::new("Could not create default config", Some(io.to_string())))?;
}
let filename = config_path
Expand Down Expand Up @@ -85,13 +86,17 @@ pub fn load_configuration<P: AsRef<Path>, TOverride: ConfigOverrideProvider>(

/// Installs a new configuration file template, copied from the application type's preset and written to the given path.
/// Also includes the common configuration defined in `config/presets/common.toml`.
pub fn write_default_config_to<P: AsRef<Path>>(path: P) -> Result<(), std::io::Error> {
pub fn write_default_config_to<P: AsRef<Path>>(path: P, non_interactive: bool) -> Result<(), std::io::Error> {
// Use the same config file so that all the settings are easier to find, and easier to
// support users over chat channels
let mine = prompt(
"Node config does not exist.\nWould you like to mine (Y/n)?\nNOTE: this will enable gprc methods that can \
leak private info on the node",
);
let mine = if non_interactive {
false
} else {
prompt(
"Node config does not exist.\nWould you like to mine (Y/n)?\nNOTE: this will enable gprc methods that can \
leak private info on the node",
)
};
let base_node_deny_methods = if mine {
include_str!("../../config/presets/c_base_node_b_mining_deny_methods.toml")
} else {
Expand Down
1 change: 1 addition & 0 deletions integration_tests/src/merge_mining_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl MergeMiningProxyProcess {
("merge_mining_proxy.stealth_payment".to_string(), stealth.to_string()),
],
},
non_interactive_mode: false,
};
let rt = runtime::Builder::new_multi_thread().enable_all().build().unwrap();
if let Err(e) = rt.block_on(merge_miner(cli)) {
Expand Down
1 change: 1 addition & 0 deletions integration_tests/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl MinerProcess {
miner_max_blocks: blocks,
miner_min_diff,
miner_max_diff,
non_interactive_mode: false,
};
run_miner(cli).await.unwrap();
}
Expand Down

0 comments on commit bafd7e7

Please sign in to comment.