-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
450 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// Copyright 2020 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::config::old_config_v1_1_21::ConfigV1_1_21; | ||
use crate::config::default_config_filepath; | ||
use crate::error::MixnodeError; | ||
use crate::{config::Config, Cli}; | ||
use anyhow::anyhow; | ||
use clap::CommandFactory; | ||
use clap::Subcommand; | ||
use colored::Colorize; | ||
|
@@ -22,6 +22,7 @@ mod init; | |
mod node_details; | ||
mod run; | ||
mod sign; | ||
mod upgrade_helpers; | ||
|
||
#[derive(Subcommand)] | ||
pub(crate) enum Commands { | ||
|
@@ -131,32 +132,19 @@ pub(crate) fn version_check(cfg: &Config) -> bool { | |
} | ||
} | ||
|
||
fn try_upgrade_v1_1_21_config(id: &str) -> std::io::Result<()> { | ||
use nym_config::legacy_helpers::nym_config::MigrationNymConfig; | ||
|
||
// explicitly load it as v1.1.21 (which is incompatible with the current, i.e. 1.1.22+) | ||
let Ok(old_config) = ConfigV1_1_21::load_from_file(id) else { | ||
// if we failed to load it, there might have been nothing to upgrade | ||
// or maybe it was an even older file. in either way. just ignore it and carry on with our day | ||
return Ok(()); | ||
}; | ||
info!("It seems the mixnode is using <= v1.1.21 config template."); | ||
info!("It is going to get updated to the current specification."); | ||
|
||
let updated: Config = old_config.into(); | ||
updated.save_to_default_location() | ||
} | ||
|
||
fn try_load_current_config(id: &str) -> anyhow::Result<Config> { | ||
try_upgrade_v1_1_21_config(id)?; | ||
fn try_load_current_config(id: &str) -> Result<Config, MixnodeError> { | ||
upgrade_helpers::try_upgrade_config(id)?; | ||
|
||
Config::read_from_default_path(id).map_err(|err| { | ||
let error_msg = | ||
format!( | ||
"Failed to load config for {id}. Are you sure you have run `init` before? (Error was: {err})", | ||
); | ||
error!("{error_msg}"); | ||
anyhow!(error_msg) | ||
error!( | ||
"Failed to load config for {id}. Are you sure you have run `init` before? (Error was: {err})", | ||
); | ||
MixnodeError::ConfigLoadFailure { | ||
path: default_config_filepath(id), | ||
id: id.to_string(), | ||
source: err, | ||
} | ||
}) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2023 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::config::old_config_v1_1_21::ConfigV1_1_21; | ||
use crate::config::old_config_v1_1_32::ConfigV1_1_32; | ||
use crate::config::{default_config_filepath, Config}; | ||
use crate::error::MixnodeError; | ||
use log::info; | ||
|
||
fn try_upgrade_v1_1_21_config(id: &str) -> Result<bool, MixnodeError> { | ||
use nym_config::legacy_helpers::nym_config::MigrationNymConfig; | ||
|
||
// explicitly load it as v1.1.21 (which is incompatible with the current, i.e. 1.1.22+) | ||
let Ok(old_config) = ConfigV1_1_21::load_from_file(id) else { | ||
// if we failed to load it, there might have been nothing to upgrade | ||
// or maybe it was an even older file. in either way. just ignore it and carry on with our day | ||
return Ok(false); | ||
}; | ||
info!("It seems the mixnode is using <= v1.1.21 config template."); | ||
info!("It is going to get updated to the current specification."); | ||
|
||
let updated_step1: ConfigV1_1_32 = old_config.into(); | ||
|
||
let updated: Config = updated_step1.into(); | ||
updated | ||
.save_to_default_location() | ||
.map_err(|err| MixnodeError::ConfigSaveFailure { | ||
path: default_config_filepath(id), | ||
id: id.to_string(), | ||
source: err, | ||
})?; | ||
|
||
Ok(true) | ||
} | ||
|
||
fn try_upgrade_v1_1_32_config(id: &str) -> Result<bool, MixnodeError> { | ||
// explicitly load it as v1.1.32 (which is incompatible with the current, i.e. 1.1.22+) | ||
let Ok(old_config) = ConfigV1_1_32::read_from_default_path(id) else { | ||
// if we failed to load it, there might have been nothing to upgrade | ||
// or maybe it was an even older file. in either way. just ignore it and carry on with our day | ||
return Ok(false); | ||
}; | ||
info!("It seems the mixnode is using <= v1.1.32 config template."); | ||
info!("It is going to get updated to the current specification."); | ||
|
||
let updated: Config = old_config.into(); | ||
updated | ||
.save_to_default_location() | ||
.map_err(|err| MixnodeError::ConfigSaveFailure { | ||
path: default_config_filepath(id), | ||
id: id.to_string(), | ||
source: err, | ||
})?; | ||
|
||
Ok(true) | ||
} | ||
|
||
pub(crate) fn try_upgrade_config(id: &str) -> Result<(), MixnodeError> { | ||
if try_upgrade_v1_1_21_config(id)? { | ||
return Ok(()); | ||
} | ||
if try_upgrade_v1_1_32_config(id)? { | ||
return Ok(()); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
// Copyright 2023 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::config::old_config_v1_1_32::{ | ||
ConfigV1_1_32, DebugV1_1_32, MixNodeV1_1_32, VerlocV1_1_32, | ||
}; | ||
use crate::config::persistence::paths::{KeysPaths, MixNodePaths}; | ||
use crate::config::{Config, Debug, MixNode, Verloc}; | ||
use nym_bin_common::logging::LoggingSettings; | ||
use nym_config::legacy_helpers::nym_config::MigrationNymConfig; | ||
use nym_validator_client::nyxd; | ||
|
@@ -67,13 +69,13 @@ pub struct ConfigV1_1_21 { | |
debug: DebugV1_1_21, | ||
} | ||
|
||
impl From<ConfigV1_1_21> for Config { | ||
impl From<ConfigV1_1_21> for ConfigV1_1_32 { | ||
fn from(value: ConfigV1_1_21) -> Self { | ||
let node_description = | ||
ConfigV1_1_21::default_config_directory(&value.mixnode.id).join(DESCRIPTION_FILE); | ||
|
||
Config { | ||
mixnode: MixNode { | ||
ConfigV1_1_32 { | ||
mixnode: MixNodeV1_1_32 { | ||
version: value.mixnode.version, | ||
id: value.mixnode.id, | ||
listening_address: value.mixnode.listening_address, | ||
|
@@ -82,13 +84,6 @@ impl From<ConfigV1_1_21> for Config { | |
http_api_port: value.mixnode.http_api_port, | ||
nym_api_urls: value.mixnode.nym_api_urls, | ||
}, | ||
// \/ ADDED | ||
host: nym_node::config::Host { | ||
// this is a very bad default! | ||
public_ips: vec![value.mixnode.listening_address], | ||
hostname: None, | ||
}, | ||
// /\ ADDED | ||
storage_paths: MixNodePaths { | ||
keys: KeysPaths { | ||
private_identity_key_file: value.mixnode.private_identity_key_file, | ||
|
@@ -176,9 +171,9 @@ struct VerlocV1_1_21 { | |
retry_timeout: Duration, | ||
} | ||
|
||
impl From<VerlocV1_1_21> for Verloc { | ||
impl From<VerlocV1_1_21> for VerlocV1_1_32 { | ||
fn from(value: VerlocV1_1_21) -> Self { | ||
Verloc { | ||
VerlocV1_1_32 { | ||
packets_per_node: value.packets_per_node, | ||
connection_timeout: value.connection_timeout, | ||
packet_timeout: value.packet_timeout, | ||
|
@@ -227,9 +222,9 @@ struct DebugV1_1_21 { | |
use_legacy_framed_packet_version: bool, | ||
} | ||
|
||
impl From<DebugV1_1_21> for Debug { | ||
impl From<DebugV1_1_21> for DebugV1_1_32 { | ||
fn from(value: DebugV1_1_21) -> Self { | ||
Debug { | ||
DebugV1_1_32 { | ||
node_stats_logging_delay: value.node_stats_logging_delay, | ||
node_stats_updating_delay: value.node_stats_updating_delay, | ||
packet_forwarding_initial_backoff: value.packet_forwarding_initial_backoff, | ||
|
Oops, something went wrong.