Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/upgrade fix #421

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions gateway/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn print_successful_upgrade<D1: Display, D2: Display>(from: D1, to: D2) {
);
}

fn pre_090_upgrade(from: &str, config: Config) -> Config {
fn pre_090_upgrade(from: &str, config: Config, matches: &ArgMatches) -> 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") {
Expand Down Expand Up @@ -93,10 +93,15 @@ fn pre_090_upgrade(from: &str, config: Config) -> Config {
DEFAULT_VALIDATOR_REST_ENDPOINT
);

let upgraded_config = config
let mut upgraded_config = config
.with_custom_version(to_version.to_string().as_ref())
.with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT);

if let Some(incentives_address) = matches.value_of("incentives address") {
upgraded_config = upgraded_config.with_incentives_address(incentives_address);
println!("Setting incentives address to {}", incentives_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);
Expand All @@ -123,6 +128,11 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> {
.help("REQUIRED FOR PRE-0.9.0 UPGRADES. Self provided version of the nym-gateway if none is available in the config. NOTE: if provided incorrectly, results may be catastrophic.")
.takes_value(true)
)
.arg(Arg::with_name("incentives address")
.long("incentives-address")
.help("Optional, if participating in the incentives program, payment address")
.takes_value(true)
)
}

pub fn execute(matches: &ArgMatches) {
Expand Down Expand Up @@ -156,7 +166,7 @@ pub fn execute(matches: &ArgMatches) {
});

// upgrades up to 0.9.0
existing_config = pre_090_upgrade(self_reported_version, existing_config);
existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches);
}

let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| {
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub struct Gateway {
nym_root_directory: PathBuf,

/// Optional, if participating in the incentives program, payment address.
#[serde(deserialize_with = "deserialize_option_string")]
#[serde(deserialize_with = "deserialize_option_string", default)]
incentives_address: Option<String>,
}

Expand Down
26 changes: 18 additions & 8 deletions mixnode/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn print_successful_upgrade<D1: Display, D2: Display>(from: D1, to: D2) {
);
}

fn pre_090_upgrade(from: &str, config: Config) -> Config {
fn pre_090_upgrade(from: &str, config: Config, matches: &ArgMatches) -> 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)
//
Expand Down Expand Up @@ -112,6 +112,11 @@ fn pre_090_upgrade(from: &str, config: Config) -> Config {
.with_custom_metrics_server(DEFAULT_METRICS_SERVER)
.with_custom_validator(DEFAULT_VALIDATOR_REST_ENDPOINT);

if let Some(incentives_address) = matches.value_of("incentives address") {
upgraded_config = upgraded_config.with_incentives_address(incentives_address);
println!("Setting incentives address to {}", incentives_address);
}

println!("Setting metrics server to {}", DEFAULT_METRICS_SERVER);
println!(
"Setting validator REST endpoint to to {}",
Expand Down Expand Up @@ -147,18 +152,23 @@ fn pre_090_upgrade(from: &str, config: Config) -> 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),
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
// 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. Self provided version of the nym-mixnode if none is available in the config. NOTE: if provided incorrectly, results may be catastrophic.")
.takes_value(true)
)
.arg(Arg::with_name("incentives address")
.long("incentives-address")
.help("Optional, if participating in the incentives program, payment address")
.takes_value(true)
)
}

pub fn execute(matches: &ArgMatches) {
Expand Down Expand Up @@ -192,7 +202,7 @@ pub fn execute(matches: &ArgMatches) {
});

// upgrades up to 0.9.0
existing_config = pre_090_upgrade(self_reported_version, existing_config);
existing_config = pre_090_upgrade(self_reported_version, existing_config, &matches);
}

let config_version = Version::parse(existing_config.get_version()).unwrap_or_else(|err| {
Expand Down
2 changes: 1 addition & 1 deletion mixnode/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub struct MixNode {
nym_root_directory: PathBuf,

/// Optional, if participating in the incentives program, payment address.
#[serde(deserialize_with = "deserialize_option_string")]
#[serde(deserialize_with = "deserialize_option_string", default)]
incentives_address: Option<String>,
}

Expand Down