From 039c8ba0602b978972e2277914f02a5c1d4ceefd Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Mon, 16 Dec 2024 18:57:46 +0530 Subject: [PATCH] feat(launchpad): add network id arg for testing --- node-launchpad/src/app.rs | 23 ++++++++---- node-launchpad/src/bin/tui/main.rs | 47 +++++++++++++------------ node-launchpad/src/components/status.rs | 21 ++++++----- node-launchpad/src/node_mgmt.rs | 41 +++++++++++---------- 4 files changed, 77 insertions(+), 55 deletions(-) diff --git a/node-launchpad/src/app.rs b/node-launchpad/src/app.rs index 605c51efd3..7db62de89e 100644 --- a/node-launchpad/src/app.rs +++ b/node-launchpad/src/app.rs @@ -55,6 +55,7 @@ impl App { peers_args: PeersArgs, antnode_path: Option, app_data_path: Option, + network_id: Option, ) -> Result { // Configurations let app_data = AppData::load(app_data_path)?; @@ -93,6 +94,7 @@ impl App { allocated_disk_space: app_data.nodes_to_start, rewards_address: app_data.discord_username.clone(), peers_args, + network_id, antnode_path, data_dir_path, connection_mode, @@ -356,7 +358,7 @@ mod tests { let mut output = Cursor::new(Vec::new()); // Create and run the App, capturing its output - let app_result = App::new(60.0, 60.0, peers_args, None, Some(config_path)).await; + let app_result = App::new(60.0, 60.0, peers_args, None, Some(config_path), None).await; match app_result { Ok(app) => { @@ -417,7 +419,8 @@ mod tests { let mut output = Cursor::new(Vec::new()); // Create and run the App, capturing its output - let app_result = App::new(60.0, 60.0, peers_args, None, Some(test_app_data_path)).await; + let app_result = + App::new(60.0, 60.0, peers_args, None, Some(test_app_data_path), None).await; match app_result { Ok(app) => { @@ -472,8 +475,15 @@ mod tests { let mut output = Cursor::new(Vec::new()); // Create and run the App, capturing its output - let app_result = - App::new(60.0, 60.0, peers_args, None, Some(non_existent_config_path)).await; + let app_result = App::new( + 60.0, + 60.0, + peers_args, + None, + Some(non_existent_config_path), + None, + ) + .await; match app_result { Ok(app) => { @@ -535,7 +545,7 @@ mod tests { let peers_args = PeersArgs::default(); // Create and run the App, capturing its output - let app_result = App::new(60.0, 60.0, peers_args, None, Some(config_path)).await; + let app_result = App::new(60.0, 60.0, peers_args, None, Some(config_path), None).await; // Could be that the mountpoint doesn't exists // or that the user doesn't have permissions to access it @@ -576,7 +586,8 @@ mod tests { let peers_args = PeersArgs::default(); // Create and run the App - let app_result = App::new(60.0, 60.0, peers_args, None, Some(test_app_data_path)).await; + let app_result = + App::new(60.0, 60.0, peers_args, None, Some(test_app_data_path), None).await; match app_result { Ok(app) => { diff --git a/node-launchpad/src/bin/tui/main.rs b/node-launchpad/src/bin/tui/main.rs index 969e2c811a..46d733681d 100644 --- a/node-launchpad/src/bin/tui/main.rs +++ b/node-launchpad/src/bin/tui/main.rs @@ -26,42 +26,44 @@ use std::{env, path::PathBuf}; #[derive(Parser, Debug)] #[command(disable_version_flag = true)] pub struct Cli { - #[arg( - short, - long, - value_name = "FLOAT", - help = "Tick rate, i.e. number of ticks per second", - default_value_t = 1.0 - )] - pub tick_rate: f64, - - #[arg( - short, - long, - value_name = "FLOAT", - help = "Frame rate, i.e. number of frames per second", - default_value_t = 60.0 - )] - pub frame_rate: f64, - /// Provide a path for the antnode binary to be used by the service. /// /// Useful for creating the service using a custom built binary. #[clap(long)] antnode_path: Option, - #[command(flatten)] - pub(crate) peers: PeersArgs, - /// Print the crate version. #[clap(long)] crate_version: bool, + /// Specify the network ID to use. This will allow you to run the node on a different network. + /// + /// By default, the network ID is set to 1, which represents the mainnet. + #[clap(long, verbatim_doc_comment)] + network_id: Option, + + /// Frame rate, i.e. number of frames per second + #[arg(short, long, value_name = "FLOAT", default_value_t = 60.0)] + frame_rate: f64, + + /// Provide a path for the antnode binary to be used by the service. + /// + /// Useful for creating the service using a custom built binary. + #[clap(long)] + path: Option, + + #[command(flatten)] + peers: PeersArgs, + /// Print the package version. #[clap(long)] #[cfg(not(feature = "nightly"))] package_version: bool, + /// Tick rate, i.e. number of ticks per second + #[arg(short, long, value_name = "FLOAT", default_value_t = 1.0)] + tick_rate: f64, + /// Print the version. #[clap(long)] version: bool, @@ -129,7 +131,8 @@ async fn main() -> Result<()> { args.frame_rate, args.peers, args.antnode_path, - None, + args.path, + args.network_id, ) .await?; app.run().await?; diff --git a/node-launchpad/src/components/status.rs b/node-launchpad/src/components/status.rs index 1899bbd9bc..5ce84cf6fc 100644 --- a/node-launchpad/src/components/status.rs +++ b/node-launchpad/src/components/status.rs @@ -83,6 +83,8 @@ pub struct Status<'a> { // Nodes node_services: Vec, items: Option>>, + /// To pass into node services. + network_id: Option, // Node Management node_management: NodeManagement, // Amount of nodes @@ -117,13 +119,14 @@ pub enum LockRegistryState { pub struct StatusConfig { pub allocated_disk_space: usize, - pub rewards_address: String, - pub peers_args: PeersArgs, pub antnode_path: Option, - pub data_dir_path: PathBuf, pub connection_mode: ConnectionMode, + pub data_dir_path: PathBuf, + pub network_id: Option, + pub peers_args: PeersArgs, pub port_from: Option, pub port_to: Option, + pub rewards_address: String, } impl Status<'_> { @@ -135,6 +138,7 @@ impl Status<'_> { active: true, is_nat_status_determined: false, error_while_running_nat_detection: 0, + network_id: config.network_id, node_stats: NodeStats::default(), node_stats_last_update: Instant::now(), node_services: Default::default(), @@ -614,16 +618,17 @@ impl Component for Status<'_> { let action_sender = self.get_actions_sender()?; let maintain_nodes_args = MaintainNodesArgs { + action_sender: action_sender.clone(), + antnode_path: self.antnode_path.clone(), + connection_mode: self.connection_mode, count: self.nodes_to_start as u16, + data_dir_path: Some(self.data_dir_path.clone()), + network_id: self.network_id, owner: self.rewards_address.clone(), peers_args: self.peers_args.clone(), - run_nat_detection: self.should_we_run_nat_detection(), - antnode_path: self.antnode_path.clone(), - data_dir_path: Some(self.data_dir_path.clone()), - action_sender: action_sender.clone(), - connection_mode: self.connection_mode, port_range: Some(port_range), rewards_address: self.rewards_address.clone(), + run_nat_detection: self.should_we_run_nat_detection(), }; debug!("Calling maintain_n_running_nodes"); diff --git a/node-launchpad/src/node_mgmt.rs b/node-launchpad/src/node_mgmt.rs index 735f049fea..18780b4f2b 100644 --- a/node-launchpad/src/node_mgmt.rs +++ b/node-launchpad/src/node_mgmt.rs @@ -122,16 +122,17 @@ async fn stop_nodes(services: Vec, action_sender: UnboundedSender, + pub antnode_path: Option, + pub connection_mode: ConnectionMode, pub count: u16, + pub data_dir_path: Option, + pub network_id: Option, pub owner: String, pub peers_args: PeersArgs, - pub run_nat_detection: bool, - pub antnode_path: Option, - pub data_dir_path: Option, - pub action_sender: UnboundedSender, - pub connection_mode: ConnectionMode, pub port_range: Option, pub rewards_address: String, + pub run_nat_detection: bool, } /// Maintain the specified number of nodes @@ -289,16 +290,17 @@ async fn load_node_registry( } struct NodeConfig { + antnode_path: Option, auto_set_nat_flags: bool, - upnp: bool, - home_network: bool, - custom_ports: Option, - owner: Option, count: u16, + custom_ports: Option, data_dir_path: Option, + home_network: bool, + network_id: Option, + owner: Option, peers_args: PeersArgs, - antnode_path: Option, rewards_address: String, + upnp: bool, } /// Run the NAT detection process @@ -344,9 +346,10 @@ async fn run_nat_detection(action_sender: &UnboundedSender) { fn prepare_node_config(args: &MaintainNodesArgs) -> NodeConfig { NodeConfig { + antnode_path: args.antnode_path.clone(), auto_set_nat_flags: args.connection_mode == ConnectionMode::Automatic, - upnp: args.connection_mode == ConnectionMode::UPnP, - home_network: args.connection_mode == ConnectionMode::HomeNetwork, + data_dir_path: args.data_dir_path.clone(), + count: args.count, custom_ports: if args.connection_mode == ConnectionMode::CustomPorts { args.port_range.clone() } else { @@ -357,11 +360,11 @@ fn prepare_node_config(args: &MaintainNodesArgs) -> NodeConfig { } else { Some(args.owner.clone()) }, - count: args.count, - data_dir_path: args.data_dir_path.clone(), + home_network: args.connection_mode == ConnectionMode::HomeNetwork, + network_id: args.network_id, peers_args: args.peers_args.clone(), - antnode_path: args.antnode_path.clone(), rewards_address: args.rewards_address.clone(), + upnp: args.connection_mode == ConnectionMode::UPnP, } } @@ -373,8 +376,8 @@ fn debug_log_config(config: &NodeConfig, args: &MaintainNodesArgs) { config.count ); debug!( - " owner: {:?}, peers_args: {:?}, antnode_path: {:?}", - config.owner, config.peers_args, config.antnode_path + " owner: {:?}, peers_args: {:?}, antnode_path: {:?}, network_id: {:?}", + config.owner, config.peers_args, config.antnode_path, args.network_id ); debug!( " data_dir_path: {:?}, connection_mode: {:?}", @@ -423,7 +426,7 @@ async fn scale_down_nodes(config: &NodeConfig, count: u16) { None, None, None, - None, + config.network_id, None, None, // We don't care about the port, as we are scaling down config.owner.clone(), @@ -497,7 +500,7 @@ async fn add_nodes( None, None, None, - None, + config.network_id, None, port_range, config.owner.clone(),