Feature Noise XKpsk3 : Fix localnet (#4465)

* add custom mixnet option for gateways

* add custom mixnet option for mixnode

* change topology construction as to not miss described_nodes

* adapt localnet scripts to new topology

* add snake_case alias to described_nodes
This commit is contained in:
Simon Wicky
2024-03-19 15:49:29 +01:00
committed by GitHub
parent 5a9c391ba2
commit 4b3dcb6eca
12 changed files with 275 additions and 35 deletions
+9
View File
@@ -11,6 +11,7 @@ use nym_bin_common::output_format::OutputFormat;
use nym_config::helpers::SPECIAL_ADDRESSES;
use nym_validator_client::nyxd;
use std::net::IpAddr;
use std::path::PathBuf;
#[derive(Args, Clone)]
pub(crate) struct Run {
/// Id of the nym-mixnode we want to run
@@ -42,6 +43,10 @@ pub(crate) struct Run {
#[clap(long, alias = "validators", value_delimiter = ',')]
nym_apis: Option<Vec<url::Url>>,
/// Path to .json file containing custom network specification.
#[arg(long, group = "network", hide = true)]
pub custom_mixnet: Option<PathBuf>,
#[clap(short, long, default_value_t = OutputFormat::default())]
output: OutputFormat,
}
@@ -91,6 +96,10 @@ pub(crate) async fn execute(args: &Run) -> anyhow::Result<()> {
Select the correct version and install it to your machine. You will need to provide the following: \n ");
mixnode.print_node_details(args.output);
if let Some(custom_mixnet) = &args.custom_mixnet {
mixnode = mixnode.with_stored_topology(custom_mixnet)?;
}
mixnode.run().await?;
Ok(())
}
+9
View File
@@ -34,6 +34,15 @@ pub enum MixnodeError {
source: io::Error,
},
#[error(
"failed to load custom topology using path '{}'. detailed message: {source}", file_path.display()
)]
CustomTopologyLoadFailure {
file_path: PathBuf,
#[source]
source: std::io::Error,
},
#[error(
"failed to save config file for id {id} using path '{}'. detailed message: {source}", path.display()
)]
+26 -4
View File
@@ -19,6 +19,7 @@ use nym_crypto::asymmetric::{encryption, identity};
use nym_mixnode_common::verloc::{self, AtomicVerlocResult, VerlocMeasurer};
use nym_task::{TaskClient, TaskManager};
use nym_topology::provider_trait::TopologyProvider;
use nym_topology::HardcodedTopologyProvider;
use nym_topology_control::accessor::TopologyAccessor;
use nym_topology_control::nym_api_provider::NymApiTopologyProvider;
use nym_topology_control::TopologyRefresher;
@@ -27,6 +28,7 @@ use nym_validator_client::NymApiClient;
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::net::SocketAddr;
use std::path::Path;
use std::process;
use std::sync::Arc;
use url::Url;
@@ -44,6 +46,7 @@ pub struct MixNode {
descriptor: NodeDescription,
identity_keypair: Arc<identity::KeyPair>,
sphinx_keypair: Arc<encryption::KeyPair>,
custom_topology_provider: Option<Box<dyn TopologyProvider + Send + Sync>>,
}
impl MixNode {
@@ -53,6 +56,7 @@ impl MixNode {
identity_keypair: Arc::new(load_identity_keys(&config)?),
sphinx_keypair: Arc::new(load_sphinx_keys(&config)?),
config,
custom_topology_provider: None,
})
}
@@ -75,6 +79,18 @@ impl MixNode {
println!("{}", output.format(&node_details));
}
pub fn with_stored_topology<P: AsRef<Path>>(mut self, file: P) -> Result<Self, MixnodeError> {
self.custom_topology_provider = Some(Box::new(
HardcodedTopologyProvider::new_from_file(&file).map_err(|source| {
MixnodeError::CustomTopologyLoadFailure {
file_path: file.as_ref().to_path_buf(),
source,
}
})?,
));
Ok(self)
}
fn start_http_api(
&self,
atomic_verloc_result: AtomicVerlocResult,
@@ -207,12 +223,15 @@ impl MixNode {
atomic_verloc_results
}
fn setup_topology_provider(nym_api_urls: Vec<Url>) -> Box<dyn TopologyProvider + Send + Sync> {
fn setup_topology_provider(
custom_provider: Option<Box<dyn TopologyProvider + Send + Sync>>,
nym_api_urls: Vec<Url>,
) -> Box<dyn TopologyProvider + Send + Sync> {
// if no custom provider was ... provided ..., create one using nym-api
Box::new(NymApiTopologyProvider::new(
custom_provider.unwrap_or(Box::new(NymApiTopologyProvider::new(
nym_api_urls,
env!("CARGO_PKG_VERSION").to_string(),
))
)))
}
// future responsible for periodically polling directory server and updating
@@ -295,7 +314,10 @@ impl MixNode {
let (node_stats_pointer, node_stats_update_sender) = self
.start_node_stats_controller(shutdown.subscribe().named("node_statistics::Controller"));
let topology_provider = Self::setup_topology_provider(self.config.get_nym_api_endpoints());
let topology_provider = Self::setup_topology_provider(
self.custom_topology_provider.take(),
self.config.get_nym_api_endpoints(),
);
let shared_topology_access = TopologyAccessor::new();
Self::start_topology_refresher(
topology_provider,