Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(launchpad): add network id arg for testing #2541

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ jobs:
- name: Run node tests
timeout-minutes: 25
run: cargo test --release --package ant-node --lib

- name: Run launchpad tests
timeout-minutes: 25
run: cargo test --release --package node-launchpad

# The `can_store_after_restart` can be executed with other package tests together and passing
# on local machine. However keeps failing (when executed together) on CI machines.
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ jobs:
timeout-minutes: 25
run: cargo test --release --package ant-bootstrap

- name: Run launchpad tests
timeout-minutes: 25
run: cargo test --release --package node-launchpad

- name: Run node tests
timeout-minutes: 25
run: cargo test --release --package ant-node --lib
Expand Down
37 changes: 22 additions & 15 deletions node-launchpad/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl App {
peers_args: PeersArgs,
antnode_path: Option<PathBuf>,
app_data_path: Option<PathBuf>,
network_id: Option<u8>,
) -> Result<Self> {
// Configurations
let app_data = AppData::load(app_data_path)?;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -319,6 +321,7 @@ mod tests {
use super::*;
use ant_bootstrap::PeersArgs;
use color_eyre::eyre::Result;
use serde_json::json;
use std::io::Cursor;
use std::io::Write;
use tempfile::tempdir;
Expand All @@ -331,22 +334,17 @@ mod tests {

let mountpoint = get_primary_mount_point();

// Create a valid configuration file with all fields
let valid_config = format!(
r#"
{{
let config = json!({
"discord_username": "happy_user",
"nodes_to_start": 5,
"storage_mountpoint": "{}",
"storage_mountpoint": mountpoint.display().to_string(),
"storage_drive": "C:",
"connection_mode": "Automatic",
"port_from": 12000,
"port_to": 13000
}}
"#,
mountpoint.display()
);
});

let valid_config = serde_json::to_string_pretty(&config)?;
std::fs::write(&config_path, valid_config)?;

// Create default PeersArgs
Expand All @@ -356,7 +354,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) => {
Expand Down Expand Up @@ -417,7 +415,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) => {
Expand Down Expand Up @@ -472,8 +471,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) => {
Expand Down Expand Up @@ -535,7 +541,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
Expand Down Expand Up @@ -576,7 +582,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) => {
Expand Down
47 changes: 25 additions & 22 deletions node-launchpad/src/bin/tui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

#[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<u8>,

/// 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<PathBuf>,

#[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,
Expand Down Expand Up @@ -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?;
Expand Down
21 changes: 13 additions & 8 deletions node-launchpad/src/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub struct Status<'a> {
// Nodes
node_services: Vec<NodeServiceData>,
items: Option<StatefulTable<NodeItem<'a>>>,
/// To pass into node services.
network_id: Option<u8>,
// Node Management
node_management: NodeManagement,
// Amount of nodes
Expand Down Expand Up @@ -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<PathBuf>,
pub data_dir_path: PathBuf,
pub connection_mode: ConnectionMode,
pub data_dir_path: PathBuf,
pub network_id: Option<u8>,
pub peers_args: PeersArgs,
pub port_from: Option<u32>,
pub port_to: Option<u32>,
pub rewards_address: String,
}

impl Status<'_> {
Expand All @@ -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(),
Expand Down Expand Up @@ -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");
Expand Down
41 changes: 22 additions & 19 deletions node-launchpad/src/node_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@ async fn stop_nodes(services: Vec<String>, action_sender: UnboundedSender<Action

#[derive(Debug)]
pub struct MaintainNodesArgs {
pub action_sender: UnboundedSender<Action>,
pub antnode_path: Option<PathBuf>,
pub connection_mode: ConnectionMode,
pub count: u16,
pub data_dir_path: Option<PathBuf>,
pub network_id: Option<u8>,
pub owner: String,
pub peers_args: PeersArgs,
pub run_nat_detection: bool,
pub antnode_path: Option<PathBuf>,
pub data_dir_path: Option<PathBuf>,
pub action_sender: UnboundedSender<Action>,
pub connection_mode: ConnectionMode,
pub port_range: Option<PortRange>,
pub rewards_address: String,
pub run_nat_detection: bool,
}

/// Maintain the specified number of nodes
Expand Down Expand Up @@ -289,16 +290,17 @@ async fn load_node_registry(
}

struct NodeConfig {
antnode_path: Option<PathBuf>,
auto_set_nat_flags: bool,
upnp: bool,
home_network: bool,
custom_ports: Option<PortRange>,
owner: Option<String>,
count: u16,
custom_ports: Option<PortRange>,
data_dir_path: Option<PathBuf>,
home_network: bool,
network_id: Option<u8>,
owner: Option<String>,
peers_args: PeersArgs,
antnode_path: Option<PathBuf>,
rewards_address: String,
upnp: bool,
}

/// Run the NAT detection process
Expand Down Expand Up @@ -344,9 +346,10 @@ async fn run_nat_detection(action_sender: &UnboundedSender<Action>) {

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 {
Expand All @@ -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,
}
}

Expand All @@ -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: {:?}",
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -497,7 +500,7 @@ async fn add_nodes(
None,
None,
None,
None,
config.network_id,
None,
port_range,
config.owner.clone(),
Expand Down
Loading