diff --git a/clients/native/src/commands/mod.rs b/clients/native/src/commands/mod.rs index 735b314185..08c4f9592d 100644 --- a/clients/native/src/commands/mod.rs +++ b/clients/native/src/commands/mod.rs @@ -24,7 +24,6 @@ use std::net::IpAddr; pub(crate) mod init; pub(crate) mod run; -pub(crate) mod upgrade; lazy_static! { pub static ref PRETTY_BUILD_INFORMATION: String = @@ -51,10 +50,9 @@ pub(crate) struct Cli { pub(crate) enum Commands { /// Initialise a Nym client. Do this first! Init(init::Init), + /// Run the Nym client with provided configuration client optionally overriding set parameters Run(run::Run), - /// Try to upgrade the client - Upgrade(upgrade::Upgrade), /// Generate shell completions Completions(ArgShell), @@ -81,7 +79,6 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box init::execute(m).await?, Commands::Run(m) => run::execute(m).await?, - Commands::Upgrade(m) => upgrade::execute(m), Commands::Completions(s) => s.generate(&mut Cli::command(), bin_name), Commands::GenerateFigSpec => fig_generate(&mut Cli::command(), bin_name), } diff --git a/clients/native/src/commands/upgrade.rs b/clients/native/src/commands/upgrade.rs deleted file mode 100644 index b4c2d45ad3..0000000000 --- a/clients/native/src/commands/upgrade.rs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2021-2023 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::client::config::Config; -use crate::commands::try_load_current_config; -use clap::Args; -use nym_bin_common::version_checker::Version; -use std::process; - -fn unimplemented_upgrade(current_version: &Version, config_version: &Version) -> ! { - eprintln!("Cannot perform upgrade from {config_version} to {current_version} as it hasn't been implemented yet"); - process::exit(1) -} - -#[derive(Args, Clone)] -pub(crate) struct Upgrade { - /// Id of the nym-client we want to upgrade - #[clap(long)] - id: String, -} - -fn parse_config_version(config: &Config) -> Version { - let version = Version::parse(&config.base.client.version).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {err}"); - process::exit(1) - }); - - if version.is_prerelease() || !version.build.is_empty() { - eprintln!( - "Trying to upgrade from a non-released version {version}. This is not supported!" - ); - process::exit(1) - } - - version -} - -fn parse_package_version() -> Version { - let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - - // technically this is not a correct way of checking it as a released version might contain valid build identifiers - // however, we are not using them ourselves at the moment and hence it should be fine. - // if we change our mind, we could easily tweak this code - if version.is_prerelease() || !version.build.is_empty() { - eprintln!("Trying to upgrade to a non-released version {version}. This is not supported!"); - process::exit(1) - } - - version -} - -fn do_upgrade(config: Config, _args: &Upgrade, package_version: &Version) { - let config_version = parse_config_version(&config); - if &config_version == package_version { - println!("You're using the most recent version!"); - return; - } - - unimplemented_upgrade(package_version, &config_version) -} - -pub(crate) fn execute(args: &Upgrade) { - let package_version = parse_package_version(); - - let id = &args.id; - - let existing_config = try_load_current_config(id).unwrap_or_else(|err| { - eprintln!("failed to load existing config file! - {err}"); - process::exit(1) - }); - - if existing_config.base.client.version.is_empty() { - eprintln!("the existing configuration file does not seem to contain version number."); - process::exit(1); - } - - do_upgrade(existing_config, args, &package_version) -} diff --git a/clients/socks5/src/commands/mod.rs b/clients/socks5/src/commands/mod.rs index 60d6b6e0b7..266a4d6e26 100644 --- a/clients/socks5/src/commands/mod.rs +++ b/clients/socks5/src/commands/mod.rs @@ -24,7 +24,6 @@ use std::error::Error; pub mod init; pub(crate) mod run; -pub(crate) mod upgrade; lazy_static! { pub static ref PRETTY_BUILD_INFORMATION: String = @@ -55,9 +54,6 @@ pub(crate) enum Commands { /// Run the Nym client with provided configuration client optionally overriding set parameters Run(run::Run), - /// Try to upgrade the client - Upgrade(upgrade::Upgrade), - /// Generate shell completions Completions(ArgShell), @@ -83,7 +79,6 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box init::execute(m).await?, Commands::Run(m) => run::execute(m).await?, - Commands::Upgrade(m) => upgrade::execute(m), Commands::Completions(s) => s.generate(&mut Cli::command(), bin_name), Commands::GenerateFigSpec => fig_generate(&mut Cli::command(), bin_name), } diff --git a/clients/socks5/src/commands/upgrade.rs b/clients/socks5/src/commands/upgrade.rs deleted file mode 100644 index 00ffb9252b..0000000000 --- a/clients/socks5/src/commands/upgrade.rs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2021-2023 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::commands::try_load_current_config; -use crate::config::Config; -use clap::Args; -use nym_bin_common::version_checker::Version; -use std::process; - -fn unimplemented_upgrade(current_version: &Version, config_version: &Version) -> ! { - eprintln!("Cannot perform upgrade from {config_version} to {current_version} as it hasn't been implemented yet"); - process::exit(1) -} - -#[derive(Args, Clone)] -pub(crate) struct Upgrade { - /// Id of the nym-client we want to upgrade - #[clap(long)] - id: String, -} - -fn parse_config_version(config: &Config) -> Version { - let version = Version::parse(&config.core.base.client.version).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {err}"); - process::exit(1) - }); - - if version.is_prerelease() || !version.build.is_empty() { - eprintln!( - "Trying to upgrade from a non-released version {version}. This is not supported!" - ); - process::exit(1) - } - - version -} - -fn parse_package_version() -> Version { - let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - - // technically this is not a correct way of checking it as a released version might contain valid build identifiers - // however, we are not using them ourselves at the moment and hence it should be fine. - // if we change our mind, we could easily tweak this code - if version.is_prerelease() || !version.build.is_empty() { - eprintln!("Trying to upgrade to a non-released version {version}. This is not supported!"); - process::exit(1) - } - - version -} - -fn do_upgrade(config: Config, _args: &Upgrade, package_version: &Version) { - let config_version = parse_config_version(&config); - if &config_version == package_version { - println!("You're using the most recent version!"); - return; - } - - unimplemented_upgrade(package_version, &config_version) -} - -pub(crate) fn execute(args: &Upgrade) { - let package_version = parse_package_version(); - - let id = &args.id; - - let existing_config = try_load_current_config(id).unwrap_or_else(|err| { - eprintln!("failed to load existing config file! - {err}"); - process::exit(1) - }); - - if existing_config.core.base.client.version.is_empty() { - eprintln!("the existing configuration file does not seem to contain version number."); - process::exit(1); - } - - do_upgrade(existing_config, args, &package_version) -} diff --git a/gateway/src/commands/mod.rs b/gateway/src/commands/mod.rs index 8430e0b7e5..15775ec757 100644 --- a/gateway/src/commands/mod.rs +++ b/gateway/src/commands/mod.rs @@ -22,7 +22,6 @@ pub(crate) mod init; pub(crate) mod node_details; pub(crate) mod run; pub(crate) mod sign; -pub(crate) mod upgrade; #[derive(Subcommand)] pub(crate) enum Commands { @@ -38,9 +37,6 @@ pub(crate) enum Commands { /// Sign text to prove ownership of this mixnode Sign(sign::Sign), - /// Try to upgrade the gateway - Upgrade(upgrade::Upgrade), - /// Generate shell completions Completions(ArgShell), @@ -71,7 +67,6 @@ pub(crate) async fn execute(args: Cli) -> Result<(), Box node_details::execute(m).await?, Commands::Run(m) => run::execute(m).await?, Commands::Sign(m) => sign::execute(m)?, - Commands::Upgrade(m) => upgrade::execute(&m).await, Commands::Completions(s) => s.generate(&mut crate::Cli::command(), bin_name), Commands::GenerateFigSpec => fig_generate(&mut crate::Cli::command(), bin_name), } diff --git a/gateway/src/commands/upgrade.rs b/gateway/src/commands/upgrade.rs deleted file mode 100644 index c726971b58..0000000000 --- a/gateway/src/commands/upgrade.rs +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2020 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::config::Config; -use clap::Args; -use nym_bin_common::version_checker::Version; -use std::fmt::Display; -use std::process; - -#[derive(Args, Clone)] -pub struct Upgrade { - /// Id of the nym-gateway we want to upgrade - #[clap(long)] - id: String, -} - -#[allow(dead_code)] -fn fail_upgrade(from_version: D1, to_version: D2) -> ! { - print_failed_upgrade(from_version, to_version); - process::exit(1) -} - -fn print_start_upgrade(from: D1, to: D2) { - eprintln!( - "\n==================\nTrying to upgrade gateway from {} to {} ...", - from, to - ); -} - -fn print_failed_upgrade(from: D1, to: D2) { - eprintln!( - "Upgrade from {} to {} failed!\n==================\n", - from, to - ); -} - -fn print_successful_upgrade(from: D1, to: D2) { - eprintln!( - "Upgrade from {} to {} was successful!\n==================\n", - from, to - ); -} - -fn outdated_upgrade(config_version: &Version, package_version: &Version) -> ! { - eprintln!( - "Cannot perform upgrade from {} to {}. Your version is too old to perform the upgrade.!", - config_version, package_version - ); - process::exit(1) -} - -fn unsupported_upgrade(current_version: &Version, config_version: &Version) -> ! { - eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, current_version); - process::exit(1) -} - -fn parse_config_version(config: &Config) -> Version { - let version = Version::parse(&config.gateway.version).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {err}"); - process::exit(1) - }); - - if version.is_prerelease() || !version.build.is_empty() { - eprintln!( - "Trying to upgrade from a non-released version {}. This is not supported!", - version - ); - process::exit(1) - } - - version -} - -fn parse_package_version() -> Version { - let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - - // technically this is not a correct way of checking it as a released version might contain valid build identifiers - // however, we are not using them ourselves at the moment and hence it should be fine. - // if we change our mind, we could easily tweak this code - if version.is_prerelease() || !version.build.is_empty() { - eprintln!( - "Trying to upgrade to a non-released version {}. This is not supported!", - version - ); - process::exit(1) - } - - version -} - -fn minor_0_12_upgrade( - config: Config, - _args: &Upgrade, - config_version: &Version, - package_version: &Version, -) -> Config { - let to_version = if package_version.major == 0 && package_version.minor == 12 { - package_version.clone() - } else { - Version::new(0, 12, 0) - }; - - print_start_upgrade(config_version, &to_version); - - let upgraded_config = config.with_custom_version(to_version.to_string()); - - upgraded_config - .save_to_default_location() - .unwrap_or_else(|err| { - eprintln!("failed to overwrite config file! - {err}"); - print_failed_upgrade(config_version, &to_version); - process::exit(1); - }); - - print_successful_upgrade(config_version, to_version); - - upgraded_config -} - -fn do_upgrade(mut config: Config, args: &Upgrade, package_version: Version) { - loop { - let config_version = parse_config_version(&config); - - if config_version == package_version { - eprintln!("You're using the most recent version!"); - return; - } - - config = match config_version.major { - 0 => match config_version.minor { - 9 | 10 => outdated_upgrade(&config_version, &package_version), - 11 => minor_0_12_upgrade(config, args, &config_version, &package_version), - _ => unsupported_upgrade(&config_version, &package_version), - }, - _ => unsupported_upgrade(&config_version, &package_version), - } - } -} - -pub async fn execute(args: &Upgrade) { - let package_version = parse_package_version(); - - let existing_config = Config::read_from_default_path(&args.id).unwrap_or_else(|err| { - eprintln!("failed to load existing config file! - {err}"); - process::exit(1) - }); - - if existing_config.gateway.version.is_empty() { - eprintln!("the existing configuration file does not seem to contain version number."); - process::exit(1); - } - - do_upgrade(existing_config, args, package_version) -} diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs index 16cf17aa2b..d3c7cd040d 100644 --- a/gateway/src/config/mod.rs +++ b/gateway/src/config/mod.rs @@ -159,11 +159,6 @@ impl Config { self } - pub fn with_custom_version>(mut self, version: S) -> Self { - self.gateway.version = version.into(); - self - } - pub fn get_statistics_service_url(&self) -> Url { self.gateway.statistics_service_url.clone() } diff --git a/mixnode/src/commands/mod.rs b/mixnode/src/commands/mod.rs index 6582fe2c62..b8c8f84894 100644 --- a/mixnode/src/commands/mod.rs +++ b/mixnode/src/commands/mod.rs @@ -20,7 +20,6 @@ mod init; mod node_details; mod run; mod sign; -mod upgrade; #[derive(Subcommand)] pub(crate) enum Commands { @@ -36,9 +35,6 @@ pub(crate) enum Commands { /// Sign text to prove ownership of this mixnode Sign(sign::Sign), - /// Try to upgrade the mixnode - Upgrade(upgrade::Upgrade), - /// Show details of this mixnode NodeDetails(node_details::NodeDetails), @@ -67,7 +63,6 @@ pub(crate) async fn execute(args: Cli) -> anyhow::Result<()> { Commands::Init(m) => init::execute(&m), Commands::Run(m) => run::execute(&m).await?, Commands::Sign(m) => sign::execute(&m)?, - Commands::Upgrade(m) => upgrade::execute(&m)?, Commands::NodeDetails(m) => node_details::execute(&m)?, Commands::Completions(s) => s.generate(&mut crate::Cli::command(), bin_name), Commands::GenerateFigSpec => fig_generate(&mut crate::Cli::command(), bin_name), diff --git a/mixnode/src/commands/upgrade.rs b/mixnode/src/commands/upgrade.rs deleted file mode 100644 index 5c8a95d313..0000000000 --- a/mixnode/src/commands/upgrade.rs +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2020 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::commands::try_upgrade_v1_1_21_config; -use crate::config::Config; -use clap::Args; -use nym_bin_common::version_checker::Version; -use std::fmt::Display; -use std::process; - -#[derive(Args)] -pub(crate) struct Upgrade { - /// Id of the nym-mixnode we want to upgrade - #[clap(long)] - id: String, -} - -#[allow(dead_code)] -fn fail_upgrade(from_version: D1, to_version: D2) -> ! { - print_failed_upgrade(from_version, to_version); - process::exit(1) -} - -fn print_start_upgrade(from: D1, to: D2) { - println!("\n==================\nTrying to upgrade mixnode from {from} to {to} ..."); -} - -fn print_failed_upgrade(from: D1, to: D2) { - eprintln!("Upgrade from {from} to {to} failed!\n==================\n"); -} - -fn print_successful_upgrade(from: D1, to: D2) { - println!("Upgrade from {from} to {to} was successful!\n==================\n"); -} - -fn outdated_upgrade(config_version: &Version, package_version: &Version) -> ! { - eprintln!( - "Cannot perform upgrade from {config_version} to {package_version}. Your version is too old to perform the upgrade.!" - ); - process::exit(1) -} - -fn unsupported_upgrade(config_version: &Version, package_version: &Version) -> ! { - eprintln!("Cannot perform upgrade from {config_version} to {package_version}. Please let the developers know about this issue if you expected it to work!"); - process::exit(1) -} - -fn parse_config_version(config: &Config) -> Version { - let version = Version::parse(&config.mixnode.version).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {err}"); - process::exit(1) - }); - - if version.is_prerelease() || !version.build.is_empty() { - eprintln!( - "Trying to upgrade from a non-released version {version}. This is not supported!" - ); - process::exit(1) - } - - version -} - -fn parse_package_version() -> Version { - let version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - - // technically this is not a correct way of checking it as a released version might contain valid build identifiers - // however, we are not using them ourselves at the moment and hence it should be fine. - // if we change our mind, we could easily tweak this code - if version.is_prerelease() || !version.build.is_empty() { - eprintln!("Trying to upgrade to a non-released version {version}. This is not supported!"); - process::exit(1) - } - - version -} - -fn minor_0_12_upgrade( - config: Config, - _args: &Upgrade, - config_version: &Version, - package_version: &Version, -) -> Config { - let to_version = if package_version.major == 0 && package_version.minor == 12 { - package_version.clone() - } else { - Version::new(0, 12, 0) - }; - - print_start_upgrade(config_version, &to_version); - - let upgraded_config = config.with_custom_version(to_version.to_string()); - - upgraded_config - .save_to_default_location() - .unwrap_or_else(|err| { - eprintln!("failed to overwrite config file! - {err}"); - print_failed_upgrade(config_version, &to_version); - process::exit(1); - }); - - print_successful_upgrade(config_version, to_version); - - upgraded_config -} - -fn do_upgrade(mut config: Config, args: &Upgrade, package_version: Version) { - loop { - let config_version = parse_config_version(&config); - - if config_version == package_version { - println!("You're using the most recent version!"); - return; - } - - config = match config_version.major { - 0 => match config_version.minor { - 9 | 10 => outdated_upgrade(&config_version, &package_version), - 11 => minor_0_12_upgrade(config, args, &config_version, &package_version), - _ => unsupported_upgrade(&config_version, &package_version), - }, - _ => unsupported_upgrade(&config_version, &package_version), - } - } -} - -pub(crate) fn execute(args: &Upgrade) -> anyhow::Result<()> { - try_upgrade_v1_1_21_config(&args.id)?; - - let package_version = parse_package_version(); - - let existing_config = Config::read_from_default_path(&args.id).unwrap_or_else(|err| { - eprintln!("failed to load existing config file! - {err}"); - process::exit(1) - }); - - if existing_config.mixnode.version.is_empty() { - eprintln!("the existing configuration file does not seem to contain version number."); - process::exit(1); - } - - do_upgrade(existing_config, args, package_version); - Ok(()) -} diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index 02ce8d875a..ec4077deab 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -147,11 +147,6 @@ impl Config { self } - pub fn with_custom_version>(mut self, version: S) -> Self { - self.mixnode.version = version.into(); - self - } - pub fn get_nym_api_endpoints(&self) -> Vec { self.mixnode.nym_api_urls.clone() }