Merge pull request #4547 from nymtech/feature/update-nymnode-bonding-version

Feature/update nymnode bonding version
This commit is contained in:
Jędrzej Stuczyński
2024-04-19 10:12:18 +01:00
committed by GitHub
6 changed files with 49 additions and 71 deletions
Generated
+1
View File
@@ -6174,6 +6174,7 @@ dependencies = [
"cargo_metadata",
"celes",
"clap 4.4.7",
"colored",
"cupid",
"humantime-serde",
"ipnetwork 0.16.0",
+1
View File
@@ -18,6 +18,7 @@ anyhow.workspace = true
bip39 = { workspace = true, features = ["zeroize"] }
bs58.workspace = true
celes = "2.4.0" # country codes
colored = "2"
clap = { workspace = true, features = ["cargo", "env"] }
humantime-serde = { workspace = true }
ipnetwork = "0.16.0"
-36
View File
@@ -1,36 +0,0 @@
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
use cargo_metadata::MetadataCommand;
use std::fs;
use std::path::PathBuf;
// that's disgusting, but it works, so it's good enough for now ¯\_(ツ)_/¯
fn main() {
let out_dir: PathBuf = std::env::var("OUT_DIR").unwrap().into();
let path: PathBuf = std::env::var("CARGO_MANIFEST_DIR").unwrap().into();
let mix_path = path.parent().unwrap().join("mixnode");
let gateway_path = path.parent().unwrap().join("gateway");
let mix_meta = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.current_dir(&mix_path)
.exec()
.unwrap();
let mix_version = &mix_meta.root_package().unwrap().version;
let gateway_meta = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.current_dir(&gateway_path)
.exec()
.unwrap();
let gateway_version = &gateway_meta.root_package().unwrap().version;
fs::write(out_dir.join("mixnode_version"), mix_version.to_string()).unwrap();
fs::write(out_dir.join("gateway_version"), gateway_version.to_string()).unwrap();
println!("cargo::rerun-if-changed=build.rs");
}
+28 -3
View File
@@ -5,8 +5,12 @@ use crate::cli::helpers::{
EntryGatewayArgs, ExitGatewayArgs, HostArgs, HttpArgs, MixnetArgs, MixnodeArgs, WireguardArgs,
};
use crate::node::description::save_node_description;
use crate::node::helpers::{load_ed25519_identity_public_key, store_x25519_noise_keypair};
use crate::node::helpers::{
bonding_version, load_ed25519_identity_public_key, store_x25519_noise_keypair,
};
use clap::ValueEnum;
use colored::Color::TrueColor;
use colored::Colorize;
use nym_crypto::asymmetric::x25519;
use nym_gateway::helpers::{load_ip_packet_router_config, load_network_requester_config};
use nym_gateway::GatewayError;
@@ -627,7 +631,28 @@ pub(crate) async fn execute(args: Args) -> Result<(), NymNodeError> {
trace!("args: {args:#?}");
match args.node_type {
NodeType::Mixnode => migrate_mixnode(args).await,
NodeType::Gateway => migrate_gateway(args).await,
NodeType::Mixnode => migrate_mixnode(args).await?,
NodeType::Gateway => migrate_gateway(args).await?,
}
let orange = TrueColor {
r: 251,
g: 110,
b: 78,
};
println!("{}", "** Attention **".color(orange).bold());
print!("Please consider updating the '");
print!("{}", "version".color(orange));
print!("' field of your ");
print!("{}", "existing".bold().underline());
println!(" node to:");
println!();
println!("{}", bonding_version().bold().color(orange));
println!();
print!("in the settings section of the ");
println!("{}", "Nym Wallet".bold().color(orange));
println!();
Ok(())
}
+5 -32
View File
@@ -1,10 +1,11 @@
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
use crate::node::helpers::{load_ed25519_identity_public_key, load_x25519_sphinx_public_key};
use crate::node::helpers::{
bonding_version, load_ed25519_identity_public_key, load_x25519_sphinx_public_key,
};
use nym_node::config::{Config, NodeMode};
use nym_node::error::NymNodeError;
use semver::{BuildMetadata, Version};
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
@@ -60,26 +61,12 @@ impl MixnodeBondingInformation {
x25519_sphinx_key: String,
) -> MixnodeBondingInformation {
MixnodeBondingInformation {
version: Self::get_version(),
version: bonding_version(),
host: "YOU NEED TO FILL THIS FIELD MANUALLY".to_string(),
identity_key: ed25519_identity_key,
sphinx_key: x25519_sphinx_key,
}
}
#[allow(clippy::unwrap_used)]
fn get_version() -> String {
// SAFETY:
// 1. the value has been put into the environment during build.rs, so it must exist,
// 2. and the obtained version has already been parsed into semver in build.rs, so it must be a valid semver
let raw = include_str!(concat!(env!("OUT_DIR"), "/mixnode_version"));
let mut semver: Version = raw.parse().unwrap();
// if it's not empty, then we messed up our own versioning
assert!(semver.build.is_empty());
semver.build = BuildMetadata::new("nymnode").unwrap();
semver.to_string()
}
}
impl Display for MixnodeBondingInformation {
@@ -108,27 +95,13 @@ impl GatewayBondingInformation {
x25519_sphinx_key: String,
) -> GatewayBondingInformation {
GatewayBondingInformation {
version: Self::get_version(),
version: bonding_version(),
host: "YOU NEED TO FILL THIS FIELD MANUALLY".to_string(),
location: "YOU NEED TO FILL THIS FIELD MANUALLY".to_string(),
identity_key: ed25519_identity_key,
sphinx_key: x25519_sphinx_key,
}
}
#[allow(clippy::unwrap_used)]
fn get_version() -> String {
// SAFETY:
// 1. the value has been put into the file during build.rs, so it must exist,
// 2. and the obtained version has already been parsed into semver in build.rs, so it must be a valid semver
let raw = include_str!(concat!(env!("OUT_DIR"), "/gateway_version"));
let mut semver: Version = raw.parse().unwrap();
// if it's not empty, then we messed up our own versioning
assert!(semver.build.is_empty());
semver.build = BuildMetadata::new("nymnode").unwrap();
semver.to_string()
}
}
impl Display for GatewayBondingInformation {
+14
View File
@@ -7,10 +7,24 @@ use nym_node::error::{KeyIOFailure, NymNodeError};
use nym_node_http_api::api::api_requests::v1::node::models::NodeDescription;
use nym_pemstore::traits::{PemStorableKey, PemStorableKeyPair};
use nym_pemstore::KeyPairPath;
use semver::{BuildMetadata, Version};
use serde::Serialize;
use std::fmt::{Display, Formatter};
use std::path::Path;
#[allow(clippy::unwrap_used)]
pub fn bonding_version() -> String {
// SAFETY:
// the value has been put there by cargo
let raw = env!("CARGO_PKG_VERSION");
let mut semver: Version = raw.parse().unwrap();
// if it's not empty, then we messed up our own versioning
assert!(semver.build.is_empty());
semver.build = BuildMetadata::new("nymnode").unwrap();
semver.to_string()
}
#[derive(Debug, Serialize)]
pub(crate) struct DisplayDetails {
pub(crate) current_mode: NodeMode,