diff --git a/Cargo.lock b/Cargo.lock index 0a37989170..528c51a738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,7 +345,7 @@ dependencies = [ [[package]] name = "client-core" -version = "0.9.2" +version = "0.10.0" dependencies = [ "config", "crypto", @@ -1420,7 +1420,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "0.9.2" +version = "0.10.0" dependencies = [ "clap", "client-core", @@ -1471,7 +1471,7 @@ dependencies = [ [[package]] name = "nym-gateway" -version = "0.9.2" +version = "0.10.0" dependencies = [ "clap", "config", @@ -1501,7 +1501,7 @@ dependencies = [ [[package]] name = "nym-mixnode" -version = "0.9.2" +version = "0.10.0" dependencies = [ "bs58 0.4.0", "clap", @@ -1574,7 +1574,7 @@ dependencies = [ [[package]] name = "nym-socks5-client" -version = "0.9.2" +version = "0.10.0" dependencies = [ "clap", "client-core", diff --git a/clients/client-core/Cargo.toml b/clients/client-core/Cargo.toml index 76bb6579cc..61d5221557 100644 --- a/clients/client-core/Cargo.toml +++ b/clients/client-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "client-core" -version = "0.9.2" +version = "0.10.0" authors = ["Dave Hrycyszyn "] edition = "2018" diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index 62a87ca092..ebc641deb6 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-client" -version = "0.9.2" +version = "0.10.0" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/clients/native/src/commands/upgrade.rs b/clients/native/src/commands/upgrade.rs index 44e2c04231..d27dc5048e 100644 --- a/clients/native/src/commands/upgrade.rs +++ b/clients/native/src/commands/upgrade.rs @@ -14,7 +14,7 @@ use crate::client::config::{Config, MISSING_VALUE}; use clap::{App, Arg, ArgMatches}; -use client_core::config::DEFAULT_VALIDATOR_REST_ENDPOINT; +use client_core::config::{DEFAULT_MIXNET_CONTRACT_ADDRESS, DEFAULT_VALIDATOR_REST_ENDPOINT}; use config::NymConfig; use std::fmt::Display; use std::process; @@ -41,6 +41,62 @@ fn print_successful_upgrade(from: D1, to: D2) { ); } +pub fn command_args<'a, 'b>() -> App<'a, 'b> { + App::new("upgrade").about("Try to upgrade the client") + .arg( + Arg::with_name("id") + .long("id") + .help("Id of the nym-client we want to upgrade") + .takes_value(true) + .required(true), + ) + // the rest of arguments depend on the upgrade path + .arg(Arg::with_name("current version") + .long("current-version") + .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") + .takes_value(true) + ) +} + +fn unsupported_upgrade(config_version: Version, package_version: Version) -> ! { + eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, package_version); + process::exit(1) +} + +fn parse_config_version(config: &Config) -> Version { + let version = Version::parse(config.get_base().get_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 pre_090_upgrade(from: &str, mut config: Config) -> Config { // this is not extracted to separate function as you only have to manually pass version // if upgrading from pre090 version @@ -112,89 +168,86 @@ fn pre_090_upgrade(from: &str, mut config: Config) -> Config { config } -fn patch_09x_upgrade(mut config: Config, _matches: &ArgMatches) -> Config { - // this call must succeed as it was already called before - let from_version = Version::parse(config.get_base().get_version()).unwrap(); - let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); +/* +changes: +- introduction of mixnet contract address field +- change to default validator rest endpoint + */ +fn minor_010_upgrade( + mut config: Config, + _matches: &ArgMatches, + config_version: &Version, + package_version: &Version, +) -> Config { + let to_version = if package_version.major == 0 && package_version.minor == 10 { + package_version.clone() + } else { + Version::new(0, 10, 0) + }; - print_start_upgrade(&from_version, &to_version); + print_start_upgrade(&config_version, &to_version); - // 0.9.1 upgrade: config .get_base_mut() .set_custom_version(to_version.to_string().as_ref()); + if config.get_base().get_validator_mixnet_contract_address() != MISSING_VALUE { + eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade."); + print_failed_upgrade(&config_version, &to_version); + process::exit(1); + } + + println!( + "Setting mixnet contract address to {}", + DEFAULT_MIXNET_CONTRACT_ADDRESS + ); + + config + .get_base_mut() + .set_mixnet_contract(DEFAULT_MIXNET_CONTRACT_ADDRESS); + + // The default validator endpoint changed + println!( + "Setting validator REST endpoint to to {}", + DEFAULT_VALIDATOR_REST_ENDPOINT + ); + + config + .get_base_mut() + .set_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT); + config.save_to_file(None).unwrap_or_else(|err| { eprintln!("failed to overwrite config file! - {:?}", err); - print_failed_upgrade(&from_version, &to_version); + print_failed_upgrade(&config_version, &to_version); process::exit(1); }); - print_successful_upgrade(from_version, to_version); + print_successful_upgrade(config_version, to_version); config } -pub fn command_args<'a, 'b>() -> App<'a, 'b> { - App::new("upgrade").about("Try to upgrade the client") - .arg( - Arg::with_name("id") - .long("id") - .help("Id of the nym-client we want to upgrade") - .takes_value(true) - .required(true), - ) - // the rest of arguments depend on the upgrade path - .arg(Arg::with_name("current version") - .long("current-version") - .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") - .takes_value(true) - ) -} - -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 do_upgrade(mut config: Config, matches: &ArgMatches) { - let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - +fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) { loop { - let config_version = - Version::parse(config.get_base().get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {:?}", err); - process::exit(1) - }); + let config_version = parse_config_version(&config); - if config_version == current { + 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 => patch_09x_upgrade(config, &matches), - _ => unsupported_upgrade(current, config_version), + 9 => minor_010_upgrade(config, &matches, &config_version, &package_version), + _ => unsupported_upgrade(config_version, package_version), }, - _ => unsupported_upgrade(current, config_version), + _ => unsupported_upgrade(config_version, package_version), } } } pub fn execute(matches: &ArgMatches) { - let current = 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 current.is_prerelease() || !current.build.is_empty() { - eprintln!( - "Trying to upgrade to a non-released version {}. This is not supported!", - current - ); - process::exit(1) - } + let package_version = parse_package_version(); let id = matches.value_of("id").unwrap(); @@ -216,24 +269,6 @@ pub fn execute(matches: &ArgMatches) { existing_config = pre_090_upgrade(self_reported_version, existing_config); } - let config_version = - Version::parse(existing_config.get_base().get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {:?}", err); - process::exit(1) - }); - - if config_version.is_prerelease() || !config_version.build.is_empty() { - eprintln!( - "Trying to upgrade from non-released version {}. This is not supported!", - config_version - ); - process::exit(1) - } - // here be upgrade path to 0.9.X and beyond based on version number from config - if config_version == current { - println!("You're using the most recent version!"); - } else { - do_upgrade(existing_config, matches) - } + do_upgrade(existing_config, matches, package_version) } diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index 3fd1724abb..35d224aab6 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-socks5-client" -version = "0.9.2" +version = "0.10.0" authors = ["Dave Hrycyszyn "] edition = "2018" diff --git a/clients/socks5/src/commands/upgrade.rs b/clients/socks5/src/commands/upgrade.rs index 0615983ed6..6a783d8824 100644 --- a/clients/socks5/src/commands/upgrade.rs +++ b/clients/socks5/src/commands/upgrade.rs @@ -14,7 +14,7 @@ use crate::client::config::{Config, MISSING_VALUE}; use clap::{App, Arg, ArgMatches}; -use client_core::config::DEFAULT_VALIDATOR_REST_ENDPOINT; +use client_core::config::{DEFAULT_MIXNET_CONTRACT_ADDRESS, DEFAULT_VALIDATOR_REST_ENDPOINT}; use config::NymConfig; use std::fmt::Display; use std::process; @@ -41,6 +41,62 @@ fn print_successful_upgrade(from: D1, to: D2) { ); } +pub fn command_args<'a, 'b>() -> App<'a, 'b> { + App::new("upgrade").about("Try to upgrade the client") + .arg( + Arg::with_name("id") + .long("id") + .help("Id of the nym-socks5-client we want to upgrade") + .takes_value(true) + .required(true), + ) + // the rest of arguments depend on the upgrade path + .arg(Arg::with_name("current version") + .long("current-version") + .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") + .takes_value(true) + ) +} + +fn unsupported_upgrade(config_version: Version, package_version: Version) -> ! { + eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, package_version); + process::exit(1) +} + +fn parse_config_version(config: &Config) -> Version { + let version = Version::parse(config.get_base().get_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 pre_090_upgrade(from: &str, mut config: Config) -> Config { // this is not extracted to separate function as you only have to manually pass version // if upgrading from pre090 version @@ -112,89 +168,86 @@ fn pre_090_upgrade(from: &str, mut config: Config) -> Config { config } -fn patch_09x_upgrade(mut config: Config, _matches: &ArgMatches) -> Config { - // this call must succeed as it was already called before - let from_version = Version::parse(config.get_base().get_version()).unwrap(); - let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); +/* +changes: +- introduction of mixnet contract address field +- change to default validator rest endpoint + */ +fn minor_010_upgrade( + mut config: Config, + _matches: &ArgMatches, + config_version: &Version, + package_version: &Version, +) -> Config { + let to_version = if package_version.major == 0 && package_version.minor == 10 { + package_version.clone() + } else { + Version::new(0, 10, 0) + }; - print_start_upgrade(&from_version, &to_version); + print_start_upgrade(&config_version, &to_version); - // 0.9.1 upgrade: config .get_base_mut() .set_custom_version(to_version.to_string().as_ref()); + if config.get_base().get_validator_mixnet_contract_address() != MISSING_VALUE { + eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade."); + print_failed_upgrade(&config_version, &to_version); + process::exit(1); + } + + println!( + "Setting mixnet contract address to {}", + DEFAULT_MIXNET_CONTRACT_ADDRESS + ); + + config + .get_base_mut() + .set_mixnet_contract(DEFAULT_MIXNET_CONTRACT_ADDRESS); + + // The default validator endpoint changed + println!( + "Setting validator REST endpoint to to {}", + DEFAULT_VALIDATOR_REST_ENDPOINT + ); + + config + .get_base_mut() + .set_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT); + config.save_to_file(None).unwrap_or_else(|err| { eprintln!("failed to overwrite config file! - {:?}", err); - print_failed_upgrade(&from_version, &to_version); + print_failed_upgrade(&config_version, &to_version); process::exit(1); }); - print_successful_upgrade(from_version, to_version); + print_successful_upgrade(config_version, to_version); config } -pub fn command_args<'a, 'b>() -> App<'a, 'b> { - App::new("upgrade").about("Try to upgrade the client") - .arg( - Arg::with_name("id") - .long("id") - .help("Id of the nym-socks5-client we want to upgrade") - .takes_value(true) - .required(true), - ) - // the rest of arguments depend on the upgrade path - .arg(Arg::with_name("current version") - .long("current-version") - .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") - .takes_value(true) - ) -} - -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 do_upgrade(mut config: Config, matches: &ArgMatches) { - let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - +fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) { loop { - let config_version = - Version::parse(config.get_base().get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {:?}", err); - process::exit(1) - }); + let config_version = parse_config_version(&config); - if config_version == current { + 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 => patch_09x_upgrade(config, &matches), - _ => unsupported_upgrade(current, config_version), + 9 => minor_010_upgrade(config, &matches, &config_version, &package_version), + _ => unsupported_upgrade(config_version, package_version), }, - _ => unsupported_upgrade(current, config_version), + _ => unsupported_upgrade(config_version, package_version), } } } pub fn execute(matches: &ArgMatches) { - let current = 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 current.is_prerelease() || !current.build.is_empty() { - eprintln!( - "Trying to upgrade to a non-released version {}. This is not supported!", - current - ); - process::exit(1) - } + let package_version = parse_package_version(); let id = matches.value_of("id").unwrap(); @@ -216,24 +269,6 @@ pub fn execute(matches: &ArgMatches) { existing_config = pre_090_upgrade(self_reported_version, existing_config); } - let config_version = - Version::parse(existing_config.get_base().get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse client version! - {:?}", err); - process::exit(1) - }); - - if config_version.is_prerelease() || !config_version.build.is_empty() { - eprintln!( - "Trying to upgrade from non-released version {}. This is not supported!", - config_version - ); - process::exit(1) - } - // here be upgrade path to 0.9.X and beyond based on version number from config - if config_version == current { - println!("You're using the most recent version!"); - } else { - do_upgrade(existing_config, matches) - } + do_upgrade(existing_config, matches, package_version) } diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 0686dc4fd9..c09a21d361 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-gateway" -version = "0.9.2" +version = "0.10.0" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/gateway/src/commands/upgrade.rs b/gateway/src/commands/upgrade.rs index 942049d8bd..822231daed 100644 --- a/gateway/src/commands/upgrade.rs +++ b/gateway/src/commands/upgrade.rs @@ -1,8 +1,8 @@ // Copyright 2020 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use crate::config::DEFAULT_VALIDATOR_REST_ENDPOINT; use crate::config::{Config, MISSING_VALUE}; +use crate::config::{DEFAULT_MIXNET_CONTRACT_ADDRESS, DEFAULT_VALIDATOR_REST_ENDPOINT}; use clap::{App, Arg, ArgMatches}; use config::NymConfig; use std::fmt::Display; @@ -30,7 +30,63 @@ fn print_successful_upgrade(from: D1, to: D2) { ); } -fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config { +pub fn command_args<'a, 'b>() -> App<'a, 'b> { + App::new("upgrade").about("Try to upgrade the gateway") + .arg( + Arg::with_name("id") + .long("id") + .help("Id of the nym-gateway we want to upgrade") + .takes_value(true) + .required(true), + ) + // the rest of arguments depend on the upgrade path + .arg(Arg::with_name("current version") + .long("current-version") + .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") + .takes_value(true) + ) +} + +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.get_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 pre_090_upgrade(from: &str, config: Config) -> Config { // this is not extracted to separate function as you only have to manually pass version // if upgrading from pre090 version let from = match from.strip_prefix("v") { @@ -97,86 +153,73 @@ fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config upgraded_config } -fn patch_09x_upgrade(config: Config, _matches: &ArgMatches) -> Config { - // this call must succeed as it was already called before - let from_version = Version::parse(config.get_version()).unwrap(); - let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); +fn minor_010_upgrade( + config: Config, + _matches: &ArgMatches, + config_version: &Version, + package_version: &Version, +) -> Config { + let to_version = if package_version.major == 0 && package_version.minor == 10 { + package_version.clone() + } else { + Version::new(0, 10, 0) + }; - print_start_upgrade(&from_version, &to_version); + print_start_upgrade(&config_version, &to_version); - // 0.9.1 upgrade: - let upgraded_config = config.with_custom_version(to_version.to_string().as_ref()); + if config.get_validator_mixnet_contract_address() != MISSING_VALUE { + eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade."); + print_failed_upgrade(&config_version, &to_version); + process::exit(1); + } + + println!( + "Setting validator REST endpoint to {}", + DEFAULT_VALIDATOR_REST_ENDPOINT + ); + + println!( + "Setting mixnet contract address to {}", + DEFAULT_MIXNET_CONTRACT_ADDRESS + ); + + let upgraded_config = config + .with_custom_version(to_version.to_string().as_ref()) + .with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT) + .with_custom_mixnet_contract(DEFAULT_MIXNET_CONTRACT_ADDRESS); upgraded_config.save_to_file(None).unwrap_or_else(|err| { eprintln!("failed to overwrite config file! - {:?}", err); - print_failed_upgrade(&from_version, &to_version); + print_failed_upgrade(&config_version, &to_version); process::exit(1); }); - print_successful_upgrade(from_version, to_version); + print_successful_upgrade(config_version, to_version); upgraded_config } -pub fn command_args<'a, 'b>() -> App<'a, 'b> { - App::new("upgrade").about("Try to upgrade the gateway") - .arg( - Arg::with_name("id") - .long("id") - .help("Id of the nym-gateway we want to upgrade") - .takes_value(true) - .required(true), - ) - // the rest of arguments depend on the upgrade path - .arg(Arg::with_name("current version") - .long("current-version") - .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") - .takes_value(true) - ) -} - -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 do_upgrade(mut config: Config, matches: &ArgMatches) { - let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - +fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) { loop { - let config_version = Version::parse(config.get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse node version! - {:?}", err); - process::exit(1) - }); + let config_version = parse_config_version(&config); - if config_version == current { + 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 => patch_09x_upgrade(config, &matches), - _ => unsupported_upgrade(current, config_version), + 9 => minor_010_upgrade(config, &matches, &config_version, &package_version), + _ => unsupported_upgrade(config_version, package_version), }, - _ => unsupported_upgrade(current, config_version), + _ => unsupported_upgrade(config_version, package_version), } } } pub fn execute(matches: &ArgMatches) { - let current = 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 current.is_prerelease() || !current.build.is_empty() { - eprintln!( - "Trying to upgrade to a non-released version {}. This is not supported!", - current - ); - process::exit(1) - } + let package_version = parse_package_version(); let id = matches.value_of("id").unwrap(); @@ -195,26 +238,9 @@ pub fn execute(matches: &ArgMatches) { }); // upgrades up to 0.9.0 - existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches); - } - - let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse node version! - {:?}", err); - process::exit(1) - }); - - if config_version.is_prerelease() || !config_version.build.is_empty() { - eprintln!( - "Trying to upgrade from non-released version {}. This is not supported!", - config_version - ); - process::exit(1) + existing_config = pre_090_upgrade(self_reported_version, existing_config); } // here be upgrade path to 0.9.X and beyond based on version number from config - if config_version == current { - println!("You're using the most recent version!"); - } else { - do_upgrade(existing_config, matches) - } + do_upgrade(existing_config, matches, package_version) } diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 741b4f01f6..6fc8938dfa 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-mixnode" -version = "0.9.2" +version = "0.10.0" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/mixnode/src/commands/upgrade.rs b/mixnode/src/commands/upgrade.rs index 78c3988a47..0a8f56f090 100644 --- a/mixnode/src/commands/upgrade.rs +++ b/mixnode/src/commands/upgrade.rs @@ -2,7 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 use crate::config::{ - missing_string_value, Config, DEFAULT_METRICS_SERVER, DEFAULT_VALIDATOR_REST_ENDPOINT, + missing_string_value, Config, DEFAULT_METRICS_SERVER, DEFAULT_MIXNET_CONTRACT_ADDRESS, + DEFAULT_VALIDATOR_REST_ENDPOINT, MISSING_VALUE, }; use clap::{App, Arg, ArgMatches}; use config::NymConfig; @@ -33,7 +34,63 @@ fn print_successful_upgrade(from: D1, to: D2) { ); } -fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config { +pub fn command_args<'a, 'b>() -> App<'a, 'b> { + App::new("upgrade").about("Try to upgrade the mixnode") + .arg( + Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnode we want to upgrade") + .takes_value(true) + .required(true), + ) + // the rest of arguments depend on the upgrade path + .arg(Arg::with_name("current version") + .long("current-version") + .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") + .takes_value(true) + ) +} + +fn unsupported_upgrade(config_version: Version, package_version: Version) -> ! { + eprintln!("Cannot perform upgrade from {} to {}. Please let the developers know about this issue if you expected it to work!", config_version, package_version); + process::exit(1) +} + +fn parse_config_version(config: &Config) -> Version { + let version = Version::parse(config.get_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 pre_090_upgrade(from: &str, config: Config) -> Config { // note: current is guaranteed to not have any `build` information suffix (nor pre-release // information), as this was asserted at the beginning of this command) // @@ -135,86 +192,73 @@ fn pre_090_upgrade(from: &str, config: Config, _matches: &ArgMatches) -> Config upgraded_config } -fn patch_09x_upgrade(config: Config, _matches: &ArgMatches) -> Config { - // this call must succeed as it was already called before - let from_version = Version::parse(config.get_version()).unwrap(); - let to_version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); +fn minor_010_upgrade( + config: Config, + _matches: &ArgMatches, + config_version: &Version, + package_version: &Version, +) -> Config { + let to_version = if package_version.major == 0 && package_version.minor == 10 { + package_version.clone() + } else { + Version::new(0, 10, 0) + }; - print_start_upgrade(&from_version, &to_version); + print_start_upgrade(&config_version, &to_version); - // 0.9.1 upgrade: - let upgraded_config = config.with_custom_version(to_version.to_string().as_ref()); + if config.get_validator_mixnet_contract_address() != MISSING_VALUE { + eprintln!("existing config seems to have specified mixnet contract address which was only introduced in 0.10.0! Can't perform upgrade."); + print_failed_upgrade(&config_version, &to_version); + process::exit(1); + } + + println!( + "Setting validator REST endpoint to {}", + DEFAULT_VALIDATOR_REST_ENDPOINT + ); + + println!( + "Setting mixnet contract address to {}", + DEFAULT_MIXNET_CONTRACT_ADDRESS + ); + + let upgraded_config = config + .with_custom_version(to_version.to_string().as_ref()) + .with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT) + .with_custom_mixnet_contract(DEFAULT_MIXNET_CONTRACT_ADDRESS); upgraded_config.save_to_file(None).unwrap_or_else(|err| { eprintln!("failed to overwrite config file! - {:?}", err); - print_failed_upgrade(&from_version, &to_version); + print_failed_upgrade(&config_version, &to_version); process::exit(1); }); - print_successful_upgrade(from_version, to_version); + print_successful_upgrade(config_version, to_version); upgraded_config } -pub fn command_args<'a, 'b>() -> App<'a, 'b> { - App::new("upgrade").about("Try to upgrade the mixnode") - .arg( - Arg::with_name("id") - .long("id") - .help("Id of the nym-mixnode we want to upgrade") - .takes_value(true) - .required(true), - ) - // the rest of arguments depend on the upgrade path - .arg(Arg::with_name("current version") - .long("current-version") - .help("REQUIRED FOR PRE-0.9.0 UPGRADES. Specifies current version of the configuration file to help to determine a valid upgrade path. Valid formats include '0.8.1', 'v0.8.1' or 'V0.8.1'") - .takes_value(true) - ) -} - -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 do_upgrade(mut config: Config, matches: &ArgMatches) { - let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); - +fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) { loop { - let config_version = Version::parse(config.get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse node version! - {:?}", err); - process::exit(1) - }); + let config_version = parse_config_version(&config); - if config_version == current { + 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 => patch_09x_upgrade(config, &matches), - _ => unsupported_upgrade(current, config_version), + 9 => minor_010_upgrade(config, &matches, &config_version, &package_version), + _ => unsupported_upgrade(config_version, package_version), }, - _ => unsupported_upgrade(current, config_version), + _ => unsupported_upgrade(config_version, package_version), } } } pub fn execute(matches: &ArgMatches) { - let current = 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 current.is_prerelease() || !current.build.is_empty() { - eprintln!( - "Trying to upgrade to a non-released version {}. This is not supported!", - current - ); - process::exit(1) - } + let package_version = parse_package_version(); let id = matches.value_of("id").unwrap(); @@ -233,26 +277,9 @@ pub fn execute(matches: &ArgMatches) { }); // upgrades up to 0.9.0 - existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches); - } - - let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| { - eprintln!("failed to parse node version! - {:?}", err); - process::exit(1) - }); - - if config_version.is_prerelease() || !config_version.build.is_empty() { - eprintln!( - "Trying to upgrade from non-released version {}. This is not supported!", - config_version - ); - process::exit(1) + existing_config = pre_090_upgrade(self_reported_version, existing_config); } // here be upgrade path to 0.9.X and beyond based on version number from config - if config_version == current { - println!("You're using the most recent version!"); - } else { - do_upgrade(existing_config, matches) - } + do_upgrade(existing_config, matches, package_version) }