From 2b7a5fa959a4f019860b3db6eb8de8d4319aad96 Mon Sep 17 00:00:00 2001 From: Stan Date: Mon, 11 Apr 2022 17:03:22 +0400 Subject: [PATCH 1/4] fix: add separator to Environment config source --- common/src/configuration/utils.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/configuration/utils.rs b/common/src/configuration/utils.rs index bb4a5709a6..80f5a01bd9 100644 --- a/common/src/configuration/utils.rs +++ b/common/src/configuration/utils.rs @@ -36,7 +36,11 @@ pub fn load_configuration>( .ok_or_else(|| ConfigError::new("Invalid config file path", None))?; let mut cfg = Config::builder() .add_source(config::File::with_name(filename)) - .add_source(config::Environment::with_prefix("TARI")); + .add_source( + config::Environment::with_prefix("TARI") + .prefix_separator("_") + .separator("__"), + ); for (key, value) in overrides { cfg = cfg From e04117f08195324b460ac8004a3ef80fc496fbd3 Mon Sep 17 00:00:00 2001 From: Stan Date: Mon, 11 Apr 2022 17:32:12 +0400 Subject: [PATCH 2/4] refactor: remove --create-id cli arg --- .../tari_app_utilities/src/identity_management.rs | 9 +++++---- applications/tari_base_node/src/cli.rs | 3 --- applications/tari_base_node/src/main.rs | 12 +----------- applications/tari_validator_node/src/cli.rs | 3 --- applications/tari_validator_node/src/main.rs | 2 +- 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/applications/tari_app_utilities/src/identity_management.rs b/applications/tari_app_utilities/src/identity_management.rs index 4d05fe4dda..093f6a7ecf 100644 --- a/applications/tari_app_utilities/src/identity_management.rs +++ b/applications/tari_app_utilities/src/identity_management.rs @@ -39,10 +39,11 @@ const REQUIRED_IDENTITY_PERMS: u32 = 0o100600; /// Loads the node identity, or creates a new one if the --create-id flag was specified /// /// ## Parameters -/// `identity_file` - Reference to file path -/// `public_address` - Network address of the base node -/// `create_id` - Whether an identity needs to be created or not -/// `peer_features` - Enables features of the base node +/// - `identity_file` - Reference to file path +/// - `public_address` - Network address of the base node +/// - `create_id` - Only applies if the identity_file does not exist or is malformed. If true, a new identity will be +/// created, otherwise the user will be prompted to create a new ID +/// - `peer_features` - Enables features of the base node /// /// # Return /// A NodeIdentity wrapped in an atomic reference counter on success, the exit code indicating the reason on failure diff --git a/applications/tari_base_node/src/cli.rs b/applications/tari_base_node/src/cli.rs index a8ac81a228..34be9b74e4 100644 --- a/applications/tari_base_node/src/cli.rs +++ b/applications/tari_base_node/src/cli.rs @@ -31,9 +31,6 @@ const DEFAULT_NETWORK: &str = "dibbler"; pub(crate) struct Cli { #[clap(flatten)] pub common: CommonCliArgs, - /// Create and save new node identity if one doesn't exist - #[clap(long, alias = "create_id")] - pub create_id: bool, /// Create a default configuration file if it doesn't exist #[clap(long)] pub init: bool, diff --git a/applications/tari_base_node/src/main.rs b/applications/tari_base_node/src/main.rs index 37707d13b6..a6adb6cd63 100644 --- a/applications/tari_base_node/src/main.rs +++ b/applications/tari_base_node/src/main.rs @@ -153,20 +153,10 @@ fn main_inner() -> Result<(), ExitError> { let node_identity = setup_node_identity( &config.base_node.identity_file, config.base_node.p2p.public_address.as_ref(), - cli.create_id || cli.non_interactive_mode, + cli.non_interactive_mode || cli.init, PeerFeatures::COMMUNICATION_NODE, )?; - // Exit if create_id or init arguments were run - if cli.create_id { - info!( - target: LOG_TARGET, - "Base node's node ID created at '{}'. Done.", - config.base_node.identity_file.as_path().to_string_lossy(), - ); - return Ok(()); - } - if cli.init { info!(target: LOG_TARGET, "Default configuration created. Done."); return Ok(()); diff --git a/applications/tari_validator_node/src/cli.rs b/applications/tari_validator_node/src/cli.rs index 4e1fe0debc..bd6922e017 100644 --- a/applications/tari_validator_node/src/cli.rs +++ b/applications/tari_validator_node/src/cli.rs @@ -56,9 +56,6 @@ pub(crate) struct Cli { /// Enable tracing #[clap(long, aliases = &["tracing", "enable-tracing"])] pub tracing_enabled: bool, - /// Create and save new node identity if one doesn't exist - #[clap(long, alias = "create_id")] - pub create_id: bool, /// Supply a network (overrides existing configuration) #[clap(long, alias = "network", default_value = DEFAULT_NETWORK)] pub network: String, diff --git a/applications/tari_validator_node/src/main.rs b/applications/tari_validator_node/src/main.rs index 5896ad8410..bb3ae1b917 100644 --- a/applications/tari_validator_node/src/main.rs +++ b/applications/tari_validator_node/src/main.rs @@ -101,7 +101,7 @@ async fn run_node(config: &ApplicationConfig, cli: Cli) -> Result<(), ExitError> let node_identity = setup_node_identity( &config.validator_node.identity_file, config.validator_node.public_address.as_ref(), - cli.create_id, + true, PeerFeatures::NONE, )?; let db_factory = SqliteDbFactory::new(config.validator_node.data_dir.clone()); From 8cd4a0ea3dcc35f05126fb73627496ab4060b0d9 Mon Sep 17 00:00:00 2001 From: Stan Date: Mon, 11 Apr 2022 17:41:33 +0400 Subject: [PATCH 3/4] fix clippy --- applications/tari_validator_node/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/tari_validator_node/src/main.rs b/applications/tari_validator_node/src/main.rs index bb3ae1b917..dbf3123b2c 100644 --- a/applications/tari_validator_node/src/main.rs +++ b/applications/tari_validator_node/src/main.rs @@ -90,12 +90,12 @@ fn main_inner() -> Result<(), ExitError> { let config = ApplicationConfig::load_from(&cfg)?; let runtime = build_runtime()?; - runtime.block_on(run_node(&config, cli))?; + runtime.block_on(run_node(&config))?; Ok(()) } -async fn run_node(config: &ApplicationConfig, cli: Cli) -> Result<(), ExitError> { +async fn run_node(config: &ApplicationConfig) -> Result<(), ExitError> { let shutdown = Shutdown::new(); let node_identity = setup_node_identity( From d5db280c841e8c33c7be00203761258beb450a62 Mon Sep 17 00:00:00 2001 From: Stan Date: Tue, 12 Apr 2022 09:11:47 +0400 Subject: [PATCH 4/4] remove all references to --create-id --- README.md | 4 ++-- applications/launchpad/docker_rig/quick_start.sh | 2 +- .../tari_app_utilities/src/identity_management.rs | 12 +++++------- applications/tari_base_node/linux/supervisord.md | 2 +- applications/tari_base_node/osx/install.sh | 1 - applications/tari_base_node/osx/post_install.sh | 2 +- applications/tari_base_node/setup.sh | 1 - applications/tari_base_node/src/main.rs | 2 +- .../windows/runtime/source_base_node_env.bat | 2 +- buildtools/docker/start.sh | 2 +- integration_tests/helpers/baseNodeProcess.js | 9 +-------- integration_tests/helpers/validatorNodeProcess.js | 2 +- 12 files changed, 15 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 955faaefce..f4132cc89e 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ start Tor service `~/tari/applications/tari_base_node/osx/start_tor` (on Mac), To run from any directory of your choice, where the executable is visible in the path (first time use): - tari_base_node --init --create-id + tari_base_node --init tari_base_node tari_console_wallet --init @@ -264,7 +264,7 @@ Consecutive runs: Alternatively, you can run the Tari applications from your source directory using `cargo`, and just omit the `--release` flag if you want to run in debug mode (first time use): - cargo run --bin tari_base_node --release -- --init --create-id + cargo run --bin tari_base_node --release -- --init cargo run --bin tari_base_node --release cargo run --bin tari_merge_mining_proxy --release diff --git a/applications/launchpad/docker_rig/quick_start.sh b/applications/launchpad/docker_rig/quick_start.sh index 614dedb87d..990eeee809 100755 --- a/applications/launchpad/docker_rig/quick_start.sh +++ b/applications/launchpad/docker_rig/quick_start.sh @@ -52,7 +52,7 @@ export TARI_NETWORK=$NETWORK if [[ $SETUP == 1 ]]; then echo "Creating identity files and default config file" - docker compose run --rm base_node --create-id --init + docker compose run --rm base_node --init fi if [[ $START_TOR == 1 ]]; then diff --git a/applications/tari_app_utilities/src/identity_management.rs b/applications/tari_app_utilities/src/identity_management.rs index 093f6a7ecf..da597ee5f7 100644 --- a/applications/tari_app_utilities/src/identity_management.rs +++ b/applications/tari_app_utilities/src/identity_management.rs @@ -36,7 +36,7 @@ pub const LOG_TARGET: &str = "tari_application"; const REQUIRED_IDENTITY_PERMS: u32 = 0o100600; -/// Loads the node identity, or creates a new one if the --create-id flag was specified +/// Loads the node identity, or creates a new one if create_id is true /// /// ## Parameters /// - `identity_file` - Reference to file path @@ -65,7 +65,7 @@ pub fn setup_node_identity>( ExitCode::ConfigError, &format!( "{path} has incorrect permissions. You can update the identity file with the correct permissions \ - using 'chmod 600 {path}', or delete the identity file and re-run the node with the --create-id flag.", + using 'chmod 600 {path}', or delete the identity file and a new one will be created on next start", path = identity_file.as_ref().to_string_lossy() ), )), @@ -76,17 +76,15 @@ pub fn setup_node_identity>( if !prompt { error!( target: LOG_TARGET, - "Node identity information not found. {}. You can update the configuration file to point to a \ - valid node identity file, or re-run the node with the --create-id flag to create a new \ - identity.", + "Node identity not found. {}. You can update the configuration file to point to a valid node \ + identity file, or re-run the node and create a new one.", e ); return Err(ExitError::new( ExitCode::ConfigError, &format!( "Node identity information not found. {}. You can update the configuration file to point \ - to a valid node identity file, or re-run the node with the --create-id flag to create a \ - new identity.", + to a valid node identity file, or re-run the node to create a new one", e ), )); diff --git a/applications/tari_base_node/linux/supervisord.md b/applications/tari_base_node/linux/supervisord.md index dba75e34c5..5c30274367 100644 --- a/applications/tari_base_node/linux/supervisord.md +++ b/applications/tari_base_node/linux/supervisord.md @@ -20,7 +20,7 @@ sudo cp -v /home/vagrant/src/tari/target/release/tari_base_node /usr/local/tari ``` Create your tari_base_node configs ``` -sudo /usr/local/tari/bin/tari_base_node --base-path /usr/local/tari --init --create-id +sudo /usr/local/tari/bin/tari_base_node --base-path /usr/local/tari --init ``` Setup ```tari_base_node``` services in supervisord - ```/etc/supervisor/conf.d/tari_base_node.conf``` diff --git a/applications/tari_base_node/osx/install.sh b/applications/tari_base_node/osx/install.sh index daa4ac9409..acbdb4b1b0 100755 --- a/applications/tari_base_node/osx/install.sh +++ b/applications/tari_base_node/osx/install.sh @@ -83,7 +83,6 @@ fi # Configure Base Node ./tari_base_node --init -./tari_base_node --create-id banner Running Tari Base Node # Run Base Node diff --git a/applications/tari_base_node/osx/post_install.sh b/applications/tari_base_node/osx/post_install.sh index 133b4eca3d..472062be44 100755 --- a/applications/tari_base_node/osx/post_install.sh +++ b/applications/tari_base_node/osx/post_install.sh @@ -197,7 +197,7 @@ if [ ! -f "$DATA_DIR/config.toml" ]; then # cp log4rs_sample_base_node.yml $DATA_DIR/log4rs_base_node.yml # Configure Base Node - tari_base_node --init --create-id + tari_base_node --init echo "Configuration complete." fi diff --git a/applications/tari_base_node/setup.sh b/applications/tari_base_node/setup.sh index 0296a5e8bd..d8464fe076 100644 --- a/applications/tari_base_node/setup.sh +++ b/applications/tari_base_node/setup.sh @@ -29,7 +29,6 @@ osascript -e "tell application \"Terminal\" to do script \"sh ${PWD}/start_tor.s # Configure Base Node cd "${INSTALL_ROOT}" || exit tari_base-node --init -tari_base_node --create-id # Run Base Node tari_base_node diff --git a/applications/tari_base_node/src/main.rs b/applications/tari_base_node/src/main.rs index a6adb6cd63..9c3c2b6757 100644 --- a/applications/tari_base_node/src/main.rs +++ b/applications/tari_base_node/src/main.rs @@ -44,7 +44,7 @@ /// ``` /// /// For the first run -/// `cargo run tari_base_node -- --create-id` +/// `cargo run tari_base_node -- --init /// /// Subsequent runs /// `cargo run tari_base_node` diff --git a/applications/tari_base_node/windows/runtime/source_base_node_env.bat b/applications/tari_base_node/windows/runtime/source_base_node_env.bat index 2146186902..a289c61c6c 100644 --- a/applications/tari_base_node/windows/runtime/source_base_node_env.bat +++ b/applications/tari_base_node/windows/runtime/source_base_node_env.bat @@ -61,7 +61,7 @@ if exist "%my_exe_path%\%my_exe%" ( rem First time run if not exist "%config_path%\base_node_id.json" ( - "%base_node%" --create-id --init --config "%config_path%\config.toml" --log_config "%config_path%\log4rs_base_node.yml" --base-path "%base_path%" + "%base_node%" --init --config "%config_path%\config.toml" --log_config "%config_path%\log4rs_base_node.yml" --base-path "%base_path%" echo. echo. echo Created "%config_path%\base_node_id.json". diff --git a/buildtools/docker/start.sh b/buildtools/docker/start.sh index 6b067dd060..2e66aaf38c 100755 --- a/buildtools/docker/start.sh +++ b/buildtools/docker/start.sh @@ -11,7 +11,7 @@ sleep 15 TARI_CONFIG=~/.tari/config/config.toml if [[ ! -f $TARI_CONFIG ]]; then - tari_base_node --init --create-id + tari_base_node --init # fix for docker, bind grpc to 0.0.0.0 instead of loopback sed -i -e 's/127.0.0.1:18142/0.0.0.0:18142/' $TARI_CONFIG fi diff --git a/integration_tests/helpers/baseNodeProcess.js b/integration_tests/helpers/baseNodeProcess.js index 7b552e1cdb..c99844d9f1 100644 --- a/integration_tests/helpers/baseNodeProcess.js +++ b/integration_tests/helpers/baseNodeProcess.js @@ -49,14 +49,7 @@ class BaseNodeProcess { break; } } while (fs.existsSync(this.baseDir)); - const args = [ - "--base-path", - ".", - "--init", - "--create-id", - "--network", - "localnet", - ]; + const args = ["--base-path", ".", "--init", "--network", "localnet"]; const overrides = this.getOverrides(); Object.keys(overrides).forEach((k) => { args.push("-p"); diff --git a/integration_tests/helpers/validatorNodeProcess.js b/integration_tests/helpers/validatorNodeProcess.js index f30d33bb90..c11e9d6c23 100644 --- a/integration_tests/helpers/validatorNodeProcess.js +++ b/integration_tests/helpers/validatorNodeProcess.js @@ -47,7 +47,7 @@ class ValidatorNodeProcess { break; } } while (fs.existsSync(this.baseDir)); - const args = ["--base-path", ".", "--init", "--create-id"]; + const args = ["--base-path", ".", "--init"]; if (this.logFilePath) { args.push("--log-config", this.logFilePath); }