From 010a05f3ca2b428b770c5b891665a1d8c48cd930 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 10 Dec 2024 18:55:05 +0530 Subject: [PATCH 1/7] Revert "feat(antctl): impl network_id option while adding node" This reverts commit aae44cb12fde68d2a7ae7b165f4074f5e1237bcb. --- ant-node-manager/src/add_services/config.rs | 17 +- ant-node-manager/src/add_services/mod.rs | 2 - ant-node-manager/src/add_services/tests.rs | 203 ------------------- ant-node-manager/src/bin/cli/main.rs | 7 - ant-node-manager/src/cmd/node.rs | 4 - ant-node-manager/src/lib.rs | 206 -------------------- ant-node-manager/src/local.rs | 1 - ant-node-manager/src/rpc.rs | 3 - ant-service-management/src/node.rs | 5 - node-launchpad/src/node_mgmt.rs | 2 - 10 files changed, 3 insertions(+), 447 deletions(-) diff --git a/ant-node-manager/src/add_services/config.rs b/ant-node-manager/src/add_services/config.rs index 7aac0eaeb6..40eea8ff86 100644 --- a/ant-node-manager/src/add_services/config.rs +++ b/ant-node-manager/src/add_services/config.rs @@ -79,7 +79,6 @@ pub struct InstallNodeServiceCtxBuilder { pub log_dir_path: PathBuf, pub log_format: Option, pub name: String, - pub network_id: Option, pub max_archived_log_files: Option, pub max_log_files: Option, pub metrics_port: Option, @@ -106,10 +105,6 @@ impl InstallNodeServiceCtxBuilder { ]; push_arguments_from_peers_args(&self.peers_args, &mut args); - if let Some(id) = self.network_id { - args.push(OsString::from("--network-id")); - args.push(OsString::from(id.to_string())); - } if self.home_network { args.push(OsString::from("--home-network")); } @@ -190,7 +185,6 @@ pub struct AddNodeServiceOptions { pub max_archived_log_files: Option, pub max_log_files: Option, pub metrics_port: Option, - pub network_id: Option, pub node_ip: Option, pub node_port: Option, pub owner: Option, @@ -320,11 +314,10 @@ mod tests { home_network: false, log_dir_path: PathBuf::from("/logs"), log_format: None, + name: "test-node".to_string(), max_archived_log_files: None, max_log_files: None, metrics_port: None, - name: "test-node".to_string(), - network_id: None, node_ip: None, node_port: None, owner: None, @@ -356,11 +349,10 @@ mod tests { home_network: false, log_dir_path: PathBuf::from("/logs"), log_format: None, + name: "test-node".to_string(), max_archived_log_files: None, max_log_files: None, metrics_port: None, - name: "test-node".to_string(), - network_id: None, node_ip: None, node_port: None, owner: None, @@ -393,11 +385,10 @@ mod tests { home_network: false, log_dir_path: PathBuf::from("/logs"), log_format: None, + name: "test-node".to_string(), max_archived_log_files: Some(10), max_log_files: Some(10), metrics_port: None, - name: "test-node".to_string(), - network_id: Some(5), node_ip: None, node_port: None, owner: None, @@ -519,8 +510,6 @@ mod tests { "http://localhost:8080", "--testnet", "--ignore-cache", - "--network-id", - "5", "--home-network", "--log-format", "json", diff --git a/ant-node-manager/src/add_services/mod.rs b/ant-node-manager/src/add_services/mod.rs index 76e8d46c12..a871f73179 100644 --- a/ant-node-manager/src/add_services/mod.rs +++ b/ant-node-manager/src/add_services/mod.rs @@ -210,7 +210,6 @@ pub async fn add_node( max_log_files: options.max_log_files, metrics_port: metrics_free_port, name: service_name.clone(), - network_id: options.network_id, node_ip: options.node_ip, node_port, owner: owner.clone(), @@ -247,7 +246,6 @@ pub async fn add_node( max_archived_log_files: options.max_archived_log_files, max_log_files: options.max_log_files, metrics_port: metrics_free_port, - network_id: options.network_id, node_ip: options.node_ip, node_port, number: node_number, diff --git a/ant-node-manager/src/add_services/tests.rs b/ant-node-manager/src/add_services/tests.rs index 58eaf31162..ee19f167b0 100644 --- a/ant-node-manager/src/add_services/tests.rs +++ b/ant-node-manager/src/add_services/tests.rs @@ -139,7 +139,6 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res max_log_files: None, metrics_port: None, name: "antnode1".to_string(), - network_id: None, node_ip: None, node_port: None, owner: None, @@ -174,7 +173,6 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -296,7 +294,6 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -344,7 +341,6 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -434,7 +430,6 @@ async fn add_genesis_node_should_return_an_error_if_count_is_greater_than_1() -> max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -530,7 +525,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -579,7 +573,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode2".to_string(), node_ip: None, node_port: None, @@ -628,7 +621,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode3".to_string(), node_ip: None, node_port: None, @@ -665,7 +657,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -811,7 +802,6 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -847,7 +837,6 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -942,7 +931,6 @@ async fn add_new_node_should_add_another_service() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -999,7 +987,6 @@ async fn add_new_node_should_add_another_service() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode2".to_string(), node_ip: None, node_port: None, @@ -1036,7 +1023,6 @@ async fn add_new_node_should_add_another_service() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -1200,7 +1186,6 @@ async fn add_node_should_create_service_file_with_first_arg() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -1357,7 +1342,6 @@ async fn add_node_should_create_service_file_with_peers_args() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -1509,7 +1493,6 @@ async fn add_node_should_create_service_file_with_local_arg() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -1665,7 +1648,6 @@ async fn add_node_should_create_service_file_with_network_contacts_url_arg() -> max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -1820,7 +1802,6 @@ async fn add_node_should_create_service_file_with_testnet_arg() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -1972,7 +1953,6 @@ async fn add_node_should_create_service_file_with_ignore_cache_arg() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -2125,7 +2105,6 @@ async fn add_node_should_create_service_file_with_custom_bootstrap_cache_path() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -2173,148 +2152,6 @@ async fn add_node_should_create_service_file_with_custom_bootstrap_cache_path() Ok(()) } -#[tokio::test] -async fn add_node_should_create_service_file_with_network_id() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--network-id"), - OsString::from("5"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - network_id: Some(5), - node_ip: None, - node_port: None, - owner: None, - peers_args: Default::default(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].network_id, Some(5)); - - Ok(()) -} - #[tokio::test] async fn add_node_should_use_custom_ip() -> Result<()> { let tmp_data_dir = assert_fs::TempDir::new()?; @@ -2415,7 +2252,6 @@ async fn add_node_should_use_custom_ip() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: Some(custom_ip), node_port: None, owner: None, @@ -2512,7 +2348,6 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: Some(custom_port), @@ -2549,7 +2384,6 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(PortRange::Single(custom_port)), owner: None, @@ -2807,7 +2641,6 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(PortRange::Range(12000, 12002)), owner: None, @@ -2882,7 +2715,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(12000), number: 1, @@ -2928,7 +2760,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(PortRange::Single(12000)), owner: None, @@ -3001,7 +2832,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(12000), owner: None, @@ -3047,7 +2877,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(PortRange::Range(12000, 12002)), owner: None, @@ -3126,7 +2955,6 @@ async fn add_node_should_return_an_error_if_port_and_node_count_do_not_match() - max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(PortRange::Range(12000, 12002)), owner: None, @@ -3210,7 +3038,6 @@ async fn add_node_should_return_an_error_if_multiple_services_are_specified_with max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: Some(PortRange::Single(12000)), owner: None, @@ -3356,7 +3183,6 @@ async fn add_node_should_set_random_ports_if_enable_metrics_server_is_true() -> max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -3494,7 +3320,6 @@ async fn add_node_should_set_max_archived_log_files() -> Result<()> { max_archived_log_files: Some(20), max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -3633,7 +3458,6 @@ async fn add_node_should_set_max_log_files() -> Result<()> { max_archived_log_files: None, max_log_files: Some(20), metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -3886,7 +3710,6 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< max_archived_log_files: None, max_log_files: None, metrics_port: Some(PortRange::Range(12000, 12002)), - network_id: None, node_ip: None, node_port: None, owner: None, @@ -3958,7 +3781,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use max_archived_log_files: None, max_log_files: None, metrics_port: Some(12000), - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4004,7 +3826,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use max_archived_log_files: None, max_log_files: None, metrics_port: Some(PortRange::Single(12000)), - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4078,7 +3899,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran max_archived_log_files: None, max_log_files: None, metrics_port: Some(12000), - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4124,7 +3944,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran max_archived_log_files: None, max_log_files: None, metrics_port: Some(PortRange::Range(12000, 12002)), - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4360,7 +4179,6 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4443,7 +4261,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4489,7 +4306,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4563,7 +4379,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4609,7 +4424,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4704,7 +4518,6 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -4740,7 +4553,6 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4832,7 +4644,6 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -4868,7 +4679,6 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4960,7 +4770,6 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -4996,7 +4805,6 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -5083,7 +4891,6 @@ async fn add_node_should_return_an_error_if_nat_status_is_none_but_auto_set_nat_ max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -5704,7 +5511,6 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -5741,7 +5547,6 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -5834,7 +5639,6 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -5871,7 +5675,6 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -5964,7 +5767,6 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -6001,7 +5803,6 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -6091,7 +5892,6 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, name: "antnode1".to_string(), node_ip: None, node_port: None, @@ -6128,7 +5928,6 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -6265,7 +6064,6 @@ async fn add_node_should_assign_an_owner_in_lowercase() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: Some("Discord_Username".to_string()), @@ -6404,7 +6202,6 @@ async fn add_node_should_auto_restart() -> Result<()> { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: Some("discord_username".to_string()), diff --git a/ant-node-manager/src/bin/cli/main.rs b/ant-node-manager/src/bin/cli/main.rs index b440cb09d8..5e6afa325c 100644 --- a/ant-node-manager/src/bin/cli/main.rs +++ b/ant-node-manager/src/bin/cli/main.rs @@ -172,11 +172,6 @@ pub enum SubCmd { /// services, which in this case would be 5. The range must also go from lower to higher. #[clap(long, value_parser = PortRange::parse)] metrics_port: Option, - /// Specify the network ID to use for the services. 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, /// Specify the IP address for the antnode service(s). /// /// If not set, we bind to all the available network interfaces. @@ -1080,7 +1075,6 @@ async fn main() -> Result<()> { max_archived_log_files, max_log_files, metrics_port, - network_id, node_ip, node_port, owner, @@ -1108,7 +1102,6 @@ async fn main() -> Result<()> { max_archived_log_files, max_log_files, metrics_port, - network_id, node_ip, node_port, owner, diff --git a/ant-node-manager/src/cmd/node.rs b/ant-node-manager/src/cmd/node.rs index 5ab42c0ea8..fd4b938bbc 100644 --- a/ant-node-manager/src/cmd/node.rs +++ b/ant-node-manager/src/cmd/node.rs @@ -49,7 +49,6 @@ pub async fn add( max_archived_log_files: Option, max_log_files: Option, metrics_port: Option, - network_id: Option, node_ip: Option, node_port: Option, owner: Option, @@ -126,7 +125,6 @@ pub async fn add( max_archived_log_files, max_log_files, metrics_port, - network_id, node_ip, node_port, owner, @@ -595,7 +593,6 @@ pub async fn maintain_n_running_nodes( max_archived_log_files: Option, max_log_files: Option, metrics_port: Option, - network_id: Option, node_ip: Option, node_port: Option, owner: Option, @@ -700,7 +697,6 @@ pub async fn maintain_n_running_nodes( max_archived_log_files, max_log_files, metrics_port.clone(), - network_id, node_ip, Some(PortRange::Single(port)), owner.clone(), diff --git a/ant-node-manager/src/lib.rs b/ant-node-manager/src/lib.rs index 8b2aaee95b..2b4c6a8921 100644 --- a/ant-node-manager/src/lib.rs +++ b/ant-node-manager/src/lib.rs @@ -767,7 +767,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -881,7 +880,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -960,7 +958,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1079,7 +1076,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1171,7 +1167,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1273,7 +1268,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1374,7 +1368,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1445,7 +1438,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1508,7 +1500,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1569,7 +1560,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1633,7 +1623,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1708,7 +1697,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1848,7 +1836,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -1949,7 +1936,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -2095,7 +2081,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -2253,7 +2238,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -2406,7 +2390,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -2560,7 +2543,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -2739,7 +2721,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -2911,7 +2892,6 @@ mod tests { max_archived_log_files: None, max_log_files: None, metrics_port: None, -network_id: None, node_ip: None, node_port: None, number: 1, @@ -2974,168 +2954,6 @@ network_id: None, Ok(()) } - #[tokio::test] - async fn upgrade_should_retain_the_network_id_arg() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--network-id"), - OsString::from("5"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - network_id: Some(5), - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: Default::default(), - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert_eq!(service_manager.service.service_data.network_id, Some(5)); - - Ok(()) - } - #[tokio::test] async fn upgrade_should_retain_the_local_flag() -> Result<()> { let current_version = "0.1.0"; @@ -3250,7 +3068,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -3420,7 +3237,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -3600,7 +3416,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -3775,7 +3590,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -3945,7 +3759,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4125,7 +3938,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4287,7 +4099,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, owner: None, @@ -4452,7 +4263,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -4614,7 +4424,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, number: 1, node_ip: Some(Ipv4Addr::new(192, 168, 1, 1)), node_port: None, @@ -4779,7 +4588,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, number: 1, node_ip: None, node_port: Some(12000), @@ -4940,7 +4748,6 @@ network_id: None, max_archived_log_files: Some(20), max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -5105,7 +4912,6 @@ network_id: None, max_archived_log_files: None, max_log_files: Some(20), metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -5268,7 +5074,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: Some(12000), - network_id: None, node_ip: None, node_port: None, number: 1, @@ -5433,7 +5238,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: Some(12000), - network_id: None, node_ip: None, node_port: None, number: 1, @@ -5598,7 +5402,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -5763,7 +5566,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -5939,7 +5741,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6116,7 +5917,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6281,7 +6081,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6366,7 +6165,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6435,7 +6233,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6519,7 +6316,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6598,7 +6394,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, @@ -6675,7 +6470,6 @@ network_id: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - network_id: None, node_ip: None, node_port: None, number: 1, diff --git a/ant-node-manager/src/local.rs b/ant-node-manager/src/local.rs index 6acd1d6531..9bfc06eee9 100644 --- a/ant-node-manager/src/local.rs +++ b/ant-node-manager/src/local.rs @@ -435,7 +435,6 @@ pub async fn run_node( max_archived_log_files: None, max_log_files: None, metrics_port: run_options.metrics_port, - network_id: None, node_ip: None, node_port: run_options.node_port, number: run_options.number, diff --git a/ant-node-manager/src/rpc.rs b/ant-node-manager/src/rpc.rs index 1af38833ff..a06d0ef338 100644 --- a/ant-node-manager/src/rpc.rs +++ b/ant-node-manager/src/rpc.rs @@ -74,7 +74,6 @@ pub async fn restart_node_service( max_log_files: current_node_clone.max_log_files, metrics_port: None, name: current_node_clone.service_name.clone(), - network_id: current_node_clone.network_id, node_ip: current_node_clone.node_ip, node_port: current_node_clone.get_antnode_port(), owner: current_node_clone.owner.clone(), @@ -190,7 +189,6 @@ pub async fn restart_node_service( max_archived_log_files: current_node_clone.max_archived_log_files, max_log_files: current_node_clone.max_log_files, metrics_port: None, - network_id: current_node_clone.network_id, node_ip: current_node_clone.node_ip, node_port: None, owner: None, @@ -219,7 +217,6 @@ pub async fn restart_node_service( max_archived_log_files: current_node_clone.max_archived_log_files, max_log_files: current_node_clone.max_log_files, metrics_port: None, - network_id: current_node_clone.network_id, node_ip: current_node_clone.node_ip, node_port: None, number: new_node_number as u16, diff --git a/ant-service-management/src/node.rs b/ant-service-management/src/node.rs index 3c281ba4b7..d9a91eeb12 100644 --- a/ant-service-management/src/node.rs +++ b/ant-service-management/src/node.rs @@ -77,10 +77,6 @@ impl ServiceStateActions for NodeService<'_> { args.push(OsString::from("--log-format")); args.push(OsString::from(log_fmt.as_str())); } - if let Some(id) = self.service_data.network_id { - args.push(OsString::from("--network-id")); - args.push(OsString::from(id.to_string())); - } if self.service_data.upnp { args.push(OsString::from("--upnp")); } @@ -290,7 +286,6 @@ pub struct NodeServiceData { pub metrics_port: Option, #[serde(default)] pub owner: Option, - pub network_id: Option, #[serde(default)] pub node_ip: Option, #[serde(default)] diff --git a/node-launchpad/src/node_mgmt.rs b/node-launchpad/src/node_mgmt.rs index 735f049fea..daad00123f 100644 --- a/node-launchpad/src/node_mgmt.rs +++ b/node-launchpad/src/node_mgmt.rs @@ -424,7 +424,6 @@ async fn scale_down_nodes(config: &NodeConfig, count: u16) { None, None, None, - None, None, // We don't care about the port, as we are scaling down config.owner.clone(), config.peers_args.clone(), @@ -498,7 +497,6 @@ async fn add_nodes( None, None, None, - None, port_range, config.owner.clone(), config.peers_args.clone(), From 93ff3978830c4aaa2838c6e2211929e8d72b3afc Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 10 Dec 2024 18:55:15 +0530 Subject: [PATCH 2/7] Revert "feat: use a simple network id to differentiate between network" This reverts commit c3e3fa87e3a21b3800bae09edcf7ce48d586a1ac. --- Cargo.lock | 1 - ant-bootstrap/src/config.rs | 4 +- ant-cli/Cargo.toml | 1 - ant-cli/src/main.rs | 3 - ant-cli/src/opt.rs | 6 -- ant-networking/src/driver.rs | 54 +++++-------- ant-networking/src/event/swarm.rs | 11 +-- ant-node/src/bin/antnode/main.rs | 21 +---- ant-protocol/src/version.rs | 130 ++++++++++-------------------- autonomi/src/client/mod.rs | 2 +- 10 files changed, 73 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e026f82310..e6d3183c8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -763,7 +763,6 @@ dependencies = [ "ant-bootstrap", "ant-build-info", "ant-logging", - "ant-protocol", "autonomi", "clap", "color-eyre", diff --git a/ant-bootstrap/src/config.rs b/ant-bootstrap/src/config.rs index b2c88561be..131d857694 100644 --- a/ant-bootstrap/src/config.rs +++ b/ant-bootstrap/src/config.rs @@ -7,7 +7,7 @@ // permissions and limitations relating to use of the SAFE Network Software. use crate::error::{Error, Result}; -use ant_protocol::version::{get_network_id, get_truncate_version_str}; +use ant_protocol::version::{get_key_version_str, get_truncate_version_str}; use std::{ path::{Path, PathBuf}, time::Duration, @@ -125,6 +125,6 @@ fn default_cache_path() -> Result { /// Returns the name of the cache file pub fn cache_file_name() -> String { - let network_id = format!("{}_{}", get_network_id(), get_truncate_version_str()); + let network_id = format!("{}_{}", get_key_version_str(), get_truncate_version_str()); format!("bootstrap_cache_{network_id}.json") } diff --git a/ant-cli/Cargo.toml b/ant-cli/Cargo.toml index c6eecb42f6..8f605ec14c 100644 --- a/ant-cli/Cargo.toml +++ b/ant-cli/Cargo.toml @@ -26,7 +26,6 @@ harness = false ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" } ant-build-info = { path = "../ant-build-info", version = "0.1.19" } ant-logging = { path = "../ant-logging", version = "0.2.40" } -ant-protocol = { path = "../ant-protocol", version = "0.17.15" } autonomi = { path = "../autonomi", version = "0.2.4", features = [ "fs", "vault", diff --git a/ant-cli/src/main.rs b/ant-cli/src/main.rs index c0404e9f75..b50092e538 100644 --- a/ant-cli/src/main.rs +++ b/ant-cli/src/main.rs @@ -34,9 +34,6 @@ use tracing::Level; async fn main() -> Result<()> { color_eyre::install().expect("Failed to initialise error handler"); let opt = Opt::parse(); - if let Some(network_id) = opt.network_id { - ant_protocol::version::set_network_id(network_id); - } let _log_guards = init_logging_and_metrics(&opt)?; #[cfg(feature = "metrics")] tokio::spawn(init_metrics(std::process::id())); diff --git a/ant-cli/src/opt.rs b/ant-cli/src/opt.rs index 3ffa1eb5f6..3e84379fc0 100644 --- a/ant-cli/src/opt.rs +++ b/ant-cli/src/opt.rs @@ -51,12 +51,6 @@ pub(crate) struct Opt { #[clap(long = "timeout", global = true, value_parser = |t: &str| -> Result { Ok(t.parse().map(Duration::from_secs)?) })] pub connection_timeout: Option, - /// Specify the network ID to use. This will allow you to run the CLI on a different network. - /// - /// By default, the network ID is set to 1, which represents the mainnet. - #[clap(long, verbatim_doc_comment)] - pub network_id: Option, - /// Prevent verification of data storage on the network. /// /// This may increase operation speed, but offers no guarantees that operations were successful. diff --git a/ant-networking/src/driver.rs b/ant-networking/src/driver.rs index f259b82dab..e0c66d2c9e 100644 --- a/ant-networking/src/driver.rs +++ b/ant-networking/src/driver.rs @@ -35,7 +35,7 @@ use ant_protocol::{ messages::{ChunkProof, Nonce, Request, Response}, storage::{try_deserialize_record, RetryStrategy}, version::{ - get_network_id, IDENTIFY_CLIENT_VERSION_STR, IDENTIFY_NODE_VERSION_STR, + get_key_version_str, IDENTIFY_CLIENT_VERSION_STR, IDENTIFY_NODE_VERSION_STR, IDENTIFY_PROTOCOL_STR, REQ_RESPONSE_VERSION_STR, }, NetworkAddress, PrettyPrintKBucketKey, PrettyPrintRecordKey, @@ -267,16 +267,16 @@ pub(super) struct NodeBehaviour { #[derive(Debug)] pub struct NetworkBuilder { bootstrap_cache: Option, - concurrency_limit: Option, is_behind_home_network: bool, keypair: Keypair, - listen_addr: Option, local: bool, + listen_addr: Option, + request_timeout: Option, + concurrency_limit: Option, #[cfg(feature = "open-metrics")] metrics_registries: Option, #[cfg(feature = "open-metrics")] metrics_server_port: Option, - request_timeout: Option, #[cfg(feature = "upnp")] upnp: bool, } @@ -285,16 +285,16 @@ impl NetworkBuilder { pub fn new(keypair: Keypair, local: bool) -> Self { Self { bootstrap_cache: None, - concurrency_limit: None, is_behind_home_network: false, keypair, - listen_addr: None, local, + listen_addr: None, + request_timeout: None, + concurrency_limit: None, #[cfg(feature = "open-metrics")] metrics_registries: None, #[cfg(feature = "open-metrics")] metrics_server_port: None, - request_timeout: None, #[cfg(feature = "upnp")] upnp: false, } @@ -394,7 +394,7 @@ impl NetworkBuilder { check_and_wipe_storage_dir_if_necessary( root_dir.clone(), storage_dir_path.clone(), - get_network_id(), + get_key_version_str(), )?; // Configures the disk_store to store records under the provided path and increase the max record size @@ -431,6 +431,7 @@ impl NetworkBuilder { Some(store_cfg), false, ProtocolSupport::Full, + IDENTIFY_NODE_VERSION_STR.to_string(), #[cfg(feature = "upnp")] upnp, )?; @@ -470,6 +471,7 @@ impl NetworkBuilder { None, true, ProtocolSupport::Outbound, + IDENTIFY_CLIENT_VERSION_STR.to_string(), #[cfg(feature = "upnp")] false, )?; @@ -484,13 +486,9 @@ impl NetworkBuilder { record_store_cfg: Option, is_client: bool, req_res_protocol: ProtocolSupport, + identify_version: String, #[cfg(feature = "upnp")] upnp: bool, ) -> Result<(Network, mpsc::Receiver, SwarmDriver)> { - let identify_protocol_str = IDENTIFY_PROTOCOL_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_PROTOCOL_STR") - .clone(); - let peer_id = PeerId::from(self.keypair.public()); // vdash metric (if modified please notify at https://github.com/happybeing/vdash/issues): #[cfg(not(target_arch = "wasm32"))] @@ -554,7 +552,7 @@ impl NetworkBuilder { "The protocol version string that is used to connect to the correct network", Info::new(vec![( "identify_protocol_str".to_string(), - identify_protocol_str.clone(), + IDENTIFY_PROTOCOL_STR.to_string(), )]), ); @@ -568,16 +566,14 @@ impl NetworkBuilder { let request_response = { let cfg = RequestResponseConfig::default() .with_request_timeout(self.request_timeout.unwrap_or(REQUEST_TIMEOUT_DEFAULT_S)); - let req_res_version_str = REQ_RESPONSE_VERSION_STR - .read() - .expect("Failed to obtain read lock for REQ_RESPONSE_VERSION_STR") - .clone(); - info!("Building request response with {req_res_version_str:?}",); + info!( + "Building request response with {:?}", + REQ_RESPONSE_VERSION_STR.as_str() + ); request_response::cbor::Behaviour::new( [( - StreamProtocol::try_from_owned(req_res_version_str) - .expect("StreamProtocol should start with a /"), + StreamProtocol::new(&REQ_RESPONSE_VERSION_STR), req_res_protocol, )], cfg, @@ -633,22 +629,12 @@ impl NetworkBuilder { #[cfg(feature = "local")] let mdns = mdns::tokio::Behaviour::new(mdns_config, peer_id)?; - let agent_version = if is_client { - IDENTIFY_CLIENT_VERSION_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_CLIENT_VERSION_STR") - .clone() - } else { - IDENTIFY_NODE_VERSION_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_NODE_VERSION_STR") - .clone() - }; // Identify Behaviour - info!("Building Identify with identify_protocol_str: {identify_protocol_str:?} and identify_protocol_str: {identify_protocol_str:?}"); + let identify_protocol_str = IDENTIFY_PROTOCOL_STR.to_string(); + info!("Building Identify with identify_protocol_str: {identify_protocol_str:?} and identify_version: {identify_version:?}"); let identify = { let cfg = libp2p::identify::Config::new(identify_protocol_str, self.keypair.public()) - .with_agent_version(agent_version) + .with_agent_version(identify_version) // Enlength the identify interval from default 5 mins to 1 hour. .with_interval(RESEND_IDENTIFY_INVERVAL); libp2p::identify::Behaviour::new(cfg) diff --git a/ant-networking/src/event/swarm.rs b/ant-networking/src/event/swarm.rs index 3bf65eb6d9..84127c43d3 100644 --- a/ant-networking/src/event/swarm.rs +++ b/ant-networking/src/event/swarm.rs @@ -124,13 +124,11 @@ impl SwarmDriver { } => { debug!(conn_id=%connection_id, %peer_id, ?info, "identify: received info"); - let our_identify_protocol = IDENTIFY_PROTOCOL_STR.read().expect("IDENTIFY_PROTOCOL_STR has been locked to write. A call to set_network_id performed. This should not happen.").to_string(); - - if info.protocol_version != our_identify_protocol { - warn!(?info.protocol_version, "identify: {peer_id:?} does not have the same protocol. Our IDENTIFY_PROTOCOL_STR: {our_identify_protocol:?}"); + if info.protocol_version != IDENTIFY_PROTOCOL_STR.to_string() { + warn!(?info.protocol_version, "identify: {peer_id:?} does not have the same protocol. Our IDENTIFY_PROTOCOL_STR: {:?}", IDENTIFY_PROTOCOL_STR.as_str()); self.send_event(NetworkEvent::PeerWithUnsupportedProtocol { - our_protocol: our_identify_protocol, + our_protocol: IDENTIFY_PROTOCOL_STR.to_string(), their_protocol: info.protocol_version, }); // Block the peer from any further communication. @@ -145,9 +143,8 @@ impl SwarmDriver { return Ok(()); } - let our_agent_version = IDENTIFY_NODE_VERSION_STR.read().expect("IDENTIFY_NODE_VERSION_STR has been locked to write. A call to set_network_id performed. This should not happen.").to_string(); // if client, return. - if info.agent_version != our_agent_version { + if info.agent_version != IDENTIFY_NODE_VERSION_STR.to_string() { return Ok(()); } diff --git a/ant-node/src/bin/antnode/main.rs b/ant-node/src/bin/antnode/main.rs index db40d00101..ec8d759f7b 100644 --- a/ant-node/src/bin/antnode/main.rs +++ b/ant-node/src/bin/antnode/main.rs @@ -22,7 +22,7 @@ use ant_node::{Marker, NodeBuilder, NodeEvent, NodeEventsReceiver}; use ant_protocol::{ node::get_antnode_root_dir, node_rpc::{NodeCtrl, StopResult}, - version, + version::IDENTIFY_PROTOCOL_STR, }; use clap::{command, Parser}; use color_eyre::{eyre::eyre, Result}; @@ -128,12 +128,6 @@ struct Opt { #[clap(long, verbatim_doc_comment)] max_archived_log_files: Option, - /// 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, - /// Specify the rewards address. /// The rewards address is the address that will receive the rewards for the node. /// It should be a valid EVM address. @@ -223,20 +217,13 @@ fn main() -> Result<()> { color_eyre::install()?; let opt = Opt::parse(); - if let Some(network_id) = opt.network_id { - version::set_network_id(network_id); - } - - let identify_protocol_str = version::IDENTIFY_PROTOCOL_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_PROTOCOL_STR"); if opt.version { println!( "{}", ant_build_info::version_string( "Autonomi Node", env!("CARGO_PKG_VERSION"), - Some(&identify_protocol_str) + Some(&IDENTIFY_PROTOCOL_STR) ) ); return Ok(()); @@ -253,7 +240,7 @@ fn main() -> Result<()> { } if opt.protocol_version { - println!("Network version: {identify_protocol_str}"); + println!("Network version: {}", *IDENTIFY_PROTOCOL_STR); return Ok(()); } @@ -292,7 +279,7 @@ fn main() -> Result<()> { ); info!("\n{}\n{}", msg, "=".repeat(msg.len())); - ant_build_info::log_version_info(env!("CARGO_PKG_VERSION"), &identify_protocol_str); + ant_build_info::log_version_info(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR); debug!( "antnode built with git version: {}", ant_build_info::git_info() diff --git a/ant-protocol/src/version.rs b/ant-protocol/src/version.rs index 3d5c92cfab..6606e74be0 100644 --- a/ant-protocol/src/version.rs +++ b/ant-protocol/src/version.rs @@ -7,83 +7,39 @@ // permissions and limitations relating to use of the SAFE Network Software. use lazy_static::lazy_static; -use std::sync::RwLock; lazy_static! { - /// The network_id is used to differentiate between different networks. - /// The default is set to 1 and it represents the mainnet. - pub static ref NETWORK_ID: RwLock = RwLock::new(1); - /// The node version used during Identify Behaviour. - pub static ref IDENTIFY_NODE_VERSION_STR: RwLock = - RwLock::new(format!( - "ant/node/{}/{}", + pub static ref IDENTIFY_NODE_VERSION_STR: String = + format!( + "safe/node/{}/{}", get_truncate_version_str(), - *NETWORK_ID.read().expect("Failed to obtain read lock for NETWORK_ID"), - )); + get_key_version_str(), + ); /// The client version used during Identify Behaviour. - pub static ref IDENTIFY_CLIENT_VERSION_STR: RwLock = - RwLock::new(format!( - "ant/client/{}/{}", + pub static ref IDENTIFY_CLIENT_VERSION_STR: String = + format!( + "safe/client/{}/{}", get_truncate_version_str(), - *NETWORK_ID.read().expect("Failed to obtain read lock for NETWORK_ID"), - )); + get_key_version_str(), + ); /// The req/response protocol version - pub static ref REQ_RESPONSE_VERSION_STR: RwLock = - RwLock::new(format!( - "/ant/{}/{}", + pub static ref REQ_RESPONSE_VERSION_STR: String = + format!( + "/safe/node/{}/{}", get_truncate_version_str(), - *NETWORK_ID.read().expect("Failed to obtain read lock for NETWORK_ID"), - )); + get_key_version_str(), + ); /// The identify protocol version - pub static ref IDENTIFY_PROTOCOL_STR: RwLock = - RwLock::new(format!( - "ant/{}/{}", + pub static ref IDENTIFY_PROTOCOL_STR: String = + format!( + "safe/{}/{}", get_truncate_version_str(), - *NETWORK_ID.read().expect("Failed to obtain read lock for NETWORK_ID"), - )); -} - -/// Update the NETWORK_ID and all the version strings that depend on it. -/// By default, the network id is set to 1 which represents the mainnet. -/// -/// This should be called before starting the node or client. -/// The values will be read often and this can cause issues if the values are changed after the node is started. -pub fn set_network_id(id: u8) { - let mut network_id = NETWORK_ID - .write() - .expect("Failed to obtain write lock for NETWORK_ID"); - *network_id = id; - - let mut node_version = IDENTIFY_NODE_VERSION_STR - .write() - .expect("Failed to obtain write lock for IDENTIFY_NODE_VERSION_STR"); - *node_version = format!("ant/node/{}/{}", get_truncate_version_str(), id); - let mut client_version = IDENTIFY_CLIENT_VERSION_STR - .write() - .expect("Failed to obtain write lock for IDENTIFY_CLIENT_VERSION_STR"); - *client_version = format!("ant/client/{}/{}", get_truncate_version_str(), id); - let mut req_response_version = REQ_RESPONSE_VERSION_STR - .write() - .expect("Failed to obtain write lock for REQ_RESPONSE_VERSION_STR"); - *req_response_version = format!("/ant/{}/{}", get_truncate_version_str(), id); - let mut identify_protocol = IDENTIFY_PROTOCOL_STR - .write() - .expect("Failed to obtain write lock for IDENTIFY_PROTOCOL_STR"); - *identify_protocol = format!("ant/{}/{}", get_truncate_version_str(), id); -} - -/// Get the current NETWORK_ID as string. -pub fn get_network_id() -> String { - format!( - "{}", - *NETWORK_ID - .read() - .expect("Failed to obtain read lock for NETWORK_ID") - ) + get_key_version_str(), + ); } // Protocol support shall be downward compatible for patch only version update. @@ -98,44 +54,42 @@ pub fn get_truncate_version_str() -> String { } } +/// FIXME: Remove this once BEFORE next breaking release and fix this whole file +/// Get the PKs version string. +/// If the public key mis-configed via env variable, +/// it shall result in being rejected to join by the network +pub fn get_key_version_str() -> String { + // let mut f_k_str = FOUNDATION_PK.to_hex(); + // let _ = f_k_str.split_off(6); + // let mut g_k_str = GENESIS_PK.to_hex(); + // let _ = g_k_str.split_off(6); + // let mut n_k_str = NETWORK_ROYALTIES_PK.to_hex(); + // let _ = n_k_str.split_off(6); + // let s = format!("{f_k_str}_{g_k_str}_{n_k_str}"); + // dbg!(&s); + "b20c91_93f735_af451a".to_string() +} #[cfg(test)] mod tests { use super::*; #[test] fn test_print_version_strings() -> Result<(), Box> { + // Test and print all version strings println!( - "\nIDENTIFY_NODE_VERSION_STR: {}", - *IDENTIFY_NODE_VERSION_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_NODE_VERSION_STR") - ); - println!( - "IDENTIFY_CLIENT_VERSION_STR: {}", + "\nIDENTIFY_CLIENT_VERSION_STR: {}", *IDENTIFY_CLIENT_VERSION_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_CLIENT_VERSION_STR") - ); - println!( - "REQ_RESPONSE_VERSION_STR: {}", - *REQ_RESPONSE_VERSION_STR - .read() - .expect("Failed to obtain read lock for REQ_RESPONSE_VERSION_STR") - ); - println!( - "IDENTIFY_PROTOCOL_STR: {}", - *IDENTIFY_PROTOCOL_STR - .read() - .expect("Failed to obtain read lock for IDENTIFY_PROTOCOL_STR") ); + println!("REQ_RESPONSE_VERSION_STR: {}", *REQ_RESPONSE_VERSION_STR); + println!("IDENTIFY_PROTOCOL_STR: {}", *IDENTIFY_PROTOCOL_STR); // Test truncated version string let truncated = get_truncate_version_str(); println!("\nTruncated version: {truncated}"); - // Test network id string - let network_id = get_network_id(); - println!("Network ID string: {network_id}"); + // Test key version string + let key_version = get_key_version_str(); + println!("\nKey version string: {key_version}"); Ok(()) } diff --git a/autonomi/src/client/mod.rs b/autonomi/src/client/mod.rs index d14964f9f1..acc62981da 100644 --- a/autonomi/src/client/mod.rs +++ b/autonomi/src/client/mod.rs @@ -177,7 +177,7 @@ async fn handle_event_receiver( sender .send(Err(ConnectError::TimedOutWithIncompatibleProtocol( protocols, - IDENTIFY_PROTOCOL_STR.read().expect("Failed to obtain read lock for IDENTIFY_PROTOCOL_STR. A call to set_network_id performed. This should not happen").clone(), + IDENTIFY_PROTOCOL_STR.to_string(), ))) .expect("receiver should not close"); } else { From b28ff8eae18197d07f52cd3ea1eb110b09abc271 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 10 Dec 2024 18:55:34 +0530 Subject: [PATCH 3/7] Revert "fix(bootstrap): tiny fixes and limit get_addrs count" This reverts commit c99cf8926d84878b4818c74253a5ffd3e2fdf95e. --- ant-bootstrap/src/initial_peers.rs | 29 ++++++++++---------- ant-bootstrap/tests/address_format_tests.rs | 12 ++++---- ant-bootstrap/tests/cli_integration_tests.rs | 14 +++++----- ant-cli/src/access/network.rs | 2 +- ant-node-manager/src/cmd/local.rs | 19 +++++++++++-- ant-node/src/bin/antnode/main.rs | 2 +- 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/ant-bootstrap/src/initial_peers.rs b/ant-bootstrap/src/initial_peers.rs index afa983b0de..64cd6972a7 100644 --- a/ant-bootstrap/src/initial_peers.rs +++ b/ant-bootstrap/src/initial_peers.rs @@ -79,28 +79,22 @@ pub struct PeersArgs { } impl PeersArgs { - /// Get bootstrap peers sorted by the failure rate. The peer with the lowest failure rate will be - /// the first in the list. + /// Get bootstrap peers /// Order of precedence: /// 1. Addresses from arguments /// 2. Addresses from environment variable SAFE_PEERS /// 3. Addresses from cache. `Self::bootstrap_cache_dir` will take precedence over the path provided inside `config` /// 4. Addresses from network contacts URL - pub async fn get_addrs( - &self, - config: Option, - count: Option, - ) -> Result> { + pub async fn get_addrs(&self, config: Option) -> Result> { Ok(self - .get_bootstrap_addr(config, count) + .get_bootstrap_addr(config) .await? .into_iter() .map(|addr| addr.addr) .collect()) } - /// Get bootstrap peers sorted by the failure rate. The peer with the lowest failure rate will be - /// the first in the list. + /// Get bootstrap peers /// Order of precedence: /// 1. Addresses from arguments /// 2. Addresses from environment variable SAFE_PEERS @@ -109,7 +103,6 @@ impl PeersArgs { pub async fn get_bootstrap_addr( &self, config: Option, - count: Option, ) -> Result> { // If this is the first node, return an empty list if self.first { @@ -153,6 +146,12 @@ impl PeersArgs { bootstrap_addresses.extend(addrs); } + // Return here if we fetched peers from the args + if !bootstrap_addresses.is_empty() { + bootstrap_addresses.sort_by_key(|addr| addr.failure_rate() as u64); + return Ok(bootstrap_addresses); + } + // load from cache if present if !self.ignore_cache { let cfg = if let Some(config) = config { @@ -180,6 +179,11 @@ impl PeersArgs { } } + if !bootstrap_addresses.is_empty() { + bootstrap_addresses.sort_by_key(|addr| addr.failure_rate() as u64); + return Ok(bootstrap_addresses); + } + if !self.disable_mainnet_contacts { let contacts_fetcher = ContactsFetcher::with_mainnet_endpoints()?; let addrs = contacts_fetcher.fetch_bootstrap_addresses().await?; @@ -188,9 +192,6 @@ impl PeersArgs { if !bootstrap_addresses.is_empty() { bootstrap_addresses.sort_by_key(|addr| addr.failure_rate() as u64); - if let Some(count) = count { - bootstrap_addresses.truncate(count); - } Ok(bootstrap_addresses) } else { error!("No initial bootstrap peers found through any means"); diff --git a/ant-bootstrap/tests/address_format_tests.rs b/ant-bootstrap/tests/address_format_tests.rs index 88369f4cd8..a953608039 100644 --- a/ant-bootstrap/tests/address_format_tests.rs +++ b/ant-bootstrap/tests/address_format_tests.rs @@ -47,12 +47,12 @@ async fn test_multiaddr_format_parsing() -> Result<(), Box Result<(), Box addrs: vec![], network_contacts_url: vec![format!("{}/peers", mock_server.uri()).parse()?], local: false, - disable_mainnet_contacts: true, - ignore_cache: true, + disable_mainnet_contacts: false, + ignore_cache: false, bootstrap_cache_dir: None, }; - let addrs = args.get_bootstrap_addr(None, None).await?; + let addrs = args.get_bootstrap_addr(None).await?; assert_eq!( addrs.len(), 2, diff --git a/ant-bootstrap/tests/cli_integration_tests.rs b/ant-bootstrap/tests/cli_integration_tests.rs index 98341ae452..8ac0ab571b 100644 --- a/ant-bootstrap/tests/cli_integration_tests.rs +++ b/ant-bootstrap/tests/cli_integration_tests.rs @@ -38,7 +38,7 @@ async fn test_first_flag() -> Result<(), Box> { bootstrap_cache_dir: None, }; - let addrs = args.get_addrs(Some(config), None).await?; + let addrs = args.get_addrs(Some(config)).await?; assert!(addrs.is_empty(), "First node should have no addrs"); @@ -64,7 +64,7 @@ async fn test_peer_argument() -> Result<(), Box> { bootstrap_cache_dir: None, }; - let addrs = args.get_addrs(None, None).await?; + let addrs = args.get_addrs(None).await?; assert_eq!(addrs.len(), 1, "Should have one addr"); assert_eq!(addrs[0], peer_addr, "Should have the correct address"); @@ -94,12 +94,12 @@ async fn test_network_contacts_fallback() -> Result<(), Box Result<(), Box> { bootstrap_cache_dir: None, }; - let addrs = args.get_addrs(Some(config), None).await?; + let addrs = args.get_addrs(Some(config)).await?; assert!(addrs.is_empty(), "Local mode should have no peers"); @@ -166,7 +166,7 @@ async fn test_test_network_peers() -> Result<(), Box> { bootstrap_cache_dir: None, }; - let addrs = args.get_addrs(Some(config), None).await?; + let addrs = args.get_addrs(Some(config)).await?; assert_eq!(addrs.len(), 1, "Should have exactly one test network peer"); assert_eq!( diff --git a/ant-cli/src/access/network.rs b/ant-cli/src/access/network.rs index 8c428e06d3..acf7acfae6 100644 --- a/ant-cli/src/access/network.rs +++ b/ant-cli/src/access/network.rs @@ -13,7 +13,7 @@ use color_eyre::Result; use color_eyre::Section; pub async fn get_peers(peers: PeersArgs) -> Result> { - peers.get_addrs(None, Some(100)).await + peers.get_addrs(None).await .wrap_err("Please provide valid Network peers to connect to") .with_suggestion(|| format!("make sure you've provided network peers using the --peers option or the {ANT_PEERS_ENV} env var")) .with_suggestion(|| "a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere") diff --git a/ant-node-manager/src/cmd/local.rs b/ant-node-manager/src/cmd/local.rs index 2f0b3b465b..cdf0bd375c 100644 --- a/ant-node-manager/src/cmd/local.rs +++ b/ant-node-manager/src/cmd/local.rs @@ -36,7 +36,7 @@ pub async fn join( log_format: Option, owner: Option, owner_prefix: Option, - _peers_args: PeersArgs, + peers_args: PeersArgs, rpc_port: Option, rewards_address: RewardsAddress, evm_network: Option, @@ -70,6 +70,21 @@ pub async fn join( ) .await?; + // If no peers are obtained we will attempt to join the existing local network, if one + // is running. + let peers = match peers_args.get_addrs(None).await { + Ok(peers) => Some(peers), + Err(err) => match err { + ant_bootstrap::error::Error::NoBootstrapPeersFound => { + warn!("PeersNotObtained, peers is set to None"); + None + } + _ => { + error!("Failed to obtain peers: {err:?}"); + return Err(err.into()); + } + }, + }; let options = LocalNetworkOptions { antnode_bin_path, enable_metrics_server, @@ -80,7 +95,7 @@ pub async fn join( node_port, owner, owner_prefix, - peers: None, + peers, rpc_port, skip_validation, log_format, diff --git a/ant-node/src/bin/antnode/main.rs b/ant-node/src/bin/antnode/main.rs index ec8d759f7b..6246206211 100644 --- a/ant-node/src/bin/antnode/main.rs +++ b/ant-node/src/bin/antnode/main.rs @@ -295,7 +295,7 @@ fn main() -> Result<()> { // another process with these args. #[cfg(feature = "metrics")] rt.spawn(init_metrics(std::process::id())); - let initial_peres = rt.block_on(opt.peers.get_addrs(None, Some(100)))?; + let initial_peres = rt.block_on(opt.peers.get_addrs(None))?; debug!("Node's owner set to: {:?}", opt.owner); let restart_options = rt.block_on(async move { let mut node_builder = NodeBuilder::new( From c56f4dca5aca2a188ddfb5dac8c7975d5baee0ef Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 10 Dec 2024 18:55:53 +0530 Subject: [PATCH 4/7] Revert "fix(bootstrap): do not error out if the network contacts list is empty" This reverts commit bd9934ddfc1f226c04a3c1a94db021a2ba638c2a. --- ant-bootstrap/src/contacts.rs | 90 ++++++++++++++++++++++++++++------- ant-bootstrap/src/error.rs | 2 + 2 files changed, 75 insertions(+), 17 deletions(-) diff --git a/ant-bootstrap/src/contacts.rs b/ant-bootstrap/src/contacts.rs index 24d9ac9bcf..83262fbc1a 100644 --- a/ant-bootstrap/src/contacts.rs +++ b/ant-bootstrap/src/contacts.rs @@ -95,6 +95,7 @@ impl ContactsFetcher { self.endpoints ); let mut bootstrap_addresses = Vec::new(); + let mut last_error = None; let mut fetches = stream::iter(self.endpoints.clone()) .map(|endpoint| async move { @@ -130,16 +131,37 @@ impl ContactsFetcher { } Err(e) => { warn!("Failed to fetch bootstrap addrs from {}: {}", endpoint, e); + last_error = Some(e); } } } - info!( - "Successfully discovered {} total addresses. First few: {:?}", - bootstrap_addresses.len(), - bootstrap_addresses.iter().take(3).collect::>() - ); - Ok(bootstrap_addresses) + if bootstrap_addresses.is_empty() { + last_error.map_or_else( + || { + warn!("No bootstrap addrs found from any endpoint and no errors reported"); + Err(Error::NoBootstrapAddressesFound( + "No valid peers found from any endpoint".to_string(), + )) + }, + |e| { + warn!( + "No bootstrap addrs found from any endpoint. Last error: {}", + e + ); + Err(Error::NoBootstrapAddressesFound(format!( + "No valid bootstrap addrs found from any endpoint: {e}", + ))) + }, + ) + } else { + info!( + "Successfully discovered {} total addresses. First few: {:?}", + bootstrap_addresses.len(), + bootstrap_addresses.iter().take(3).collect::>() + ); + Ok(bootstrap_addresses) + } } /// Fetch the list of multiaddrs from a single endpoint @@ -222,13 +244,20 @@ impl ContactsFetcher { }) .collect::>(); - info!( - "Successfully parsed {} valid peers from JSON", - bootstrap_addresses.len() - ); - Ok(bootstrap_addresses) + if bootstrap_addresses.is_empty() { + warn!("No valid peers found in JSON response"); + Err(Error::NoBootstrapAddressesFound( + "No valid peers found in JSON response".to_string(), + )) + } else { + info!( + "Successfully parsed {} valid peers from JSON", + bootstrap_addresses.len() + ); + Ok(bootstrap_addresses) + } } - Err(_err) => { + Err(e) => { info!("Attempting to parse response as plain text"); // Try parsing as plain text with one multiaddr per line // example of contacts file exists in resources/network-contacts-examples @@ -237,11 +266,20 @@ impl ContactsFetcher { .filter_map(|str| craft_valid_multiaddr_from_str(str, ignore_peer_id)) .collect::>(); - info!( - "Successfully parsed {} valid bootstrap addrs from plain text", - bootstrap_addresses.len() - ); - Ok(bootstrap_addresses) + if bootstrap_addresses.is_empty() { + warn!( + "No valid bootstrap addrs found in plain text response. Previous Json error: {e:?}" + ); + Err(Error::NoBootstrapAddressesFound( + "No valid bootstrap addrs found in plain text response".to_string(), + )) + } else { + info!( + "Successfully parsed {} valid bootstrap addrs from plain text", + bootstrap_addresses.len() + ); + Ok(bootstrap_addresses) + } } } } @@ -349,6 +387,24 @@ mod tests { assert_eq!(addrs[0].addr, valid_addr); } + #[tokio::test] + async fn test_empty_response() { + let mock_server = MockServer::start().await; + + Mock::given(method("GET")) + .and(path("/")) + .respond_with(ResponseTemplate::new(200).set_body_string("")) + .mount(&mock_server) + .await; + + let mut fetcher = ContactsFetcher::new().unwrap(); + fetcher.endpoints = vec![mock_server.uri().parse().unwrap()]; + + let result = fetcher.fetch_bootstrap_addresses().await; + + assert!(matches!(result, Err(Error::NoBootstrapAddressesFound(_)))); + } + #[tokio::test] async fn test_whitespace_and_empty_lines() { let mock_server = MockServer::start().await; diff --git a/ant-bootstrap/src/error.rs b/ant-bootstrap/src/error.rs index a2eedfeee5..bc735b753a 100644 --- a/ant-bootstrap/src/error.rs +++ b/ant-bootstrap/src/error.rs @@ -20,6 +20,8 @@ pub enum Error { InvalidBootstrapCacheDir, #[error("Could not obtain bootstrap addresses from {0} after {1} retries")] FailedToObtainAddrsFromUrl(String, usize), + #[error("No Bootstrap Addresses found: {0}")] + NoBootstrapAddressesFound(String), #[error("Failed to parse Url")] FailedToParseUrl, #[error("IO error: {0}")] From 2d5ee987f4ff1ff927a52c9617c24d333ed114f7 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 10 Dec 2024 18:56:02 +0530 Subject: [PATCH 5/7] Revert "feat(antctl): use custom bootstrap cache path for root users" This reverts commit 3937031875fdb217f6f0c38f0d7aab9693142291. --- ant-node-manager/src/cmd/node.rs | 6 ------ ant-node-manager/src/config.rs | 16 ---------------- 2 files changed, 22 deletions(-) diff --git a/ant-node-manager/src/cmd/node.rs b/ant-node-manager/src/cmd/node.rs index fd4b938bbc..a96a0bb118 100644 --- a/ant-node-manager/src/cmd/node.rs +++ b/ant-node-manager/src/cmd/node.rs @@ -83,11 +83,6 @@ pub async fn add( config::get_service_data_dir_path(data_dir_path, service_user.clone())?; let service_log_dir_path = config::get_service_log_dir_path(ReleaseType::AntNode, log_dir_path, service_user.clone())?; - let bootstrap_cache_dir = if let Some(user) = &service_user { - Some(config::get_bootstrap_cache_owner_path(user)?) - } else { - None - }; let mut node_registry = NodeRegistry::load(&config::get_node_registry_path()?)?; let release_repo = ::default_config(); @@ -110,7 +105,6 @@ pub async fn add( debug!("Parsing peers from PeersArgs"); peers_args.addrs.extend(PeersArgs::read_addr_from_env()); - peers_args.bootstrap_cache_dir = bootstrap_cache_dir; let options = AddNodeServiceOptions { auto_restart, diff --git a/ant-node-manager/src/config.rs b/ant-node-manager/src/config.rs index 946afdf5ab..f0c47f7ab2 100644 --- a/ant-node-manager/src/config.rs +++ b/ant-node-manager/src/config.rs @@ -159,22 +159,6 @@ pub fn get_service_data_dir_path( Ok(path) } -/// Get the bootstrap cache owner path -#[cfg(unix)] -pub fn get_bootstrap_cache_owner_path(owner: &str) -> Result { - let path = PathBuf::from("/var/antctl/bootstrap_cache"); - - create_owned_dir(path.clone(), owner)?; - Ok(path) -} - -#[cfg(windows)] -pub fn get_bootstrap_cache_owner_path(_owner: &str) -> Result { - let path = PathBuf::from("C:\\ProgramData\\antctl\\bootstrap_cache"); - std::fs::create_dir_all(&path)?; - Ok(path) -} - /// Get the logging directory for the service. /// /// It's a little counter-intuitive, but the owner will be `None` in the case of a user-mode From bbb03b544a93eafdfc87da395f03cc38c329b53e Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 10 Dec 2024 18:56:20 +0530 Subject: [PATCH 6/7] Revert "feat(bootstrap): allow writing or reading from custom bootstrap cache dir" This reverts commit c1c9981bf2cfab14213f430c15d16e6a4a22c1d7. --- ant-bootstrap/src/cache_store.rs | 10 +- ant-bootstrap/src/config.rs | 9 +- ant-bootstrap/src/error.rs | 2 - ant-bootstrap/src/initial_peers.rs | 41 +--- ant-bootstrap/tests/address_format_tests.rs | 2 - ant-bootstrap/tests/cli_integration_tests.rs | 5 - ant-node-manager/src/add_services/tests.rs | 173 ----------------- ant-node-manager/src/lib.rs | 188 +------------------ ant-node-manager/src/local.rs | 1 - ant-service-management/src/node.rs | 4 - 10 files changed, 9 insertions(+), 426 deletions(-) diff --git a/ant-bootstrap/src/cache_store.rs b/ant-bootstrap/src/cache_store.rs index eabffd6164..c435fbec23 100644 --- a/ant-bootstrap/src/cache_store.rs +++ b/ant-bootstrap/src/cache_store.rs @@ -181,21 +181,15 @@ impl BootstrapCacheStore { /// Create a empty CacheStore from the given peers argument. /// This also modifies the cfg if provided based on the PeersArgs. /// And also performs some actions based on the PeersArgs. - /// - /// `PeersArgs::bootstrap_cache_dir` will take precedence over the path provided inside `config`. pub fn new_from_peers_args( peers_arg: &PeersArgs, - config: Option, + cfg: Option, ) -> Result { - let mut config = if let Some(cfg) = config { + let config = if let Some(cfg) = cfg { cfg } else { BootstrapCacheConfig::default_config()? }; - if let Some(bootstrap_cache_path) = peers_arg.get_bootstrap_cache_path()? { - config.cache_file_path = bootstrap_cache_path; - } - let mut store = Self::new(config)?; // If it is the first node, clear the cache. diff --git a/ant-bootstrap/src/config.rs b/ant-bootstrap/src/config.rs index 131d857694..52d85b7dee 100644 --- a/ant-bootstrap/src/config.rs +++ b/ant-bootstrap/src/config.rs @@ -118,13 +118,8 @@ fn default_cache_path() -> Result { std::fs::create_dir_all(&dir)?; - let path = dir.join(cache_file_name()); + let network_id = format!("{}_{}", get_key_version_str(), get_truncate_version_str()); + let path = dir.join(format!("bootstrap_cache_{}.json", network_id)); Ok(path) } - -/// Returns the name of the cache file -pub fn cache_file_name() -> String { - let network_id = format!("{}_{}", get_key_version_str(), get_truncate_version_str()); - format!("bootstrap_cache_{network_id}.json") -} diff --git a/ant-bootstrap/src/error.rs b/ant-bootstrap/src/error.rs index bc735b753a..70da2ca80a 100644 --- a/ant-bootstrap/src/error.rs +++ b/ant-bootstrap/src/error.rs @@ -16,8 +16,6 @@ pub enum Error { FailedToParseCacheData, #[error("Could not obtain data directory")] CouldNotObtainDataDir, - #[error("Invalid bootstrap cache directory")] - InvalidBootstrapCacheDir, #[error("Could not obtain bootstrap addresses from {0} after {1} retries")] FailedToObtainAddrsFromUrl(String, usize), #[error("No Bootstrap Addresses found: {0}")] diff --git a/ant-bootstrap/src/initial_peers.rs b/ant-bootstrap/src/initial_peers.rs index 64cd6972a7..daf20d1480 100644 --- a/ant-bootstrap/src/initial_peers.rs +++ b/ant-bootstrap/src/initial_peers.rs @@ -7,7 +7,6 @@ // permissions and limitations relating to use of the SAFE Network Software. use crate::{ - config::cache_file_name, craft_valid_multiaddr, craft_valid_multiaddr_from_str, error::{Error, Result}, BootstrapAddr, BootstrapCacheConfig, BootstrapCacheStore, ContactsFetcher, @@ -15,7 +14,6 @@ use crate::{ use clap::Args; use libp2p::Multiaddr; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; use url::Url; /// The name of the environment variable that can be used to pass peers to the node. @@ -63,27 +61,17 @@ pub struct PeersArgs { /// This disables fetching peers from the mainnet network contacts. #[clap(name = "testnet", long)] pub disable_mainnet_contacts: bool, + /// Set to not load the bootstrap addresses from the local cache. #[clap(long, default_value = "false")] pub ignore_cache: bool, - /// The directory to load and store the bootstrap cache. If not provided, the default path will be used. - /// - /// The JSON filename will be derived automatically from the network ID - /// - /// The default location is platform specific: - /// - Linux: $HOME/.local/share/autonomi/bootstrap_cache/bootstrap_cache_.json - /// - macOS: $HOME/Library/Application Support/autonomi/bootstrap_cache/bootstrap_cache_.json - /// - Windows: C:\Users\\AppData\Roaming\autonomi\bootstrap_cache\bootstrap_cache_.json - #[clap(long)] - pub bootstrap_cache_dir: Option, } - impl PeersArgs { /// Get bootstrap peers /// Order of precedence: /// 1. Addresses from arguments /// 2. Addresses from environment variable SAFE_PEERS - /// 3. Addresses from cache. `Self::bootstrap_cache_dir` will take precedence over the path provided inside `config` + /// 3. Addresses from cache /// 4. Addresses from network contacts URL pub async fn get_addrs(&self, config: Option) -> Result> { Ok(self @@ -98,7 +86,7 @@ impl PeersArgs { /// Order of precedence: /// 1. Addresses from arguments /// 2. Addresses from environment variable SAFE_PEERS - /// 3. Addresses from cache. `Self::bootstrap_cache_dir` will take precedence over the path provided inside `config` + /// 3. Addresses from cache /// 4. Addresses from network contacts URL pub async fn get_bootstrap_addr( &self, @@ -159,10 +147,7 @@ impl PeersArgs { } else { BootstrapCacheConfig::default_config().ok() }; - if let Some(mut cfg) = cfg { - if let Some(file_path) = self.get_bootstrap_cache_path()? { - cfg.cache_file_path = file_path; - } + if let Some(cfg) = cfg { info!("Loading bootstrap addresses from cache"); if let Ok(data) = BootstrapCacheStore::load_cache_data(&cfg) { bootstrap_addresses = data @@ -221,22 +206,4 @@ impl PeersArgs { } bootstrap_addresses } - - /// Get the path to the bootstrap cache JSON file if `Self::bootstrap_cache_dir` is set - pub fn get_bootstrap_cache_path(&self) -> Result> { - if let Some(dir) = &self.bootstrap_cache_dir { - if dir.is_file() { - return Err(Error::InvalidBootstrapCacheDir); - } - - if !dir.exists() { - std::fs::create_dir_all(dir)?; - } - - let path = dir.join(cache_file_name()); - Ok(Some(path)) - } else { - Ok(None) - } - } } diff --git a/ant-bootstrap/tests/address_format_tests.rs b/ant-bootstrap/tests/address_format_tests.rs index a953608039..09d73e22b2 100644 --- a/ant-bootstrap/tests/address_format_tests.rs +++ b/ant-bootstrap/tests/address_format_tests.rs @@ -49,7 +49,6 @@ async fn test_multiaddr_format_parsing() -> Result<(), Box Result<(), Box local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let addrs = args.get_bootstrap_addr(None).await?; diff --git a/ant-bootstrap/tests/cli_integration_tests.rs b/ant-bootstrap/tests/cli_integration_tests.rs index 8ac0ab571b..4f70c23228 100644 --- a/ant-bootstrap/tests/cli_integration_tests.rs +++ b/ant-bootstrap/tests/cli_integration_tests.rs @@ -35,7 +35,6 @@ async fn test_first_flag() -> Result<(), Box> { local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let addrs = args.get_addrs(Some(config)).await?; @@ -61,7 +60,6 @@ async fn test_peer_argument() -> Result<(), Box> { local: false, disable_mainnet_contacts: true, ignore_cache: false, - bootstrap_cache_dir: None, }; let addrs = args.get_addrs(None).await?; @@ -96,7 +94,6 @@ async fn test_network_contacts_fallback() -> Result<(), Box Result<(), Box> { local: true, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let addrs = args.get_addrs(Some(config)).await?; @@ -163,7 +159,6 @@ async fn test_test_network_peers() -> Result<(), Box> { local: false, disable_mainnet_contacts: true, ignore_cache: false, - bootstrap_cache_dir: None, }; let addrs = args.get_addrs(Some(config)).await?; diff --git a/ant-node-manager/src/add_services/tests.rs b/ant-node-manager/src/add_services/tests.rs index ee19f167b0..e2eb37aca5 100644 --- a/ant-node-manager/src/add_services/tests.rs +++ b/ant-node-manager/src/add_services/tests.rs @@ -116,7 +116,6 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let install_ctx = InstallNodeServiceCtxBuilder { @@ -267,7 +266,6 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let mut node_registry = NodeRegistry { auditor: None, @@ -405,7 +403,6 @@ async fn add_genesis_node_should_return_an_error_if_count_is_greater_than_1() -> local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let latest_version = "0.96.4"; @@ -1111,7 +1108,6 @@ async fn add_node_should_create_service_file_with_first_arg() -> Result<()> { local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let mut seq = Sequence::new(); @@ -1225,7 +1221,6 @@ async fn add_node_should_create_service_file_with_first_arg() -> Result<()> { assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert!(node_registry.nodes[0].peers_args.first); Ok(()) } @@ -1265,7 +1260,6 @@ async fn add_node_should_create_service_file_with_peers_args() -> Result<()> { local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let mut seq = Sequence::new(); @@ -1381,7 +1375,6 @@ async fn add_node_should_create_service_file_with_peers_args() -> Result<()> { assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert_eq!(node_registry.nodes[0].peers_args.addrs.len(), 1); Ok(()) } @@ -1418,7 +1411,6 @@ async fn add_node_should_create_service_file_with_local_arg() -> Result<()> { local: true, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let mut seq = Sequence::new(); @@ -1532,7 +1524,6 @@ async fn add_node_should_create_service_file_with_local_arg() -> Result<()> { assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert!(node_registry.nodes[0].peers_args.local); Ok(()) } @@ -1572,7 +1563,6 @@ async fn add_node_should_create_service_file_with_network_contacts_url_arg() -> local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }; let mut seq = Sequence::new(); @@ -1687,10 +1677,6 @@ async fn add_node_should_create_service_file_with_network_contacts_url_arg() -> assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert_eq!( - node_registry.nodes[0].peers_args.network_contacts_url.len(), - 2 - ); Ok(()) } @@ -1727,7 +1713,6 @@ async fn add_node_should_create_service_file_with_testnet_arg() -> Result<()> { local: false, disable_mainnet_contacts: true, ignore_cache: false, - bootstrap_cache_dir: None, }; let mut seq = Sequence::new(); @@ -1841,7 +1826,6 @@ async fn add_node_should_create_service_file_with_testnet_arg() -> Result<()> { assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert!(node_registry.nodes[0].peers_args.disable_mainnet_contacts); Ok(()) } @@ -1878,7 +1862,6 @@ async fn add_node_should_create_service_file_with_ignore_cache_arg() -> Result<( local: false, disable_mainnet_contacts: false, ignore_cache: true, - bootstrap_cache_dir: None, }; let mut seq = Sequence::new(); @@ -1992,162 +1975,6 @@ async fn add_node_should_create_service_file_with_ignore_cache_arg() -> Result<( assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert!(node_registry.nodes[0].peers_args.ignore_cache); - - Ok(()) -} - -#[tokio::test] -async fn add_node_should_create_service_file_with_custom_bootstrap_cache_path() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let peers_args = PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - bootstrap_cache_dir: Some(PathBuf::from("/path/to/bootstrap/cache")), - }; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--bootstrap-cache-dir"), - OsString::from("/path/to/bootstrap/cache"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - owner: None, - peers_args: peers_args.clone(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); - assert_eq!( - node_registry.nodes[0].peers_args.bootstrap_cache_dir, - Some(PathBuf::from("/path/to/bootstrap/cache")) - ); Ok(()) } diff --git a/ant-node-manager/src/lib.rs b/ant-node-manager/src/lib.rs index 2b4c6a8921..7987c55224 100644 --- a/ant-node-manager/src/lib.rs +++ b/ant-node-manager/src/lib.rs @@ -2735,7 +2735,6 @@ mod tests { local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }, pid: Some(1000), rewards_address: RewardsAddress::from_str( @@ -2909,8 +2908,7 @@ mod tests { local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, - }, + }, pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -3082,7 +3080,6 @@ mod tests { local: true, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }, pid: Some(1000), rewards_address: RewardsAddress::from_str( @@ -3254,7 +3251,6 @@ mod tests { local: false, disable_mainnet_contacts: false, ignore_cache: false, - bootstrap_cache_dir: None, }, pid: Some(1000), rewards_address: RewardsAddress::from_str( @@ -3430,7 +3426,6 @@ mod tests { local: false, disable_mainnet_contacts: true, ignore_cache: false, - bootstrap_cache_dir: None, }, pid: Some(1000), rewards_address: RewardsAddress::from_str( @@ -3604,7 +3599,6 @@ mod tests { local: false, disable_mainnet_contacts: false, ignore_cache: true, - bootstrap_cache_dir: None, }, pid: Some(1000), rewards_address: RewardsAddress::from_str( @@ -3644,186 +3638,6 @@ mod tests { Ok(()) } - #[tokio::test] - async fn upgrade_should_retain_the_custom_bootstrap_cache_path() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--bootstrap-cache-dir"), - OsString::from("/var/antctl/services/antnode1/bootstrap_cache"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - bootstrap_cache_dir: Some(PathBuf::from( - "/var/antctl/services/antnode1/bootstrap_cache", - )), - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert_eq!( - service_manager - .service - .service_data - .peers_args - .bootstrap_cache_dir, - Some(PathBuf::from( - "/var/antctl/services/antnode1/bootstrap_cache" - )) - ); - - Ok(()) - } - #[tokio::test] async fn upgrade_should_retain_the_upnp_flag() -> Result<()> { let current_version = "0.1.0"; diff --git a/ant-node-manager/src/local.rs b/ant-node-manager/src/local.rs index 9bfc06eee9..9b8b61e4e3 100644 --- a/ant-node-manager/src/local.rs +++ b/ant-node-manager/src/local.rs @@ -447,7 +447,6 @@ pub async fn run_node( local: true, disable_mainnet_contacts: true, ignore_cache: true, - bootstrap_cache_dir: None, }, pid: Some(node_info.pid), rewards_address: run_options.rewards_address, diff --git a/ant-service-management/src/node.rs b/ant-service-management/src/node.rs index d9a91eeb12..e1b5378bbc 100644 --- a/ant-service-management/src/node.rs +++ b/ant-service-management/src/node.rs @@ -424,8 +424,4 @@ pub fn push_arguments_from_peers_args(peers_args: &PeersArgs, args: &mut Vec Date: Tue, 10 Dec 2024 18:56:30 +0530 Subject: [PATCH 7/7] Revert "feat(manager): implement PeersArgs into ant node manager" This reverts commit 902db328676b1bbb8e34035f57c4ba3a3a58ccf7. --- Cargo.lock | 1 - ant-bootstrap/src/error.rs | 2 - ant-bootstrap/src/initial_peers.rs | 63 +- ant-bootstrap/tests/address_format_tests.rs | 4 +- ant-bootstrap/tests/cli_integration_tests.rs | 10 +- ant-node-manager/src/add_services/config.rs | 85 +- ant-node-manager/src/add_services/mod.rs | 42 +- ant-node-manager/src/add_services/tests.rs | 1405 +++++------------- ant-node-manager/src/bin/cli/main.rs | 1 + ant-node-manager/src/cmd/node.rs | 43 +- ant-node-manager/src/lib.rs | 1165 ++------------- ant-node-manager/src/local.rs | 40 +- ant-node-manager/src/rpc.rs | 13 +- ant-service-management/Cargo.toml | 1 - ant-service-management/src/auditor.rs | 11 + ant-service-management/src/faucet.rs | 11 + ant-service-management/src/lib.rs | 5 + ant-service-management/src/node.rs | 59 +- node-launchpad/src/node_mgmt.rs | 2 + 19 files changed, 728 insertions(+), 2235 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6d3183c8d..999850c2d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1091,7 +1091,6 @@ dependencies = [ name = "ant-service-management" version = "0.4.3" dependencies = [ - "ant-bootstrap", "ant-evm", "ant-logging", "ant-protocol", diff --git a/ant-bootstrap/src/error.rs b/ant-bootstrap/src/error.rs index 70da2ca80a..77002702e5 100644 --- a/ant-bootstrap/src/error.rs +++ b/ant-bootstrap/src/error.rs @@ -20,8 +20,6 @@ pub enum Error { FailedToObtainAddrsFromUrl(String, usize), #[error("No Bootstrap Addresses found: {0}")] NoBootstrapAddressesFound(String), - #[error("Failed to parse Url")] - FailedToParseUrl, #[error("IO error: {0}")] Io(#[from] std::io::Error), #[error("JSON error: {0}")] diff --git a/ant-bootstrap/src/initial_peers.rs b/ant-bootstrap/src/initial_peers.rs index daf20d1480..07d0cd3b24 100644 --- a/ant-bootstrap/src/initial_peers.rs +++ b/ant-bootstrap/src/initial_peers.rs @@ -13,14 +13,13 @@ use crate::{ }; use clap::Args; use libp2p::Multiaddr; -use serde::{Deserialize, Serialize}; use url::Url; /// The name of the environment variable that can be used to pass peers to the node. pub const ANT_PEERS_ENV: &str = "ANT_PEERS"; /// Command line arguments for peer configuration -#[derive(Args, Debug, Clone, Default, PartialEq, Serialize, Deserialize)] +#[derive(Args, Debug, Clone, Default)] pub struct PeersArgs { /// Set to indicate this is the first node in a new network /// @@ -42,15 +41,16 @@ pub struct PeersArgs { long = "peer", value_name = "multiaddr", value_delimiter = ',', - conflicts_with = "first" + conflicts_with = "first", + value_parser = parse_multiaddr_str )] pub addrs: Vec, /// Specify the URL to fetch the network contacts from. /// /// The URL can point to a text file containing Multiaddresses separated by newline character, or /// a bootstrap cache JSON file. - #[clap(long, conflicts_with = "first", value_delimiter = ',')] - pub network_contacts_url: Vec, + #[clap(long, conflicts_with = "first")] + pub network_contacts_url: Option, /// Set to indicate this is a local network. You could also set the `local` feature flag to set this to true. /// /// This would use mDNS for peer discovery. @@ -59,7 +59,7 @@ pub struct PeersArgs { /// Set to indicate this is a testnet. /// /// This disables fetching peers from the mainnet network contacts. - #[clap(name = "testnet", long)] + #[clap(name = "testnet", long, conflicts_with = "network_contacts_url")] pub disable_mainnet_contacts: bool, /// Set to not load the bootstrap addresses from the local cache. @@ -115,21 +115,23 @@ impl PeersArgs { warn!("Invalid multiaddress format from arguments: {addr}"); } } + // Read from ANT_PEERS environment variable if present - bootstrap_addresses.extend(Self::read_bootstrap_addr_from_env()); + if let Ok(addrs) = std::env::var(ANT_PEERS_ENV) { + for addr_str in addrs.split(',') { + if let Some(addr) = craft_valid_multiaddr_from_str(addr_str, false) { + info!("Adding addr from environment variable: {addr}"); + bootstrap_addresses.push(BootstrapAddr::new(addr)); + } else { + warn!("Invalid multiaddress format from environment variable: {addr_str}"); + } + } + } // If we have a network contacts URL, fetch addrs from there. - if !self.network_contacts_url.is_empty() { - info!( - "Fetching bootstrap address from network contacts URLs: {:?}", - self.network_contacts_url - ); - let addrs = self - .network_contacts_url - .iter() - .map(|url| url.parse::().map_err(|_| Error::FailedToParseUrl)) - .collect::>>()?; - let contacts_fetcher = ContactsFetcher::with_endpoints(addrs)?; + if let Some(url) = self.network_contacts_url.clone() { + info!("Fetching bootstrap address from network contacts URL: {url}",); + let contacts_fetcher = ContactsFetcher::with_endpoints(vec![url])?; let addrs = contacts_fetcher.fetch_bootstrap_addresses().await?; bootstrap_addresses.extend(addrs); } @@ -183,27 +185,8 @@ impl PeersArgs { Err(Error::NoBootstrapPeersFound) } } +} - pub fn read_addr_from_env() -> Vec { - Self::read_bootstrap_addr_from_env() - .into_iter() - .map(|addr| addr.addr) - .collect() - } - - pub fn read_bootstrap_addr_from_env() -> Vec { - let mut bootstrap_addresses = Vec::new(); - // Read from ANT_PEERS environment variable if present - if let Ok(addrs) = std::env::var(ANT_PEERS_ENV) { - for addr_str in addrs.split(',') { - if let Some(addr) = craft_valid_multiaddr_from_str(addr_str, false) { - info!("Adding addr from environment variable: {addr}"); - bootstrap_addresses.push(BootstrapAddr::new(addr)); - } else { - warn!("Invalid multiaddress format from environment variable: {addr_str}"); - } - } - } - bootstrap_addresses - } +pub fn parse_multiaddr_str(addr: &str) -> std::result::Result { + addr.parse::() } diff --git a/ant-bootstrap/tests/address_format_tests.rs b/ant-bootstrap/tests/address_format_tests.rs index 09d73e22b2..55d9246b8b 100644 --- a/ant-bootstrap/tests/address_format_tests.rs +++ b/ant-bootstrap/tests/address_format_tests.rs @@ -45,7 +45,7 @@ async fn test_multiaddr_format_parsing() -> Result<(), Box Result<(), Box let args = PeersArgs { first: false, addrs: vec![], - network_contacts_url: vec![format!("{}/peers", mock_server.uri()).parse()?], + network_contacts_url: Some(format!("{}/peers", mock_server.uri()).parse()?), local: false, disable_mainnet_contacts: false, ignore_cache: false, diff --git a/ant-bootstrap/tests/cli_integration_tests.rs b/ant-bootstrap/tests/cli_integration_tests.rs index 4f70c23228..1afee9176e 100644 --- a/ant-bootstrap/tests/cli_integration_tests.rs +++ b/ant-bootstrap/tests/cli_integration_tests.rs @@ -31,7 +31,7 @@ async fn test_first_flag() -> Result<(), Box> { let args = PeersArgs { first: true, addrs: vec![], - network_contacts_url: vec![], + network_contacts_url: None, local: false, disable_mainnet_contacts: false, ignore_cache: false, @@ -56,7 +56,7 @@ async fn test_peer_argument() -> Result<(), Box> { let args = PeersArgs { first: false, addrs: vec![peer_addr.clone()], - network_contacts_url: vec![], + network_contacts_url: None, local: false, disable_mainnet_contacts: true, ignore_cache: false, @@ -90,7 +90,7 @@ async fn test_network_contacts_fallback() -> Result<(), Box Result<(), Box> { let args = PeersArgs { first: false, addrs: vec![], - network_contacts_url: vec![], + network_contacts_url: None, local: true, disable_mainnet_contacts: false, ignore_cache: false, @@ -155,7 +155,7 @@ async fn test_test_network_peers() -> Result<(), Box> { let args = PeersArgs { first: false, addrs: vec![peer_addr.clone()], - network_contacts_url: vec![], + network_contacts_url: None, local: false, disable_mainnet_contacts: true, ignore_cache: false, diff --git a/ant-node-manager/src/add_services/config.rs b/ant-node-manager/src/add_services/config.rs index 40eea8ff86..046b29d79b 100644 --- a/ant-node-manager/src/add_services/config.rs +++ b/ant-node-manager/src/add_services/config.rs @@ -6,11 +6,10 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -use ant_bootstrap::PeersArgs; use ant_evm::{EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; -use ant_service_management::node::push_arguments_from_peers_args; use color_eyre::{eyre::eyre, Result}; +use libp2p::Multiaddr; use service_manager::{ServiceInstallCtx, ServiceLabel}; use std::{ ffi::OsString, @@ -72,10 +71,13 @@ impl PortRange { pub struct InstallNodeServiceCtxBuilder { pub antnode_path: PathBuf, pub autostart: bool, + pub bootstrap_peers: Vec, pub data_dir_path: PathBuf, pub env_variables: Option>, pub evm_network: EvmNetwork, + pub genesis: bool, pub home_network: bool, + pub local: bool, pub log_dir_path: PathBuf, pub log_format: Option, pub name: String, @@ -85,7 +87,6 @@ pub struct InstallNodeServiceCtxBuilder { pub node_ip: Option, pub node_port: Option, pub owner: Option, - pub peers_args: PeersArgs, pub rewards_address: RewardsAddress, pub rpc_socket_addr: SocketAddr, pub service_user: Option, @@ -104,10 +105,15 @@ impl InstallNodeServiceCtxBuilder { OsString::from(self.log_dir_path.to_string_lossy().to_string()), ]; - push_arguments_from_peers_args(&self.peers_args, &mut args); + if self.genesis { + args.push(OsString::from("--first")); + } if self.home_network { args.push(OsString::from("--home-network")); } + if self.local { + args.push(OsString::from("--local")); + } if let Some(log_format) = self.log_format { args.push(OsString::from("--log-format")); args.push(OsString::from(log_format.as_str())); @@ -140,6 +146,17 @@ impl InstallNodeServiceCtxBuilder { args.push(OsString::from(log_files.to_string())); } + if !self.bootstrap_peers.is_empty() { + let peers_str = self + .bootstrap_peers + .iter() + .map(|peer| peer.to_string()) + .collect::>() + .join(","); + args.push(OsString::from("--peer")); + args.push(OsString::from(peers_str)); + } + args.push(OsString::from("--rewards-address")); args.push(OsString::from(self.rewards_address.to_string())); @@ -175,12 +192,15 @@ pub struct AddNodeServiceOptions { pub antnode_src_path: PathBuf, pub auto_restart: bool, pub auto_set_nat_flags: bool, + pub bootstrap_peers: Vec, pub count: Option, pub delete_antnode_src: bool, pub enable_metrics_server: bool, pub env_variables: Option>, pub evm_network: EvmNetwork, + pub genesis: bool, pub home_network: bool, + pub local: bool, pub log_format: Option, pub max_archived_log_files: Option, pub max_log_files: Option, @@ -188,7 +208,6 @@ pub struct AddNodeServiceOptions { pub node_ip: Option, pub node_port: Option, pub owner: Option, - pub peers_args: PeersArgs, pub rewards_address: RewardsAddress, pub rpc_address: Option, pub rpc_port: Option, @@ -204,6 +223,7 @@ pub struct AddNodeServiceOptions { pub struct InstallAuditorServiceCtxBuilder { pub auditor_path: PathBuf, pub beta_encryption_key: Option, + pub bootstrap_peers: Vec, pub env_variables: Option>, pub log_dir_path: PathBuf, pub name: String, @@ -217,6 +237,16 @@ impl InstallAuditorServiceCtxBuilder { OsString::from(self.log_dir_path.to_string_lossy().to_string()), ]; + if !self.bootstrap_peers.is_empty() { + let peers_str = self + .bootstrap_peers + .iter() + .map(|peer| peer.to_string()) + .collect::>() + .join(","); + args.push(OsString::from("--peer")); + args.push(OsString::from(peers_str)); + } if let Some(beta_encryption_key) = self.beta_encryption_key { args.push(OsString::from("--beta-encryption-key")); args.push(OsString::from(beta_encryption_key)); @@ -237,6 +267,7 @@ impl InstallAuditorServiceCtxBuilder { #[derive(Debug, PartialEq)] pub struct InstallFaucetServiceCtxBuilder { + pub bootstrap_peers: Vec, pub env_variables: Option>, pub faucet_path: PathBuf, pub local: bool, @@ -252,6 +283,17 @@ impl InstallFaucetServiceCtxBuilder { OsString::from(self.log_dir_path.to_string_lossy().to_string()), ]; + if !self.bootstrap_peers.is_empty() { + let peers_str = self + .bootstrap_peers + .iter() + .map(|peer| peer.to_string()) + .collect::>() + .join(","); + args.push(OsString::from("--peer")); + args.push(OsString::from(peers_str)); + } + args.push(OsString::from("server")); Ok(ServiceInstallCtx { @@ -271,6 +313,7 @@ pub struct AddAuditorServiceOptions { pub auditor_install_bin_path: PathBuf, pub auditor_src_bin_path: PathBuf, pub beta_encryption_key: Option, + pub bootstrap_peers: Vec, pub env_variables: Option>, pub service_log_dir_path: PathBuf, pub user: String, @@ -278,6 +321,7 @@ pub struct AddAuditorServiceOptions { } pub struct AddFaucetServiceOptions { + pub bootstrap_peers: Vec, pub env_variables: Option>, pub faucet_install_bin_path: PathBuf, pub faucet_src_bin_path: PathBuf, @@ -308,10 +352,13 @@ mod tests { InstallNodeServiceCtxBuilder { antnode_path: PathBuf::from("/bin/antnode"), autostart: true, + bootstrap_peers: vec![], data_dir_path: PathBuf::from("/data"), env_variables: None, evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, + local: false, log_dir_path: PathBuf::from("/logs"), log_format: None, name: "test-node".to_string(), @@ -321,7 +368,6 @@ mod tests { node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124") .unwrap(), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080), @@ -333,6 +379,7 @@ mod tests { fn create_custom_evm_network_builder() -> InstallNodeServiceCtxBuilder { InstallNodeServiceCtxBuilder { autostart: true, + bootstrap_peers: vec![], data_dir_path: PathBuf::from("/data"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -346,7 +393,9 @@ mod tests { ) .unwrap(), }), + genesis: false, home_network: false, + local: false, log_dir_path: PathBuf::from("/logs"), log_format: None, name: "test-node".to_string(), @@ -356,7 +405,6 @@ mod tests { node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124") .unwrap(), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080), @@ -369,6 +417,7 @@ mod tests { fn create_builder_with_all_options_enabled() -> InstallNodeServiceCtxBuilder { InstallNodeServiceCtxBuilder { autostart: true, + bootstrap_peers: vec![], data_dir_path: PathBuf::from("/data"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -382,7 +431,9 @@ mod tests { ) .unwrap(), }), + genesis: false, home_network: false, + local: false, log_dir_path: PathBuf::from("/logs"), log_format: None, name: "test-node".to_string(), @@ -392,7 +443,6 @@ mod tests { node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124") .unwrap(), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080), @@ -475,22 +525,19 @@ mod tests { #[test] fn build_should_assign_expected_values_when_all_options_are_enabled() { let mut builder = create_builder_with_all_options_enabled(); + builder.genesis = true; builder.home_network = true; + builder.local = true; builder.log_format = Some(LogFormat::Json); builder.upnp = true; builder.node_ip = Some(Ipv4Addr::new(192, 168, 1, 1)); builder.node_port = Some(12345); builder.metrics_port = Some(9090); builder.owner = Some("test-owner".to_string()); - builder.peers_args.addrs = vec![ + builder.bootstrap_peers = vec![ "/ip4/127.0.0.1/tcp/8080".parse().unwrap(), "/ip4/192.168.1.1/tcp/8081".parse().unwrap(), ]; - builder.peers_args.first = true; - builder.peers_args.local = true; - builder.peers_args.network_contacts_url = vec!["http://localhost:8080".parse().unwrap()]; - builder.peers_args.ignore_cache = true; - builder.peers_args.disable_mainnet_contacts = true; builder.service_user = Some("antnode-user".to_string()); let result = builder.build().unwrap(); @@ -503,14 +550,8 @@ mod tests { "--log-output-dest", "/logs", "--first", - "--local", - "--peer", - "/ip4/127.0.0.1/tcp/8080,/ip4/192.168.1.1/tcp/8081", - "--network-contacts-url", - "http://localhost:8080", - "--testnet", - "--ignore-cache", "--home-network", + "--local", "--log-format", "json", "--upnp", @@ -526,6 +567,8 @@ mod tests { "10", "--max-log-files", "10", + "--peer", + "/ip4/127.0.0.1/tcp/8080,/ip4/192.168.1.1/tcp/8081", "--rewards-address", "0x03B770D9cD32077cC0bF330c13C114a87643B124", "evm-custom", diff --git a/ant-node-manager/src/add_services/mod.rs b/ant-node-manager/src/add_services/mod.rs index a871f73179..f3b77d4649 100644 --- a/ant-node-manager/src/add_services/mod.rs +++ b/ant-node-manager/src/add_services/mod.rs @@ -48,7 +48,7 @@ pub async fn add_node( service_control: &dyn ServiceControl, verbosity: VerbosityLevel, ) -> Result> { - if options.peers_args.first { + if options.genesis { if let Some(count) = options.count { if count > 1 { error!("A genesis node can only be added as a single node"); @@ -56,7 +56,7 @@ pub async fn add_node( } } - let genesis_node = node_registry.nodes.iter().find(|n| n.peers_args.first); + let genesis_node = node_registry.nodes.iter().find(|n| n.genesis); if genesis_node.is_some() { error!("A genesis node already exists"); return Err(eyre!("A genesis node already exists")); @@ -98,11 +98,30 @@ pub async fn add_node( .to_string_lossy() .to_string(); - if options.env_variables.is_some() { - node_registry - .environment_variables - .clone_from(&options.env_variables); - node_registry.save()?; + { + let mut should_save = false; + let new_bootstrap_peers: Vec<_> = options + .bootstrap_peers + .iter() + .filter(|peer| !node_registry.bootstrap_peers.contains(peer)) + .collect(); + if !new_bootstrap_peers.is_empty() { + node_registry + .bootstrap_peers + .extend(new_bootstrap_peers.into_iter().cloned()); + should_save = true; + } + + if options.env_variables.is_some() { + node_registry + .environment_variables + .clone_from(&options.env_variables); + should_save = true; + } + + if should_save { + node_registry.save()?; + } } let mut added_service_data = vec![]; @@ -200,10 +219,13 @@ pub async fn add_node( let install_ctx = InstallNodeServiceCtxBuilder { autostart: options.auto_restart, + bootstrap_peers: options.bootstrap_peers.clone(), data_dir_path: service_data_dir_path.clone(), env_variables: options.env_variables.clone(), evm_network: options.evm_network.clone(), + genesis: options.genesis, home_network: options.home_network, + local: options.local, log_dir_path: service_log_dir_path.clone(), log_format: options.log_format, max_archived_log_files: options.max_archived_log_files, @@ -213,7 +235,6 @@ pub async fn add_node( node_ip: options.node_ip, node_port, owner: owner.clone(), - peers_args: options.peers_args.clone(), rewards_address: options.rewards_address, rpc_socket_addr, antnode_path: service_antnode_path.clone(), @@ -239,8 +260,10 @@ pub async fn add_node( connected_peers: None, data_dir_path: service_data_dir_path.clone(), evm_network: options.evm_network.clone(), + genesis: options.genesis, home_network: options.home_network, listen_addr: None, + local: options.local, log_dir_path: service_log_dir_path.clone(), log_format: options.log_format, max_archived_log_files: options.max_archived_log_files, @@ -254,7 +277,6 @@ pub async fn add_node( rpc_socket_addr, owner: owner.clone(), peer_id: None, - peers_args: options.peers_args.clone(), pid: None, service_name, status: ServiceStatus::Added, @@ -359,6 +381,7 @@ pub fn add_auditor( let install_ctx = InstallAuditorServiceCtxBuilder { auditor_path: install_options.auditor_install_bin_path.clone(), beta_encryption_key: install_options.beta_encryption_key.clone(), + bootstrap_peers: install_options.bootstrap_peers.clone(), env_variables: install_options.env_variables.clone(), log_dir_path: install_options.service_log_dir_path.clone(), name: "auditor".to_string(), @@ -502,6 +525,7 @@ pub fn add_faucet( )?; let install_ctx = InstallFaucetServiceCtxBuilder { + bootstrap_peers: install_options.bootstrap_peers.clone(), env_variables: install_options.env_variables.clone(), faucet_path: install_options.faucet_install_bin_path.clone(), local: install_options.local, diff --git a/ant-node-manager/src/add_services/tests.rs b/ant-node-manager/src/add_services/tests.rs index e2eb37aca5..8a413a331e 100644 --- a/ant-node-manager/src/add_services/tests.rs +++ b/ant-node-manager/src/add_services/tests.rs @@ -16,7 +16,6 @@ use crate::{ }, VerbosityLevel, }; -use ant_bootstrap::PeersArgs; use ant_evm::{AttoTokens, CustomNetwork, EvmNetwork, RewardsAddress}; use ant_service_management::{auditor::AuditorServiceData, control::ServiceControl}; use ant_service_management::{error::Result as ServiceControlResult, NatDetectionStatus}; @@ -26,6 +25,7 @@ use ant_service_management::{ use assert_fs::prelude::*; use assert_matches::assert_matches; use color_eyre::Result; +use libp2p::Multiaddr; use mockall::{mock, predicate::*, Sequence}; use predicates::prelude::*; use service_manager::ServiceInstallCtx; @@ -97,6 +97,7 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -109,17 +110,9 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res .returning(|| Ok(8081)) .in_sequence(&mut seq); - let peers_args = PeersArgs { - first: true, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }; - let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -131,7 +124,9 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: true, home_network: false, + local: true, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -141,7 +136,6 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res node_ip: None, node_port: None, owner: None, - peers_args: peers_args.clone(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), antnode_path: node_data_dir @@ -163,19 +157,21 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: true, home_network: false, + local: true, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args, rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -211,7 +207,7 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res node_reg_path.assert(predicates::path::is_file()); assert_eq!(node_registry.nodes.len(), 1); - assert!(node_registry.nodes[0].peers_args.first); + assert!(node_registry.nodes[0].genesis); assert_eq!(node_registry.nodes[0].version, latest_version); assert_eq!(node_registry.nodes[0].service_name, "antnode1"); assert_eq!(node_registry.nodes[0].user, Some(get_username())); @@ -258,15 +254,6 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n let mock_service_control = MockServiceControl::new(); let latest_version = "0.96.4"; - - let peers_args = PeersArgs { - first: true, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }; let mut node_registry = NodeRegistry { auditor: None, faucet: None, @@ -285,8 +272,10 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: true, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -295,10 +284,9 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n node_ip: None, node_port: None, number: 1, - owner: None, - peer_id: None, - peers_args: peers_args.clone(), pid: None, + peer_id: None, + owner: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", )?, @@ -312,6 +300,7 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n user_mode: false, version: latest_version.to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -330,19 +319,21 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: true, home_network: false, + local: true, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args, rpc_address: Some(custom_rpc_address), rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -393,17 +384,10 @@ async fn add_genesis_node_should_return_an_error_if_count_is_greater_than_1() -> save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; - let peers_args = PeersArgs { - first: true, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }; let latest_version = "0.96.4"; let temp_dir = assert_fs::TempDir::new()?; @@ -418,19 +402,21 @@ async fn add_genesis_node_should_return_an_error_if_count_is_greater_than_1() -> AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: true, home_network: false, + local: true, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args, rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -481,6 +467,7 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -505,6 +492,7 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -516,7 +504,9 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -526,7 +516,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), antnode_path: node_data_dir .to_path_buf() @@ -553,6 +542,7 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( .in_sequence(&mut seq); let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode2"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -564,7 +554,9 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode2"), log_format: None, max_archived_log_files: None, @@ -574,7 +566,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083), antnode_path: node_data_dir @@ -602,6 +593,7 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, data_dir_path: node_data_dir.to_path_buf().join("antnode3"), + bootstrap_peers: vec![], env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { rpc_url_http: "http://localhost:8545".parse()?, @@ -612,7 +604,9 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_format: None, log_dir_path: node_logs_dir.to_path_buf().join("antnode3"), max_archived_log_files: None, @@ -622,7 +616,6 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8085), antnode_path: node_data_dir @@ -645,19 +638,21 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -744,16 +739,14 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( } #[tokio::test] -async fn add_node_should_update_the_environment_variables_inside_node_registry() -> Result<()> { +async fn add_node_should_update_the_bootstrap_peers_inside_node_registry() -> Result<()> { let tmp_data_dir = assert_fs::TempDir::new()?; let node_reg_path = tmp_data_dir.child("node_reg.json"); let mut mock_service_control = MockServiceControl::new(); - let env_variables = Some(vec![ - ("ANT_LOG".to_owned(), "all".to_owned()), - ("RUST_LOG".to_owned(), "libp2p=debug".to_owned()), - ]); + let mut old_peers = vec![Multiaddr::from_str("/ip4/64.227.35.186/udp/33188/quic-v1/p2p/12D3KooWDrx4zfUuJgz7jSusC28AZRDRbj7eo3WKZigPsw9tVKs3")?]; + let new_peers = vec![Multiaddr::from_str("/ip4/178.62.78.116/udp/45442/quic-v1/p2p/12D3KooWLH4E68xFqoSKuF2JPQQhzaAg7GNvN1vpxoLMgJq6Zqz8")?]; let mut node_registry = NodeRegistry { auditor: None, @@ -761,6 +754,7 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: old_peers.clone(), environment_variables: None, daemon: None, }; @@ -780,10 +774,12 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() .times(1) .returning(|| Ok(12001)) .in_sequence(&mut seq); + let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: new_peers.clone(), data_dir_path: node_data_dir.to_path_buf().join("antnode1"), - env_variables: env_variables.clone(), + env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { rpc_url_http: "http://localhost:8545".parse()?, payment_token_address: RewardsAddress::from_str( @@ -793,7 +789,9 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -803,7 +801,6 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), antnode_path: node_data_dir @@ -814,6 +811,7 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() upnp: false, } .build()?; + mock_service_control .expect_install() .times(1) @@ -825,23 +823,25 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: new_peers.clone(), count: None, delete_antnode_src: true, enable_metrics_server: false, - env_variables: env_variables.clone(), + env_variables: None, + local: false, + genesis: false, home_network: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), antnode_src_path: antnode_download_path.to_path_buf(), + antnode_dir_path: temp_dir.to_path_buf(), service_data_dir_path: node_data_dir.to_path_buf(), service_log_dir_path: node_logs_dir.to_path_buf(), upnp: false, @@ -871,7 +871,8 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() node_data_dir.assert(predicate::path::is_dir()); node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.environment_variables, env_variables); + old_peers.extend(new_peers); + assert_eq!(node_registry.bootstrap_peers, old_peers); assert_eq!(node_registry.nodes.len(), 1); assert_eq!(node_registry.nodes[0].version, latest_version); @@ -896,63 +897,30 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() } #[tokio::test] -async fn add_new_node_should_add_another_service() -> Result<()> { +async fn add_node_should_update_the_environment_variables_inside_node_registry() -> Result<()> { let tmp_data_dir = assert_fs::TempDir::new()?; let node_reg_path = tmp_data_dir.child("node_reg.json"); let mut mock_service_control = MockServiceControl::new(); - let latest_version = "0.96.4"; + let env_variables = Some(vec![ + ("ANT_LOG".to_owned(), "all".to_owned()), + ("RUST_LOG".to_owned(), "libp2p=debug".to_owned()), + ]); + let mut node_registry = NodeRegistry { auditor: None, faucet: None, save_path: node_reg_path.to_path_buf(), nat_status: None, - nodes: vec![NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: None, - peers_args: PeersArgs::default(), - pid: None, - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: PathBuf::from("/var/antctl/services/antnode1/antnode"), - service_name: "antnode1".to_string(), - status: ServiceStatus::Added, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: latest_version.to_string(), - }], + nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; + let latest_version = "0.96.4"; let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("antnode1"); + let node_data_dir = temp_dir.child("data"); node_data_dir.create_dir_all()?; let node_logs_dir = temp_dir.child("logs"); node_logs_dir.create_dir_all()?; @@ -960,15 +928,17 @@ async fn add_new_node_should_add_another_service() -> Result<()> { antnode_download_path.write_binary(b"fake antnode bin")?; let mut seq = Sequence::new(); + mock_service_control .expect_get_available_port() .times(1) - .returning(|| Ok(8083)) + .returning(|| Ok(12001)) .in_sequence(&mut seq); let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, - data_dir_path: node_data_dir.to_path_buf().join("antnode2"), - env_variables: None, + bootstrap_peers: vec![], + data_dir_path: node_data_dir.to_path_buf().join("antnode1"), + env_variables: env_variables.clone(), evm_network: EvmNetwork::Custom(CustomNetwork { rpc_url_http: "http://localhost:8545".parse()?, payment_token_address: RewardsAddress::from_str( @@ -978,28 +948,28 @@ async fn add_new_node_should_add_another_service() -> Result<()> { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, - log_dir_path: node_logs_dir.to_path_buf().join("antnode2"), + local: false, + log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, - name: "antnode2".to_string(), + name: "antnode1".to_string(), node_ip: None, node_port: None, - peers_args: PeersArgs::default(), - rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083), owner: None, + rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), antnode_path: node_data_dir .to_path_buf() - .join("antnode2") + .join("antnode1") .join(ANTNODE_FILE_NAME), service_user: Some(get_username()), upnp: false, } .build()?; - mock_service_control .expect_install() .times(1) @@ -1011,23 +981,25 @@ async fn add_new_node_should_add_another_service() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, - env_variables: None, + env_variables: env_variables.clone(), + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, - antnode_src_path: antnode_download_path.to_path_buf(), antnode_dir_path: temp_dir.to_path_buf(), + antnode_src_path: antnode_download_path.to_path_buf(), service_data_dir_path: node_data_dir.to_path_buf(), service_log_dir_path: node_logs_dir.to_path_buf(), upnp: false, @@ -1053,873 +1025,147 @@ async fn add_new_node_should_add_another_service() -> Result<()> { ) .await?; - assert_eq!(node_registry.nodes.len(), 2); - assert_eq!(node_registry.nodes[1].version, latest_version); - assert_eq!(node_registry.nodes[1].service_name, "antnode2"); - assert_eq!(node_registry.nodes[1].user, Some(get_username())); - assert_eq!(node_registry.nodes[1].number, 2); + antnode_download_path.assert(predicate::path::missing()); + node_data_dir.assert(predicate::path::is_dir()); + node_logs_dir.assert(predicate::path::is_dir()); + + assert_eq!(node_registry.environment_variables, env_variables); + + assert_eq!(node_registry.nodes.len(), 1); + assert_eq!(node_registry.nodes[0].version, latest_version); + assert_eq!(node_registry.nodes[0].service_name, "antnode1"); + assert_eq!(node_registry.nodes[0].user, Some(get_username())); + assert_eq!(node_registry.nodes[0].number, 1); assert_eq!( - node_registry.nodes[1].rpc_socket_addr, - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083) + node_registry.nodes[0].rpc_socket_addr, + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001) ); assert_eq!( - node_registry.nodes[1].log_dir_path, - node_logs_dir.to_path_buf().join("antnode2") + node_registry.nodes[0].log_dir_path, + node_logs_dir.to_path_buf().join("antnode1") ); assert_eq!( - node_registry.nodes[1].data_dir_path, - node_data_dir.to_path_buf().join("antnode2") - ); - assert_matches!(node_registry.nodes[0].status, ServiceStatus::Added); - assert!(!node_registry.nodes[0].auto_restart); - - Ok(()) -} - -#[tokio::test] -async fn add_node_should_create_service_file_with_first_arg() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let peers_args = PeersArgs { - first: true, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--first"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - owner: None, - peers_args: peers_args.clone(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); - - Ok(()) -} - -#[tokio::test] -async fn add_node_should_create_service_file_with_peers_args() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let peers_args = PeersArgs { - first: false, - addrs: vec![ - "/ip4/127.0.0.1/tcp/8080/p2p/12D3KooWRBhwfeP2Y4TCx1SM6s9rUoHhR5STiGwxBhgFRcw3UERE" - .parse()?, - ], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--peer"), - OsString::from( - "/ip4/127.0.0.1/tcp/8080/p2p/12D3KooWRBhwfeP2Y4TCx1SM6s9rUoHhR5STiGwxBhgFRcw3UERE"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - owner: None, - peers_args: peers_args.clone(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); - - Ok(()) -} - -#[tokio::test] -async fn add_node_should_create_service_file_with_local_arg() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let peers_args = PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: true, - disable_mainnet_contacts: false, - ignore_cache: false, - }; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--local"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - owner: None, - peers_args: peers_args.clone(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); - - Ok(()) -} - -#[tokio::test] -async fn add_node_should_create_service_file_with_network_contacts_url_arg() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let peers_args = PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![ - "http://localhost:8080/contacts".to_string(), - "http://localhost:8081/contacts".to_string(), - ], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--network-contacts-url"), - OsString::from("http://localhost:8080/contacts,http://localhost:8081/contacts"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - owner: None, - peers_args: peers_args.clone(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); - - Ok(()) -} - -#[tokio::test] -async fn add_node_should_create_service_file_with_testnet_arg() -> Result<()> { - let tmp_data_dir = assert_fs::TempDir::new()?; - let node_reg_path = tmp_data_dir.child("node_reg.json"); - - let mut mock_service_control = MockServiceControl::new(); - - let mut node_registry = NodeRegistry { - auditor: None, - faucet: None, - save_path: node_reg_path.to_path_buf(), - nat_status: None, - nodes: vec![], - environment_variables: None, - daemon: None, - }; - let latest_version = "0.96.4"; - let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); - node_data_dir.create_dir_all()?; - let node_logs_dir = temp_dir.child("logs"); - node_logs_dir.create_dir_all()?; - let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); - antnode_download_path.write_binary(b"fake antnode bin")?; - - let peers_args = PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: true, - ignore_cache: false, - }; - - let mut seq = Sequence::new(); - - mock_service_control - .expect_get_available_port() - .times(1) - .returning(|| Ok(12001)) - .in_sequence(&mut seq); - - mock_service_control - .expect_install() - .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--testnet"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) - .returning(|_, _| Ok(())) - .in_sequence(&mut seq); - - add_node( - AddNodeServiceOptions { - auto_restart: false, - auto_set_nat_flags: false, - count: None, - delete_antnode_src: true, - enable_metrics_server: false, - env_variables: None, - home_network: false, - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - owner: None, - peers_args: peers_args.clone(), - rpc_address: None, - rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), - antnode_src_path: antnode_download_path.to_path_buf(), - service_data_dir_path: node_data_dir.to_path_buf(), - service_log_dir_path: node_logs_dir.to_path_buf(), - upnp: false, - user: Some(get_username()), - user_mode: false, - version: latest_version.to_string(), - evm_network: EvmNetwork::Custom(CustomNetwork { - rpc_url_http: "http://localhost:8545".parse()?, - payment_token_address: RewardsAddress::from_str( - "0x5FbDB2315678afecb367f032d93F642f64180aa3", - )?, - data_payments_address: RewardsAddress::from_str( - "0x8464135c8F25Da09e49BC8782676a84730C318bC", - )?, - }), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - }, - &mut node_registry, - &mock_service_control, - VerbosityLevel::Normal, - ) - .await?; - - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); + node_registry.nodes[0].data_dir_path, + node_data_dir.to_path_buf().join("antnode1") + ); + assert_matches!(node_registry.nodes[0].status, ServiceStatus::Added); Ok(()) } #[tokio::test] -async fn add_node_should_create_service_file_with_ignore_cache_arg() -> Result<()> { +async fn add_new_node_should_add_another_service() -> Result<()> { let tmp_data_dir = assert_fs::TempDir::new()?; let node_reg_path = tmp_data_dir.child("node_reg.json"); let mut mock_service_control = MockServiceControl::new(); + let latest_version = "0.96.4"; let mut node_registry = NodeRegistry { auditor: None, faucet: None, save_path: node_reg_path.to_path_buf(), nat_status: None, - nodes: vec![], + nodes: vec![NodeServiceData { + auto_restart: false, + connected_peers: None, + data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + genesis: true, + home_network: false, + listen_addr: None, + local: false, + log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), + log_format: None, + max_archived_log_files: None, + max_log_files: None, + metrics_port: None, + node_ip: None, + node_port: None, + number: 1, + owner: None, + peer_id: None, + pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, + reward_balance: Some(AttoTokens::zero()), + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), + antnode_path: PathBuf::from("/var/antctl/services/antnode1/antnode"), + service_name: "antnode1".to_string(), + status: ServiceStatus::Added, + upnp: false, + user: Some("ant".to_string()), + user_mode: false, + version: latest_version.to_string(), + }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; - let latest_version = "0.96.4"; let temp_dir = assert_fs::TempDir::new()?; - let node_data_dir = temp_dir.child("data"); + let node_data_dir = temp_dir.child("antnode1"); node_data_dir.create_dir_all()?; let node_logs_dir = temp_dir.child("logs"); node_logs_dir.create_dir_all()?; let antnode_download_path = temp_dir.child(ANTNODE_FILE_NAME); antnode_download_path.write_binary(b"fake antnode bin")?; - let peers_args = PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: true, - }; - let mut seq = Sequence::new(); - mock_service_control .expect_get_available_port() .times(1) - .returning(|| Ok(12001)) + .returning(|| Ok(8083)) .in_sequence(&mut seq); + let install_ctx = InstallNodeServiceCtxBuilder { + autostart: false, + bootstrap_peers: vec![], + data_dir_path: node_data_dir.to_path_buf().join("antnode2"), + env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + genesis: false, + home_network: false, + local: false, + log_dir_path: node_logs_dir.to_path_buf().join("antnode2"), + log_format: None, + max_archived_log_files: None, + max_log_files: None, + metrics_port: None, + name: "antnode2".to_string(), + node_ip: None, + node_port: None, + rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083), + owner: None, + antnode_path: node_data_dir + .to_path_buf() + .join("antnode2") + .join(ANTNODE_FILE_NAME), + service_user: Some(get_username()), + upnp: false, + } + .build()?; mock_service_control .expect_install() .times(1) - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:12001"), - OsString::from("--root-dir"), - OsString::from( - node_data_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--log-output-dest"), - OsString::from( - node_logs_dir - .to_path_buf() - .join("antnode1") - .to_string_lossy() - .to_string(), - ), - OsString::from("--ignore-cache"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-custom"), - OsString::from("--rpc-url"), - OsString::from("http://localhost:8545/"), - OsString::from("--payment-token-address"), - OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), - OsString::from("--data-payments-address"), - OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: node_data_dir - .to_path_buf() - .join("antnode1") - .join(ANTNODE_FILE_NAME), - username: Some(get_username()), - working_directory: None, - }), - eq(false), - ) + .with(eq(install_ctx), eq(false)) .returning(|_, _| Ok(())) .in_sequence(&mut seq); @@ -1927,23 +1173,25 @@ async fn add_node_should_create_service_file_with_ignore_cache_arg() -> Result<( AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: peers_args.clone(), rpc_address: None, rpc_port: None, - antnode_dir_path: temp_dir.to_path_buf(), antnode_src_path: antnode_download_path.to_path_buf(), + antnode_dir_path: temp_dir.to_path_buf(), service_data_dir_path: node_data_dir.to_path_buf(), service_log_dir_path: node_logs_dir.to_path_buf(), upnp: false, @@ -1969,12 +1217,25 @@ async fn add_node_should_create_service_file_with_ignore_cache_arg() -> Result<( ) .await?; - antnode_download_path.assert(predicate::path::missing()); - node_data_dir.assert(predicate::path::is_dir()); - node_logs_dir.assert(predicate::path::is_dir()); - assert_eq!(node_registry.nodes.len(), 1); - assert_eq!(node_registry.nodes[0].version, latest_version); - assert_eq!(node_registry.nodes[0].peers_args, peers_args); + assert_eq!(node_registry.nodes.len(), 2); + assert_eq!(node_registry.nodes[1].version, latest_version); + assert_eq!(node_registry.nodes[1].service_name, "antnode2"); + assert_eq!(node_registry.nodes[1].user, Some(get_username())); + assert_eq!(node_registry.nodes[1].number, 2); + assert_eq!( + node_registry.nodes[1].rpc_socket_addr, + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083) + ); + assert_eq!( + node_registry.nodes[1].log_dir_path, + node_logs_dir.to_path_buf().join("antnode2") + ); + assert_eq!( + node_registry.nodes[1].data_dir_path, + node_data_dir.to_path_buf().join("antnode2") + ); + assert_matches!(node_registry.nodes[0].status, ServiceStatus::Added); + assert!(!node_registry.nodes[0].auto_restart); Ok(()) } @@ -1992,6 +1253,7 @@ async fn add_node_should_use_custom_ip() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2070,19 +1332,21 @@ async fn add_node_should_use_custom_ip() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: Some(custom_ip), node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -2135,6 +1399,7 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2158,6 +1423,7 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { .in_sequence(&mut seq); let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -2169,7 +1435,9 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -2179,7 +1447,6 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { node_ip: None, node_port: Some(custom_port), owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), antnode_path: node_data_dir @@ -2202,19 +1469,21 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: Some(PortRange::Single(custom_port)), - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -2267,6 +1536,7 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2459,19 +1729,21 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: Some(PortRange::Range(12000, 12002)), - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -2535,8 +1807,10 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_format: None, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), max_archived_log_files: None, @@ -2547,7 +1821,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -2562,6 +1835,7 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R user_mode: false, version: "0.98.1".to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2578,19 +1852,21 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: Some(PortRange::Single(12000)), - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -2652,8 +1928,10 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_format: None, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), max_archived_log_files: None, @@ -2661,9 +1939,8 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us metrics_port: None, node_ip: None, node_port: Some(12000), - owner: None, - peers_args: PeersArgs::default(), number: 1, + owner: None, peer_id: None, pid: None, rewards_address: RewardsAddress::from_str( @@ -2679,6 +1956,7 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us user_mode: false, version: "0.98.1".to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2695,19 +1973,21 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: Some(PortRange::Range(12000, 12002)), - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -2757,6 +2037,7 @@ async fn add_node_should_return_an_error_if_port_and_node_count_do_not_match() - save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2773,19 +2054,21 @@ async fn add_node_should_return_an_error_if_port_and_node_count_do_not_match() - AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(2), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: Some(PortRange::Range(12000, 12002)), - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_src_path: antnode_download_path.to_path_buf(), @@ -2840,6 +2123,7 @@ async fn add_node_should_return_an_error_if_multiple_services_are_specified_with save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -2856,19 +2140,21 @@ async fn add_node_should_return_an_error_if_multiple_services_are_specified_with AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(2), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: Some(PortRange::Single(12000)), - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -2924,6 +2210,7 @@ async fn add_node_should_set_random_ports_if_enable_metrics_server_is_true() -> save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3001,19 +2288,21 @@ async fn add_node_should_set_random_ports_if_enable_metrics_server_is_true() -> AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: true, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -3060,6 +2349,7 @@ async fn add_node_should_set_max_archived_log_files() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3138,19 +2428,21 @@ async fn add_node_should_set_max_archived_log_files() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(1), delete_antnode_src: false, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: Some(20), max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -3198,6 +2490,7 @@ async fn add_node_should_set_max_log_files() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3276,19 +2569,21 @@ async fn add_node_should_set_max_log_files() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(1), delete_antnode_src: false, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: Some(20), metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -3336,6 +2631,7 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3528,19 +2824,21 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: Some(PortRange::Range(12000, 12002)), + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -3601,8 +2899,10 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -3613,7 +2913,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -3628,6 +2927,7 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use user_mode: false, version: "0.98.1".to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3644,19 +2944,21 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: Some(PortRange::Single(12000)), + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -3719,8 +3021,10 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -3731,7 +3035,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -3746,6 +3049,7 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran user_mode: false, version: "0.98.1".to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3762,19 +3066,21 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: Some(PortRange::Range(12000, 12002)), + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -3826,6 +3132,7 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -3997,19 +3304,21 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(3), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: Some(PortRange::Range(20000, 20002)), antnode_dir_path: temp_dir.to_path_buf(), @@ -4081,8 +3390,10 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4093,7 +3404,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -4108,6 +3418,7 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() user_mode: false, version: "0.98.1".to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -4124,19 +3435,21 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: Some(PortRange::Single(8081)), antnode_dir_path: temp_dir.to_path_buf(), @@ -4199,8 +3512,10 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4211,7 +3526,6 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -4226,6 +3540,7 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i user_mode: false, version: "0.98.1".to_string(), }], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -4242,19 +3557,21 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(2), delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: Some(PortRange::Range(8081, 8082)), antnode_dir_path: temp_dir.to_path_buf(), @@ -4306,6 +3623,7 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() save_path: node_reg_path.to_path_buf(), nat_status: Some(NatDetectionStatus::Public), nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -4328,6 +3646,7 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -4339,7 +3658,9 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -4349,7 +3670,6 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), antnode_path: node_data_dir @@ -4371,19 +3691,21 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: true, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + local: false, + genesis: false, home_network: true, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -4432,6 +3754,7 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: Some(NatDetectionStatus::UPnP), nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -4454,6 +3777,7 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -4465,7 +3789,9 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -4475,7 +3801,6 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), antnode_path: node_data_dir @@ -4497,19 +3822,21 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: true, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + local: false, + genesis: false, home_network: true, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -4558,6 +3885,7 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul save_path: node_reg_path.to_path_buf(), nat_status: Some(NatDetectionStatus::Private), nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -4580,6 +3908,7 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -4591,7 +3920,9 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: true, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -4601,7 +3932,6 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), antnode_path: node_data_dir @@ -4623,19 +3953,21 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: true, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + local: false, + genesis: false, home_network: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -4685,6 +4017,7 @@ async fn add_node_should_return_an_error_if_nat_status_is_none_but_auto_set_nat_ save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -4709,19 +4042,21 @@ async fn add_node_should_return_an_error_if_nat_status_is_none_but_auto_set_nat_ AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: true, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + local: false, + genesis: false, home_network: true, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -4780,6 +4115,7 @@ async fn add_auditor_should_add_an_auditor_service() -> Result<()> { auditor_download_path.write_binary(b"fake auditor bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: None, auditor: None, faucet: None, @@ -4814,6 +4150,7 @@ async fn add_auditor_should_add_an_auditor_service() -> Result<()> { add_auditor( AddAuditorServiceOptions { + bootstrap_peers: vec![], beta_encryption_key: None, env_variables: Some(vec![("ANT_LOG".to_string(), "all".to_string())]), auditor_src_bin_path: auditor_download_path.to_path_buf(), @@ -4865,6 +4202,7 @@ async fn add_auditor_should_return_an_error_if_a_auditor_service_was_already_cre auditor_download_path.write_binary(b"fake auditor bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: None, auditor: Some(AuditorServiceData { auditor_path: auditor_download_path.to_path_buf(), @@ -4884,6 +4222,7 @@ async fn add_auditor_should_return_an_error_if_a_auditor_service_was_already_cre let result = add_auditor( AddAuditorServiceOptions { + bootstrap_peers: vec![], beta_encryption_key: None, env_variables: Some(vec![("ANT_LOG".to_string(), "all".to_string())]), auditor_src_bin_path: auditor_download_path.to_path_buf(), @@ -4926,6 +4265,7 @@ async fn add_auditor_should_include_beta_encryption_key_if_specified() -> Result auditor_download_path.write_binary(b"fake auditor bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: None, auditor: None, faucet: None, @@ -4962,6 +4302,7 @@ async fn add_auditor_should_include_beta_encryption_key_if_specified() -> Result add_auditor( AddAuditorServiceOptions { + bootstrap_peers: vec![], beta_encryption_key: Some("test".to_string()), env_variables: Some(vec![("ANT_LOG".to_string(), "all".to_string())]), auditor_src_bin_path: auditor_download_path.to_path_buf(), @@ -5014,6 +4355,7 @@ async fn add_faucet_should_add_a_faucet_service() -> Result<()> { faucet_download_path.write_binary(b"fake faucet bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: None, auditor: None, faucet: None, @@ -5049,6 +4391,7 @@ async fn add_faucet_should_add_a_faucet_service() -> Result<()> { add_faucet( AddFaucetServiceOptions { + bootstrap_peers: vec![], env_variables: Some(vec![("ANT_LOG".to_string(), "all".to_string())]), faucet_src_bin_path: faucet_download_path.to_path_buf(), faucet_install_bin_path: faucet_install_path.to_path_buf(), @@ -5100,6 +4443,7 @@ async fn add_faucet_should_return_an_error_if_a_faucet_service_was_already_creat faucet_download_path.write_binary(b"fake faucet bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: None, auditor: None, faucet: Some(FaucetServiceData { @@ -5120,6 +4464,7 @@ async fn add_faucet_should_return_an_error_if_a_faucet_service_was_already_creat let result = add_faucet( AddFaucetServiceOptions { + bootstrap_peers: vec![], env_variables: Some(vec![("ANT_LOG".to_string(), "all".to_string())]), faucet_src_bin_path: faucet_download_path.to_path_buf(), faucet_install_bin_path: faucet_install_path.to_path_buf(), @@ -5161,6 +4506,7 @@ async fn add_daemon_should_add_a_daemon_service() -> Result<()> { daemon_download_path.write_binary(b"fake daemon bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: None, auditor: None, faucet: None, @@ -5238,6 +4584,7 @@ async fn add_daemon_should_return_an_error_if_a_daemon_service_was_already_creat daemon_download_path.write_binary(b"fake daemon bin")?; let mut node_registry = NodeRegistry { + bootstrap_peers: vec![], daemon: Some(DaemonServiceData { daemon_path: PathBuf::from("/usr/local/bin/antctld"), endpoint: Some(SocketAddr::new( @@ -5297,6 +4644,7 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -5321,6 +4669,7 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -5332,7 +4681,9 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -5342,7 +4693,6 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), antnode_path: node_data_dir @@ -5365,19 +4715,21 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(1), delete_antnode_src: false, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -5425,6 +4777,7 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -5449,9 +4802,12 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, + genesis: false, home_network: true, + local: false, evm_network: EvmNetwork::Custom(CustomNetwork { rpc_url_http: "http://localhost:8545".parse()?, payment_token_address: RewardsAddress::from_str( @@ -5470,7 +4826,6 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), antnode_path: node_data_dir @@ -5493,19 +4848,21 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(1), delete_antnode_src: false, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: true, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -5553,6 +4910,7 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -5577,6 +4935,7 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -5588,7 +4947,9 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: true, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -5598,7 +4959,6 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), antnode_path: node_data_dir @@ -5621,19 +4981,21 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(1), delete_antnode_src: false, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: true, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -5679,6 +5041,7 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { save_path: node_reg_path.to_path_buf(), nat_status: None, nodes: vec![], + bootstrap_peers: vec![], environment_variables: None, daemon: None, }; @@ -5702,6 +5065,7 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { let install_ctx = InstallNodeServiceCtxBuilder { autostart: false, + bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("antnode1"), env_variables: None, evm_network: EvmNetwork::Custom(CustomNetwork { @@ -5713,7 +5077,9 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: true, + local: false, log_dir_path: node_logs_dir.to_path_buf().join("antnode1"), log_format: None, max_archived_log_files: None, @@ -5723,7 +5089,6 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { node_ip: None, node_port: None, owner: None, - peers_args: PeersArgs::default(), rewards_address: RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), antnode_path: node_data_dir @@ -5746,19 +5111,21 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: Some(1), delete_antnode_src: false, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: true, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: None, node_ip: None, node_port: None, - owner: None, - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -5810,6 +5177,7 @@ async fn add_node_should_assign_an_owner_in_lowercase() -> Result<()> { let mut node_registry = NodeRegistry { auditor: None, + bootstrap_peers: vec![], daemon: None, environment_variables: None, faucet: None, @@ -5882,19 +5250,21 @@ async fn add_node_should_assign_an_owner_in_lowercase() -> Result<()> { AddNodeServiceOptions { auto_restart: false, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: Some("Discord_Username".to_string()), node_ip: None, node_port: None, - owner: Some("Discord_Username".to_string()), - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), @@ -5948,6 +5318,7 @@ async fn add_node_should_auto_restart() -> Result<()> { let mut node_registry = NodeRegistry { auditor: None, + bootstrap_peers: vec![], daemon: None, environment_variables: None, faucet: None, @@ -6020,19 +5391,21 @@ async fn add_node_should_auto_restart() -> Result<()> { AddNodeServiceOptions { auto_restart: true, auto_set_nat_flags: false, + bootstrap_peers: vec![], count: None, delete_antnode_src: true, enable_metrics_server: false, env_variables: None, + genesis: false, home_network: false, + local: false, log_format: None, max_archived_log_files: None, max_log_files: None, metrics_port: None, + owner: Some("discord_username".to_string()), node_ip: None, node_port: None, - owner: Some("discord_username".to_string()), - peers_args: PeersArgs::default(), rpc_address: None, rpc_port: None, antnode_dir_path: temp_dir.to_path_buf(), diff --git a/ant-node-manager/src/bin/cli/main.rs b/ant-node-manager/src/bin/cli/main.rs index 5e6afa325c..14b84e55f7 100644 --- a/ant-node-manager/src/bin/cli/main.rs +++ b/ant-node-manager/src/bin/cli/main.rs @@ -1097,6 +1097,7 @@ async fn main() -> Result<()> { env_variables, Some(evm_network.try_into()?), home_network, + peers.local, log_dir_path, log_format, max_archived_log_files, diff --git a/ant-node-manager/src/cmd/node.rs b/ant-node-manager/src/cmd/node.rs index a96a0bb118..d21de2b45e 100644 --- a/ant-node-manager/src/cmd/node.rs +++ b/ant-node-manager/src/cmd/node.rs @@ -44,6 +44,7 @@ pub async fn add( env_variables: Option>, evm_network: Option, home_network: bool, + local: bool, log_dir_path: Option, log_format: Option, max_archived_log_files: Option, @@ -52,7 +53,7 @@ pub async fn add( node_ip: Option, node_port: Option, owner: Option, - mut peers_args: PeersArgs, + peers_args: PeersArgs, rewards_address: RewardsAddress, rpc_address: Option, rpc_port: Option, @@ -104,17 +105,47 @@ pub async fn add( debug!("Parsing peers from PeersArgs"); - peers_args.addrs.extend(PeersArgs::read_addr_from_env()); + // Handle the `PeersNotObtained` error to make the `--peer` argument optional for the node + // manager. + // + // Since any application making use of the node manager can enable the `network-contacts` feature on + // ant_peers_acquisition, we might end up getting having a huge peer list, and that's problematic for + // service definition files. + // Thus make use of get_peers_exclude_network_contacts() instead of get_peers() to make sure we only + // parse the --peers and ANT_PEERS env var. + + // If the `antnode` binary we're using has `network-contacts` enabled (which is the case for released binaries), + // it's fine if the service definition doesn't call `antnode` with a `--peer` argument. + let is_first = peers_args.first; + let bootstrap_peers = match peers_args.get_addrs(None).await { + Ok(peers) => { + info!("Obtained peers of length {}", peers.len()); + peers.into_iter().take(10).collect::>() + } + Err(err) => match err { + ant_bootstrap::error::Error::NoBootstrapPeersFound => { + info!("No bootstrap peers obtained, setting empty vec."); + Vec::new() + } + _ => { + error!("Error obtaining peers: {err:?}"); + return Err(err.into()); + } + }, + }; let options = AddNodeServiceOptions { auto_restart, auto_set_nat_flags, + bootstrap_peers, count, delete_antnode_src: src_path.is_none(), enable_metrics_server, evm_network: evm_network.unwrap_or(EvmNetwork::ArbitrumOne), env_variables, + genesis: is_first, home_network, + local, log_format, max_archived_log_files, max_log_files, @@ -122,7 +153,6 @@ pub async fn add( node_ip, node_port, owner, - peers_args, rewards_address, rpc_address, rpc_port, @@ -505,6 +535,7 @@ pub async fn upgrade( }; let options = UpgradeOptions { auto_restart: false, + bootstrap_peers: node_registry.bootstrap_peers.clone(), env_variables: env_variables.clone(), force: use_force, start_service: !do_not_start, @@ -582,6 +613,7 @@ pub async fn maintain_n_running_nodes( env_variables: Option>, evm_network: Option, home_network: bool, + local: bool, log_dir_path: Option, log_format: Option, max_archived_log_files: Option, @@ -590,7 +622,7 @@ pub async fn maintain_n_running_nodes( node_ip: Option, node_port: Option, owner: Option, - peers_args: PeersArgs, + peers: PeersArgs, rewards_address: RewardsAddress, rpc_address: Option, rpc_port: Option, @@ -686,6 +718,7 @@ pub async fn maintain_n_running_nodes( env_variables.clone(), evm_network.clone(), home_network, + local, log_dir_path.clone(), log_format, max_archived_log_files, @@ -694,7 +727,7 @@ pub async fn maintain_n_running_nodes( node_ip, Some(PortRange::Single(port)), owner.clone(), - peers_args.clone(), + peers.clone(), rewards_address, rpc_address, rpc_port.clone(), diff --git a/ant-node-manager/src/lib.rs b/ant-node-manager/src/lib.rs index 7987c55224..696eb93463 100644 --- a/ant-node-manager/src/lib.rs +++ b/ant-node-manager/src/lib.rs @@ -649,7 +649,6 @@ fn format_status_without_colour(status: &ServiceStatus) -> String { #[cfg(test)] mod tests { use super::*; - use ant_bootstrap::PeersArgs; use ant_evm::{AttoTokens, CustomNetwork, EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; use ant_service_management::{ @@ -760,8 +759,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -772,7 +773,6 @@ mod tests { number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -873,8 +873,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -887,7 +889,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -951,8 +952,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -965,7 +968,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1069,8 +1071,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1083,7 +1087,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1160,8 +1163,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1172,7 +1177,6 @@ mod tests { number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1261,8 +1265,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1273,7 +1279,6 @@ mod tests { number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1361,8 +1366,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1373,7 +1380,6 @@ mod tests { number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1431,8 +1437,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1445,7 +1453,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1493,8 +1500,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1505,7 +1514,6 @@ mod tests { number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1553,8 +1561,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1567,7 +1577,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1616,8 +1625,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1628,7 +1639,6 @@ mod tests { number: 1, owner: None, peer_id: None, - peers_args: PeersArgs::default(), pid: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1690,8 +1700,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1704,7 +1716,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1829,8 +1840,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1843,7 +1856,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1868,6 +1880,7 @@ mod tests { let upgrade_result = service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -1929,8 +1942,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -1943,7 +1958,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -1969,6 +1983,7 @@ mod tests { let upgrade_result = service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -2074,8 +2089,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -2088,7 +2105,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -2114,6 +2130,7 @@ mod tests { let upgrade_result = service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: true, start_service: true, @@ -2231,8 +2248,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -2245,7 +2264,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -2271,6 +2289,7 @@ mod tests { let upgrade_result = service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: false, @@ -2383,8 +2402,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -2397,7 +2418,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -2422,6 +2442,7 @@ mod tests { let upgrade_result = service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -2536,8 +2557,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -2550,7 +2573,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -2576,6 +2598,7 @@ mod tests { let upgrade_result = service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -2607,1037 +2630,6 @@ mod tests { Ok(()) } - #[tokio::test] - async fn upgrade_should_retain_the_first_flag() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--first"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: true, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert!(service_manager.service.service_data.peers_args.first); - - Ok(()) - } - - #[tokio::test] - async fn upgrade_should_retain_the_peers_arg() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--peer"), - OsString::from( - "/ip4/127.0.0.1/tcp/8080/p2p/12D3KooWRBhwfeP2Y4TCx1SM6s9rUoHhR5STiGwxBhgFRcw3UERE" - ), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: false, - addrs: vec![ - "/ip4/127.0.0.1/tcp/8080/p2p/12D3KooWRBhwfeP2Y4TCx1SM6s9rUoHhR5STiGwxBhgFRcw3UERE" - .parse()?, - ], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert!(!service_manager - .service - .service_data - .peers_args - .addrs - .is_empty()); - - Ok(()) - } - - #[tokio::test] - async fn upgrade_should_retain_the_local_flag() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--local"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: true, - disable_mainnet_contacts: false, - ignore_cache: false, - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert!(service_manager.service.service_data.peers_args.local); - - Ok(()) - } - - #[tokio::test] - async fn upgrade_should_retain_the_network_contacts_url_arg() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--network-contacts-url"), - OsString::from("http://localhost:8080/contacts.json,http://localhost:8081/contacts.json"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![ - "http://localhost:8080/contacts.json".to_string(), - "http://localhost:8081/contacts.json".to_string(), - ], - local: false, - disable_mainnet_contacts: false, - ignore_cache: false, - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert_eq!( - service_manager - .service - .service_data - .peers_args - .network_contacts_url - .len(), - 2 - ); - - Ok(()) - } - - #[tokio::test] - async fn upgrade_should_retain_the_testnet_flag() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--testnet"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: true, - ignore_cache: false, - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert!( - service_manager - .service - .service_data - .peers_args - .disable_mainnet_contacts - ); - - Ok(()) - } - - #[tokio::test] - async fn upgrade_should_retain_the_ignore_cache_flag() -> Result<()> { - let current_version = "0.1.0"; - let target_version = "0.2.0"; - - let tmp_data_dir = assert_fs::TempDir::new()?; - let current_install_dir = tmp_data_dir.child("antnode_install"); - current_install_dir.create_dir_all()?; - - let current_node_bin = current_install_dir.child("antnode"); - current_node_bin.write_binary(b"fake antnode binary")?; - let target_node_bin = tmp_data_dir.child("antnode"); - target_node_bin.write_binary(b"fake antnode binary")?; - - let mut mock_service_control = MockServiceControl::new(); - let mut mock_rpc_client = MockRpcClient::new(); - - // before binary upgrade - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(1000)); - mock_service_control - .expect_stop() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - - // after binary upgrade - mock_service_control - .expect_uninstall() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_install() - .with( - eq(ServiceInstallCtx { - args: vec![ - OsString::from("--rpc"), - OsString::from("127.0.0.1:8081"), - OsString::from("--root-dir"), - OsString::from("/var/antctl/services/antnode1"), - OsString::from("--log-output-dest"), - OsString::from("/var/log/antnode/antnode1"), - OsString::from("--ignore-cache"), - OsString::from("--rewards-address"), - OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), - OsString::from("evm-arbitrum-one"), - ], - autostart: false, - contents: None, - environment: None, - label: "antnode1".parse()?, - program: current_node_bin.to_path_buf(), - username: Some("ant".to_string()), - working_directory: None, - }), - eq(false), - ) - .times(1) - .returning(|_, _| Ok(())); - - // after service restart - mock_service_control - .expect_start() - .with(eq("antnode1"), eq(false)) - .times(1) - .returning(|_, _| Ok(())); - mock_service_control - .expect_wait() - .with(eq(3000)) - .times(1) - .returning(|_| ()); - mock_service_control - .expect_get_process_pid() - .with(eq(current_node_bin.to_path_buf().clone())) - .times(1) - .returning(|_| Ok(100)); - - mock_rpc_client.expect_node_info().times(1).returning(|| { - Ok(NodeInfo { - pid: 2000, - peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, - data_path: PathBuf::from("/var/antctl/services/antnode1"), - log_path: PathBuf::from("/var/log/antnode/antnode1"), - version: target_version.to_string(), - uptime: std::time::Duration::from_secs(1), // the service was just started - wallet_balance: 0, - }) - }); - mock_rpc_client - .expect_network_info() - .times(1) - .returning(|| { - Ok(NetworkInfo { - connected_peers: Vec::new(), - listeners: Vec::new(), - }) - }); - - let mut service_data = NodeServiceData { - auto_restart: false, - connected_peers: None, - data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), - evm_network: EvmNetwork::ArbitrumOne, - home_network: false, - listen_addr: None, - log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), - log_format: None, - max_archived_log_files: None, - max_log_files: None, - metrics_port: None, - node_ip: None, - node_port: None, - number: 1, - owner: None, - peer_id: Some(PeerId::from_str( - "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", - )?), - peers_args: PeersArgs { - first: false, - addrs: vec![], - network_contacts_url: vec![], - local: false, - disable_mainnet_contacts: false, - ignore_cache: true, - }, - pid: Some(1000), - rewards_address: RewardsAddress::from_str( - "0x03B770D9cD32077cC0bF330c13C114a87643B124", - )?, - reward_balance: Some(AttoTokens::zero()), - rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), - antnode_path: current_node_bin.to_path_buf(), - service_name: "antnode1".to_string(), - status: ServiceStatus::Running, - upnp: false, - user: Some("ant".to_string()), - user_mode: false, - version: current_version.to_string(), - }; - let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); - - let mut service_manager = ServiceManager::new( - service, - Box::new(mock_service_control), - VerbosityLevel::Normal, - ); - - service_manager - .upgrade(UpgradeOptions { - auto_restart: false, - env_variables: None, - force: false, - start_service: true, - target_bin_path: target_node_bin.to_path_buf(), - target_version: Version::parse(target_version).unwrap(), - }) - .await?; - - assert!(service_manager.service.service_data.peers_args.ignore_cache); - - Ok(()) - } - #[tokio::test] async fn upgrade_should_retain_the_upnp_flag() -> Result<()> { let current_version = "0.1.0"; @@ -3745,8 +2737,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -3759,7 +2753,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -3785,6 +2778,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -3906,8 +2900,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: Some(LogFormat::Json), max_archived_log_files: None, @@ -3920,7 +2916,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -3946,6 +2941,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -4070,8 +3066,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: true, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4084,7 +3082,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -4110,6 +3107,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -4231,8 +3229,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4245,7 +3245,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -4271,6 +3270,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -4395,8 +3395,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4409,7 +3411,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -4435,6 +3436,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -4555,8 +3557,10 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: Some(20), @@ -4569,7 +3573,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), @@ -4596,6 +3599,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -4719,8 +3723,10 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4733,7 +3739,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), @@ -4760,6 +3765,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -4881,8 +3887,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -4895,7 +3903,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -4921,6 +3928,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5045,8 +4053,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -5059,7 +4069,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -5085,6 +4094,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5209,8 +4219,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -5223,7 +4235,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -5249,6 +4260,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5373,8 +4385,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -5387,7 +4401,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -5413,6 +4426,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: true, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5548,8 +4562,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -5562,7 +4578,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -5589,6 +4604,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: true, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5724,8 +4740,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -5738,7 +4756,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -5765,6 +4782,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: true, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5888,8 +4906,10 @@ mod tests { connected_peers: None, data_dir_path: PathBuf::from("/var/antctl/services/antnode1"), evm_network: EvmNetwork::ArbitrumOne, + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -5902,7 +4922,6 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), - peers_args: PeersArgs::default(), pid: Some(1000), rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -5931,6 +4950,7 @@ mod tests { service_manager .upgrade(UpgradeOptions { auto_restart: false, + bootstrap_peers: Vec::new(), env_variables: None, force: false, start_service: true, @@ -5972,8 +4992,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: log_dir.to_path_buf(), log_format: None, max_archived_log_files: None, @@ -5983,9 +5005,8 @@ mod tests { node_port: None, number: 1, owner: None, - peers_args: PeersArgs::default(), - peer_id: None, pid: None, + peer_id: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", )?, @@ -6040,8 +5061,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -6051,7 +5074,6 @@ mod tests { node_port: None, number: 1, owner: None, - peers_args: PeersArgs::default(), pid: Some(1000), peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", @@ -6123,8 +5145,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: PathBuf::from("/var/log/antnode/antnode1"), log_format: None, max_archived_log_files: None, @@ -6134,7 +5158,6 @@ mod tests { node_port: None, number: 1, owner: None, - peers_args: PeersArgs::default(), pid: Some(1000), peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", @@ -6201,8 +5224,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: log_dir.to_path_buf(), log_format: None, max_archived_log_files: None, @@ -6213,7 +5238,6 @@ mod tests { number: 1, owner: None, pid: None, - peers_args: PeersArgs::default(), peer_id: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", @@ -6277,8 +5301,10 @@ mod tests { "0x8464135c8F25Da09e49BC8782676a84730C318bC", )?, }), + genesis: false, home_network: false, listen_addr: None, + local: false, log_dir_path: log_dir.to_path_buf(), log_format: None, max_archived_log_files: None, @@ -6289,7 +5315,6 @@ mod tests { number: 1, owner: None, pid: None, - peers_args: PeersArgs::default(), peer_id: None, rewards_address: RewardsAddress::from_str( "0x03B770D9cD32077cC0bF330c13C114a87643B124", diff --git a/ant-node-manager/src/local.rs b/ant-node-manager/src/local.rs index 9b8b61e4e3..e1fa3d4290 100644 --- a/ant-node-manager/src/local.rs +++ b/ant-node-manager/src/local.rs @@ -11,7 +11,6 @@ use crate::helpers::{ check_port_availability, get_bin_version, get_start_port_if_applicable, increment_port_option, }; -use ant_bootstrap::PeersArgs; use ant_evm::{EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; use ant_service_management::{ @@ -39,7 +38,7 @@ pub trait Launcher { #[allow(clippy::too_many_arguments)] fn launch_node( &self, - first: bool, + bootstrap_peers: Vec, log_format: Option, metrics_port: Option, node_port: Option, @@ -63,7 +62,7 @@ impl Launcher for LocalSafeLauncher { fn launch_node( &self, - first: bool, + bootstrap_peers: Vec, log_format: Option, metrics_port: Option, node_port: Option, @@ -79,8 +78,13 @@ impl Launcher for LocalSafeLauncher { args.push(owner); } - if first { + if bootstrap_peers.is_empty() { args.push("--first".to_string()) + } else { + for peer in bootstrap_peers { + args.push("--peer".to_string()); + args.push(peer.to_string()); + } } if let Some(log_format) = log_format { @@ -292,7 +296,8 @@ pub async fn run_network( let owner = get_node_owner(&options.owner_prefix, &options.owner, &number); let node = run_node( RunNodeOptions { - first: true, + bootstrap_peers: vec![], + genesis: true, metrics_port: metrics_free_port, node_port, interval: options.interval, @@ -340,7 +345,8 @@ pub async fn run_network( let owner = get_node_owner(&options.owner_prefix, &options.owner, &number); let node = run_node( RunNodeOptions { - first: false, + bootstrap_peers: bootstrap_peers.clone(), + genesis: false, metrics_port: metrics_free_port, node_port, interval: options.interval, @@ -380,7 +386,8 @@ pub async fn run_network( } pub struct RunNodeOptions { - pub first: bool, + pub bootstrap_peers: Vec, + pub genesis: bool, pub interval: u64, pub log_format: Option, pub metrics_port: Option, @@ -401,7 +408,7 @@ pub async fn run_node( info!("Launching node {}...", run_options.number); println!("Launching node {}...", run_options.number); launcher.launch_node( - run_options.first, + run_options.bootstrap_peers.clone(), run_options.log_format, run_options.metrics_port, run_options.node_port, @@ -428,8 +435,10 @@ pub async fn run_node( connected_peers, data_dir_path: node_info.data_path, evm_network: run_options.evm_network.unwrap_or(EvmNetwork::ArbitrumOne), + genesis: run_options.genesis, home_network: false, listen_addr: Some(listen_addrs), + local: true, log_dir_path: node_info.log_path, log_format: run_options.log_format, max_archived_log_files: None, @@ -440,14 +449,6 @@ pub async fn run_node( number: run_options.number, owner: run_options.owner, peer_id: Some(peer_id), - peers_args: PeersArgs { - first: run_options.first, - addrs: vec![], - network_contacts_url: vec![], - local: true, - disable_mainnet_contacts: true, - ignore_cache: true, - }, pid: Some(node_info.pid), rewards_address: run_options.rewards_address, reward_balance: None, @@ -563,7 +564,7 @@ mod tests { mock_launcher .expect_launch_node() .with( - eq(true), + eq(vec![]), eq(None), eq(None), eq(None), @@ -610,7 +611,8 @@ mod tests { let node = run_node( RunNodeOptions { - first: true, + bootstrap_peers: vec![], + genesis: true, interval: 100, log_format: None, metrics_port: None, @@ -627,7 +629,7 @@ mod tests { ) .await?; - assert!(node.peers_args.first); + assert!(node.genesis); assert_eq!(node.version, "0.100.12"); assert_eq!(node.service_name, "antnode-local1"); assert_eq!( diff --git a/ant-node-manager/src/rpc.rs b/ant-node-manager/src/rpc.rs index a06d0ef338..5cc357c2e8 100644 --- a/ant-node-manager/src/rpc.rs +++ b/ant-node-manager/src/rpc.rs @@ -64,20 +64,22 @@ pub async fn restart_node_service( let install_ctx = InstallNodeServiceCtxBuilder { antnode_path: current_node_clone.antnode_path.clone(), autostart: current_node_clone.auto_restart, + bootstrap_peers: node_registry.bootstrap_peers.clone(), data_dir_path: current_node_clone.data_dir_path.clone(), env_variables: node_registry.environment_variables.clone(), evm_network: current_node_clone.evm_network.clone(), + genesis: current_node_clone.genesis, home_network: current_node_clone.home_network, + local: current_node_clone.local, log_dir_path: current_node_clone.log_dir_path.clone(), log_format: current_node_clone.log_format, max_archived_log_files: current_node_clone.max_archived_log_files, max_log_files: current_node_clone.max_log_files, metrics_port: None, + owner: current_node_clone.owner.clone(), name: current_node_clone.service_name.clone(), node_ip: current_node_clone.node_ip, node_port: current_node_clone.get_antnode_port(), - owner: current_node_clone.owner.clone(), - peers_args: current_node_clone.peers_args.clone(), rewards_address: current_node_clone.rewards_address, rpc_socket_addr: current_node_clone.rpc_socket_addr, service_user: current_node_clone.user.clone(), @@ -179,10 +181,13 @@ pub async fn restart_node_service( let install_ctx = InstallNodeServiceCtxBuilder { autostart: current_node_clone.auto_restart, + bootstrap_peers: node_registry.bootstrap_peers.clone(), data_dir_path: data_dir_path.clone(), env_variables: node_registry.environment_variables.clone(), evm_network: current_node_clone.evm_network.clone(), + genesis: current_node_clone.genesis, home_network: current_node_clone.home_network, + local: current_node_clone.local, log_dir_path: log_dir_path.clone(), log_format: current_node_clone.log_format, name: new_service_name.clone(), @@ -192,7 +197,6 @@ pub async fn restart_node_service( node_ip: current_node_clone.node_ip, node_port: None, owner: None, - peers_args: current_node_clone.peers_args.clone(), rewards_address: current_node_clone.rewards_address, rpc_socket_addr: current_node_clone.rpc_socket_addr, antnode_path: antnode_path.clone(), @@ -210,8 +214,10 @@ pub async fn restart_node_service( connected_peers: None, data_dir_path, evm_network: current_node_clone.evm_network, + genesis: current_node_clone.genesis, home_network: current_node_clone.home_network, listen_addr: None, + local: current_node_clone.local, log_dir_path, log_format: current_node_clone.log_format, max_archived_log_files: current_node_clone.max_archived_log_files, @@ -222,7 +228,6 @@ pub async fn restart_node_service( number: new_node_number as u16, owner: None, peer_id: None, - peers_args: current_node_clone.peers_args.clone(), pid: None, rewards_address: current_node_clone.rewards_address, reward_balance: current_node_clone.reward_balance, diff --git a/ant-service-management/Cargo.toml b/ant-service-management/Cargo.toml index 53e2e27b38..bd65f25575 100644 --- a/ant-service-management/Cargo.toml +++ b/ant-service-management/Cargo.toml @@ -10,7 +10,6 @@ repository = "https://github.com/maidsafe/autonomi" version = "0.4.3" [dependencies] -ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" } ant-evm = { path = "../ant-evm", version = "0.1.4" } ant-logging = { path = "../ant-logging", version = "0.2.40" } ant-protocol = { path = "../ant-protocol", version = "0.17.15", features = ["rpc"] } diff --git a/ant-service-management/src/auditor.rs b/ant-service-management/src/auditor.rs index cea9273395..7df0bcb46c 100644 --- a/ant-service-management/src/auditor.rs +++ b/ant-service-management/src/auditor.rs @@ -54,6 +54,17 @@ impl ServiceStateActions for AuditorService<'_> { OsString::from(self.service_data.log_dir_path.to_string_lossy().to_string()), ]; + if !options.bootstrap_peers.is_empty() { + let peers_str = options + .bootstrap_peers + .iter() + .map(|peer| peer.to_string()) + .collect::>() + .join(","); + args.push(OsString::from("--peer")); + args.push(OsString::from(peers_str)); + } + args.push(OsString::from("server")); Ok(ServiceInstallCtx { diff --git a/ant-service-management/src/faucet.rs b/ant-service-management/src/faucet.rs index 7aa0d15b30..097db24f6a 100644 --- a/ant-service-management/src/faucet.rs +++ b/ant-service-management/src/faucet.rs @@ -55,6 +55,17 @@ impl ServiceStateActions for FaucetService<'_> { OsString::from(self.service_data.log_dir_path.to_string_lossy().to_string()), ]; + if !options.bootstrap_peers.is_empty() { + let peers_str = options + .bootstrap_peers + .iter() + .map(|peer| peer.to_string()) + .collect::>() + .join(","); + args.push(OsString::from("--peer")); + args.push(OsString::from(peers_str)); + } + args.push(OsString::from("server")); Ok(ServiceInstallCtx { diff --git a/ant-service-management/src/lib.rs b/ant-service-management/src/lib.rs index 1e4c970808..406f608631 100644 --- a/ant-service-management/src/lib.rs +++ b/ant-service-management/src/lib.rs @@ -23,6 +23,7 @@ pub mod antctl_proto { use async_trait::async_trait; use auditor::AuditorServiceData; +use libp2p::Multiaddr; use semver::Version; use serde::{Deserialize, Serialize}; use service_manager::ServiceInstallCtx; @@ -67,6 +68,7 @@ pub enum UpgradeResult { #[derive(Clone, Debug, Eq, PartialEq)] pub struct UpgradeOptions { pub auto_restart: bool, + pub bootstrap_peers: Vec, pub env_variables: Option>, pub force: bool, pub start_service: bool, @@ -101,6 +103,7 @@ pub struct StatusSummary { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NodeRegistry { pub auditor: Option, + pub bootstrap_peers: Vec, pub daemon: Option, pub environment_variables: Option>, pub faucet: Option, @@ -136,6 +139,7 @@ impl NodeRegistry { debug!("Loading default node registry as {path:?} does not exist"); return Ok(NodeRegistry { auditor: None, + bootstrap_peers: vec![], daemon: None, environment_variables: None, faucet: None, @@ -158,6 +162,7 @@ impl NodeRegistry { if contents.is_empty() { return Ok(NodeRegistry { auditor: None, + bootstrap_peers: vec![], daemon: None, environment_variables: None, faucet: None, diff --git a/ant-service-management/src/node.rs b/ant-service-management/src/node.rs index e1b5378bbc..e268976226 100644 --- a/ant-service-management/src/node.rs +++ b/ant-service-management/src/node.rs @@ -7,7 +7,6 @@ // permissions and limitations relating to use of the SAFE Network Software. use crate::{error::Result, rpc::RpcActions, ServiceStateActions, ServiceStatus, UpgradeOptions}; -use ant_bootstrap::PeersArgs; use ant_evm::{AttoTokens, EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; use ant_protocol::get_port_from_multiaddr; @@ -72,7 +71,12 @@ impl ServiceStateActions for NodeService<'_> { OsString::from(self.service_data.log_dir_path.to_string_lossy().to_string()), ]; - push_arguments_from_peers_args(&self.service_data.peers_args, &mut args); + if self.service_data.genesis { + args.push(OsString::from("--first")); + } + if self.service_data.local { + args.push(OsString::from("--local")); + } if let Some(log_fmt) = self.service_data.log_format { args.push(OsString::from("--log-format")); args.push(OsString::from(log_fmt.as_str())); @@ -111,6 +115,17 @@ impl ServiceStateActions for NodeService<'_> { args.push(OsString::from(owner)); } + if !options.bootstrap_peers.is_empty() { + let peers_str = options + .bootstrap_peers + .iter() + .map(|peer| peer.to_string()) + .collect::>() + .join(","); + args.push(OsString::from("--peer")); + args.push(OsString::from(peers_str)); + } + args.push(OsString::from("--rewards-address")); args.push(OsString::from( self.service_data.rewards_address.to_string(), @@ -276,8 +291,10 @@ pub struct NodeServiceData { pub data_dir_path: PathBuf, #[serde(default)] pub evm_network: EvmNetwork, + pub genesis: bool, pub home_network: bool, pub listen_addr: Option>, + pub local: bool, pub log_dir_path: PathBuf, pub log_format: Option, pub max_archived_log_files: Option, @@ -296,7 +313,6 @@ pub struct NodeServiceData { deserialize_with = "deserialize_peer_id" )] pub peer_id: Option, - pub peers_args: PeersArgs, pub pid: Option, #[serde(default)] pub rewards_address: RewardsAddress, @@ -388,40 +404,3 @@ impl NodeServiceData { None } } - -/// Pushes arguments from the `PeersArgs` struct to the provided `args` vector. -pub fn push_arguments_from_peers_args(peers_args: &PeersArgs, args: &mut Vec) { - if peers_args.first { - args.push(OsString::from("--first")); - } - if peers_args.local { - args.push(OsString::from("--local")); - } - if !peers_args.addrs.is_empty() { - let peers_str = peers_args - .addrs - .iter() - .map(|peer| peer.to_string()) - .collect::>() - .join(","); - args.push(OsString::from("--peer")); - args.push(OsString::from(peers_str)); - } - if !peers_args.network_contacts_url.is_empty() { - args.push(OsString::from("--network-contacts-url")); - args.push(OsString::from( - peers_args - .network_contacts_url - .iter() - .map(|url| url.to_string()) - .collect::>() - .join(","), - )); - } - if peers_args.disable_mainnet_contacts { - args.push(OsString::from("--testnet")); - } - if peers_args.ignore_cache { - args.push(OsString::from("--ignore-cache")); - } -} diff --git a/node-launchpad/src/node_mgmt.rs b/node-launchpad/src/node_mgmt.rs index daad00123f..49fd1c1b32 100644 --- a/node-launchpad/src/node_mgmt.rs +++ b/node-launchpad/src/node_mgmt.rs @@ -418,6 +418,7 @@ async fn scale_down_nodes(config: &NodeConfig, count: u16) { None, Some(EvmNetwork::ArbitrumSepolia), config.home_network, + false, None, None, None, @@ -491,6 +492,7 @@ async fn add_nodes( None, Some(EvmNetwork::ArbitrumSepolia), config.home_network, + false, None, None, None,