bugfix: fixed nym-node config migrations (again) (#5179)

This commit is contained in:
Jędrzej Stuczyński
2024-11-26 09:41:18 +00:00
committed by GitHub
parent dcde4c8df1
commit 2a60b2f057
6 changed files with 29 additions and 15 deletions
@@ -11,6 +11,7 @@ use nym_pemstore::store_keypair;
use old_configs::old_config_v2::*;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
use tracing::instrument;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
@@ -756,15 +757,16 @@ fn initialise(config: &WireguardV2) -> std::io::Result<()> {
Ok(())
}
#[instrument(skip_all)]
pub async fn try_upgrade_config_v1<P: AsRef<Path>>(
path: P,
prev_config: Option<ConfigV1>,
) -> Result<ConfigV2, NymNodeError> {
tracing::debug!("Updating from 1.1.2");
debug!("attempting to load v1 config...");
let old_cfg = if let Some(prev_config) = prev_config {
prev_config
} else {
ConfigV1::read_from_path(&path)?
ConfigV1::read_from_path(&path).inspect_err(|err| debug!("failed: {err}"))?
};
let wireguard = WireguardV2 {
enabled: old_cfg.wireguard.enabled,
@@ -16,6 +16,7 @@ use nym_sphinx_acknowledgements::AckKey;
use old_configs::old_config_v3::*;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
use tracing::instrument;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
@@ -786,15 +787,16 @@ pub async fn initialise(
Ok(())
}
#[instrument(skip_all)]
pub async fn try_upgrade_config_v2<P: AsRef<Path>>(
path: P,
prev_config: Option<ConfigV2>,
) -> Result<ConfigV3, NymNodeError> {
tracing::debug!("Updating from 1.1.3");
debug!("attempting to load v2 config...");
let old_cfg = if let Some(prev_config) = prev_config {
prev_config
} else {
ConfigV2::read_from_path(&path)?
ConfigV2::read_from_path(&path).inspect_err(|err| debug!("failed: {err}"))?
};
let authenticator_paths = AuthenticatorPathsV3::new(
@@ -17,6 +17,7 @@ use old_configs::old_config_v4::*;
use persistence::*;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
use tracing::instrument;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
@@ -938,15 +939,16 @@ pub async fn initialise(
Ok(())
}
#[instrument(skip_all)]
pub async fn try_upgrade_config_v3<P: AsRef<Path>>(
path: P,
prev_config: Option<ConfigV3>,
) -> Result<ConfigV4, NymNodeError> {
tracing::debug!("Updating from 1.1.4");
debug!("attempting to load v3 config...");
let old_cfg = if let Some(prev_config) = prev_config {
prev_config
} else {
ConfigV3::read_from_path(&path)?
ConfigV3::read_from_path(&path).inspect_err(|err| debug!("failed: {err}"))?
};
let exit_gateway_paths = ExitGatewayPaths::new(
@@ -20,6 +20,7 @@ use old_configs::old_config_v5::*;
use persistence::*;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
use tracing::instrument;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
@@ -203,7 +204,7 @@ pub struct MixnetV4 {
/// If applicable, custom port announced in the self-described API that other clients and nodes
/// will use.
/// Useful when the node is behind a proxy.
#[serde(deserialize_with = "de_maybe_port")]
#[serde(deserialize_with = "de_maybe_port", default)]
pub announce_port: Option<u16>,
/// Addresses to nym APIs from which the node gets the view of the network.
@@ -385,7 +386,7 @@ pub struct VerlocV4 {
/// default: `0.0.0.0:1790`
pub bind_address: SocketAddr,
#[serde(deserialize_with = "de_maybe_port")]
#[serde(deserialize_with = "de_maybe_port", default)]
pub announce_port: Option<u16>,
#[serde(default)]
@@ -1060,15 +1061,16 @@ pub async fn initialise(
Ok(())
}
#[instrument(skip_all)]
pub async fn try_upgrade_config_v4<P: AsRef<Path>>(
path: P,
prev_config: Option<ConfigV4>,
) -> Result<ConfigV5, NymNodeError> {
tracing::debug!("Updating from 1.1.5");
debug!("attempting to load v4 config...");
let old_cfg = if let Some(prev_config) = prev_config {
prev_config
} else {
ConfigV4::read_from_path(&path)?
ConfigV4::read_from_path(&path).inspect_err(|err| debug!("failed: {err}"))?
};
let exit_gateway_paths = ExitGatewayPaths::new(
@@ -25,6 +25,7 @@ use nym_sphinx_acknowledgements::AckKey;
use persistence::*;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
use tracing::instrument;
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
@@ -208,7 +209,7 @@ pub struct MixnetV5 {
/// If applicable, custom port announced in the self-described API that other clients and nodes
/// will use.
/// Useful when the node is behind a proxy.
#[serde(deserialize_with = "de_maybe_port")]
#[serde(deserialize_with = "de_maybe_port", default)]
pub announce_port: Option<u16>,
/// Addresses to nym APIs from which the node gets the view of the network.
@@ -390,7 +391,7 @@ pub struct VerlocV5 {
/// default: `0.0.0.0:1790`
pub bind_address: SocketAddr,
#[serde(deserialize_with = "de_maybe_port")]
#[serde(deserialize_with = "de_maybe_port", default)]
pub announce_port: Option<u16>,
#[serde(default)]
@@ -1069,15 +1070,16 @@ pub async fn initialise(
Ok(())
}
#[instrument(skip_all)]
pub async fn try_upgrade_config_v5<P: AsRef<Path>>(
path: P,
prev_config: Option<ConfigV5>,
) -> Result<Config, NymNodeError> {
tracing::debug!("Updating from 1.1.6");
debug!("attempting to load v5 config...");
let old_cfg = if let Some(prev_config) = prev_config {
prev_config
} else {
ConfigV5::read_from_path(&path)?
ConfigV5::read_from_path(&path).inspect_err(|err| debug!("failed: {err}"))?
};
let (private_ipv4, private_ipv6) = match old_cfg.wireguard.private_ip {
+5 -1
View File
@@ -5,6 +5,7 @@ use crate::config::old_configs::*;
use crate::config::Config;
use crate::error::NymNodeError;
use std::path::Path;
use tracing::debug;
// currently there are no upgrades
async fn try_upgrade_config(path: &Path) -> Result<(), NymNodeError> {
@@ -24,7 +25,10 @@ async fn try_upgrade_config(path: &Path) -> Result<(), NymNodeError> {
pub async fn try_load_current_config<P: AsRef<Path>>(
config_path: P,
) -> Result<Config, NymNodeError> {
if let Ok(cfg) = Config::read_from_toml_file(config_path.as_ref()) {
if let Ok(cfg) = Config::read_from_toml_file(config_path.as_ref())
.inspect_err(|err| debug!("didn't manage to load the current config: {err}"))
{
debug!("managed to load the current version of the config");
return Ok(cfg);
}