diff --git a/src/deploy.rs b/src/deploy.rs index d933ed06..e31305ce 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -140,8 +140,8 @@ impl TestnetDeployer { deployment_type: DeploymentType::New, environment_type: options.environment_type.clone(), evm_network: options.evm_network.clone(), - rewards_address: options.rewards_address.clone(), evm_testnet_data: evm_testnet_data.clone(), + rewards_address: options.rewards_address.clone(), }, ) .await?; diff --git a/src/funding.rs b/src/funding.rs index 77bb4713..d6914b4f 100644 --- a/src/funding.rs +++ b/src/funding.rs @@ -14,7 +14,7 @@ use crate::{ }; use alloy::{network::EthereumWallet, signers::local::PrivateKeySigner}; use evmlib::{common::U256, wallet::Wallet, Network}; -use log::{debug, error}; +use log::{debug, error, warn}; use std::collections::HashMap; use std::str::FromStr; @@ -48,11 +48,12 @@ impl AnsibleProvisioner { for (vm, count) in uploaders_count { if count == 0 { - error!("No uploader instances found for {:?}", vm.name); + warn!("No uploader instances found for {:?}, ", vm.name); + uploader_secret_keys.insert(vm.clone(), Vec::new()); + } else { + let sks = self.get_uploader_secret_key_per_vm(&vm, count)?; + uploader_secret_keys.insert(vm.clone(), sks); } - - let sks = self.get_uploader_secret_key_per_vm(&vm, count)?; - uploader_secret_keys.insert(vm.clone(), sks); } Ok(uploader_secret_keys) @@ -86,7 +87,9 @@ impl AnsibleProvisioner { vm.name ); for _ in 0..missing_keys_count { - keys.push(PrivateKeySigner::random()); + let sk = PrivateKeySigner::random(); + debug!("Generated key with address: {}", sk.address()); + keys.push(sk); } } } @@ -124,7 +127,7 @@ impl AnsibleProvisioner { let cmd = "systemctl list-units --type=service | grep autonomi_uploader_ | wc -l"; let result = self .ssh_client - .run_command(&vm.public_ip_addr, "root", cmd, false); + .run_command(&vm.public_ip_addr, "root", cmd, true); match result { Ok(count) => { debug!("Count found to be {count:?}, parsing"); @@ -172,9 +175,11 @@ impl AnsibleProvisioner { let mut sks_per_vm = Vec::new(); debug!( - "Fetching uploader count for {} @ {}", + "Fetching uploader secret key for {} @ {}", vm.name, vm.public_ip_addr ); + // Note: if this is gonna be parallelized, we need to make sure the secret keys are in order. + // the playbook expects them in order for count in 1..=instance_count { let cmd = format!( "systemctl show autonomi_uploader_{count}.service --property=Environment | grep SECRET_KEY | cut -d= -f3 | awk '{{print $1}}'" @@ -182,7 +187,7 @@ impl AnsibleProvisioner { debug!("Fetching secret key for {} instance {count}", vm.name); let result = self .ssh_client - .run_command(&vm.public_ip_addr, "root", &cmd, false); + .run_command(&vm.public_ip_addr, "root", &cmd, true); match result { Ok(secret_keys) => { let sk_str = secret_keys diff --git a/src/inventory.rs b/src/inventory.rs index 754bd943..8e4ef2dc 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -194,7 +194,7 @@ impl DeploymentInventoryService { wallet_public_key: sks .iter() .enumerate() - .map(|(user, sk)| (format!("safe{user}"), sk.address().encode_hex())) + .map(|(user, sk)| (format!("safe{}", user + 1), sk.address().encode_hex())) .collect(), }) .collect::>(); diff --git a/src/lib.rs b/src/lib.rs index a17b83e7..decd576b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ use crate::{ }; use flate2::read::GzDecoder; use indicatif::{ProgressBar, ProgressStyle}; -use log::debug; +use log::{debug, trace}; use semver::Version; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -1145,87 +1145,74 @@ pub fn get_progress_bar(length: u64) -> Result { progress_bar.enable_steady_tick(Duration::from_millis(100)); Ok(progress_bar) } - pub async fn get_environment_details( environment_name: &str, s3_repository: &S3Repository, ) -> Result { let temp_file = tempfile::NamedTempFile::new()?; - match s3_repository - .download_object("sn-environment-type", environment_name, temp_file.path()) - .await - { - Ok(_) => { - debug!("Downloaded the environment details file for {environment_name} from S3"); - let content = std::fs::read_to_string(temp_file.path())?; - match serde_json::from_str(&content) { - Ok(environment_details) => Ok(environment_details), - Err(_) => { - let lines: Vec<&str> = content.lines().collect(); - - let environment_type = if lines.is_empty() { - None - } else { - Some(lines[0].trim()) - }; - - let deployment_type = lines.get(1).map(|s| s.trim()); - let environment_type = match environment_type.and_then(|s| s.parse().ok()) { - Some(e) => { - debug!("Parsed the environment type from the S3 file"); - e - } - None => { - debug!("Could not parse the environment type from the S3 file"); - debug!( - "Falling back to using the environment name ({environment_name})" - ); - if environment_name.starts_with("DEV") { - debug!("Using Development as the environment type"); - EnvironmentType::Development - } else if environment_name.starts_with("STG") { - debug!("Using Staging as the environment type"); - EnvironmentType::Staging - } else if environment_name.starts_with("PROD") { - debug!("Using Production as the environment type"); - EnvironmentType::Production - } else { - return Err(Error::EnvironmentNameFromStringError( - environment_name.to_string(), - )); - } + let max_retries = 3; + let mut retries = 0; + let env_details = loop { + debug!("Downloading the environment details file for {environment_name} from S3"); + match s3_repository + .download_object("sn-environment-type", environment_name, temp_file.path()) + .await + { + Ok(_) => { + debug!("Downloaded the environment details file for {environment_name} from S3"); + let content = match std::fs::read_to_string(temp_file.path()) { + Ok(content) => content, + Err(err) => { + log::error!("Could not read the environment details file: {err:?}"); + if retries < max_retries { + debug!("Retrying to read the environment details file"); + retries += 1; + continue; + } else { + return Err(Error::EnvironmentDetailsNotFound( + environment_name.to_string(), + )); } - }; - - let deployment_type = match deployment_type.and_then(|s| s.parse().ok()) { - Some(d) => d, - None => { - debug!("Could not parse the deployment type from the S3 file"); - debug!("Using New as the default"); - DeploymentType::New + } + }; + trace!("Content of the environment details file: {}", content); + + match serde_json::from_str(&content) { + Ok(environment_details) => break environment_details, + Err(err) => { + log::error!("Could not parse the environment details file: {err:?}"); + if retries < max_retries { + debug!("Retrying to parse the environment details file"); + retries += 1; + continue; + } else { + return Err(Error::EnvironmentDetailsNotFound( + environment_name.to_string(), + )); } - }; - - Ok(EnvironmentDetails { - environment_type, - deployment_type, - evm_network: EvmNetwork::ArbitrumOne, - rewards_address: "".to_string(), - evm_testnet_data: None, - }) + } + } + } + Err(err) => { + log::error!( + "Could not download the environment details file for {environment_name} from S3: {err:?}" + ); + if retries < max_retries { + retries += 1; + continue; + } else { + return Err(Error::EnvironmentDetailsNotFound( + environment_name.to_string(), + )); } } } - Err(err) => { - log::error!( - "Could not download the environment details file for {environment_name} from S3: {err:?}" - ); - Err(Error::EnvironmentDetailsNotFound( - environment_name.to_string(), - )) - } - } + }; + + debug!("Fetched environment details: {env_details:?}"); + + Ok(env_details) } pub async fn write_environment_details( diff --git a/src/upscale.rs b/src/upscale.rs index a44159c2..c2b0797a 100644 --- a/src/upscale.rs +++ b/src/upscale.rs @@ -241,6 +241,12 @@ impl TestnetDeployer { }; debug!("Retrieved initial peer {initial_multiaddr}"); + let evm_testnet_data = options + .current_inventory + .environment_details + .evm_testnet_data + .clone(); + let should_provision_private_nodes = desired_private_node_vm_count > 0; let mut n = 1; let mut total = if is_bootstrap_deploy { 3 } else { 4 }; @@ -262,7 +268,7 @@ impl TestnetDeployer { &provision_options, &initial_multiaddr, NodeType::Bootstrap, - None, + evm_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned bootstrap nodes"); @@ -285,7 +291,7 @@ impl TestnetDeployer { &provision_options, &initial_multiaddr, NodeType::Normal, - None, + evm_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned normal nodes"); @@ -352,7 +358,7 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Uploaders"); self.ansible_provisioner - .provision_uploaders(&provision_options, &initial_multiaddr, None) + .provision_uploaders(&provision_options, &initial_multiaddr, evm_testnet_data) .await .map_err(|err| { println!("Failed to provision uploaders {err:?}");