From 17c688e0cc310356a7b3ae9546a030b21fb81374 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Tue, 23 Jan 2024 20:30:57 +0530 Subject: [PATCH] chore: revert sample peer and progress bar changes --- resources/scripts/get_peer_multiaddr.sh | 2 +- src/lib.rs | 47 +++++++++++++++---------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/resources/scripts/get_peer_multiaddr.sh b/resources/scripts/get_peer_multiaddr.sh index e86b4346..f589c9e2 100644 --- a/resources/scripts/get_peer_multiaddr.sh +++ b/resources/scripts/get_peer_multiaddr.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -rg "is listening on " ~/.local/share/safe/node | \ +rg "is listening on " /var/log/safenode/ | \ rg -v "ip4/10." | rg -v "ip4/127." | sort -k1.90,1.119 | head -n +1 | \ sed -n 's/.*"\(.*\)".*/\1/p' diff --git a/src/lib.rs b/src/lib.rs index 91220e68..d9057b20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -527,8 +527,6 @@ impl TestnetDeploy { let (genesis_multiaddr, genesis_ip) = self.get_genesis_multiaddr(name).await?; println!("Retrieving node manager inventory. This can take a minute."); - let node_manager_inv_progress = - get_progress_bar(remaining_nodes_inventory.len() as u64 + 1)?; // Get peer ids and rpc addr from node manager inventory file let node_manager_inventories = { @@ -588,35 +586,49 @@ impl TestnetDeploy { manager_inventory_files .par_iter() - .flat_map(|(file_path, ip_addr)| { - let res = match get_node_manager_inventory(file_path) { + .flat_map( + |(file_path, ip_addr)| match get_node_manager_inventory(file_path) { Ok(inventory) => vec![Ok((inventory, *ip_addr))], Err(err) => vec![Err(err)], - }; - node_manager_inv_progress.inc(1); - res - }) + }, + ) .collect::>>()? }; - node_manager_inv_progress.finish_and_clear(); let mut rpc_endpoints = Vec::new(); - let mut peers = Vec::new(); - for (node_manager_inventory, ip_addr) in node_manager_inventories { let vm_rpc_ports = node_manager_inventory .nodes .iter() .map(|node| SocketAddr::new(ip_addr, node.rpc_port)); rpc_endpoints.extend(vm_rpc_ports); - - let vm_peers = node_manager_inventory - .nodes - .into_iter() - .filter_map(|node| node.peer_id); - peers.extend(vm_peers); } + // The scripts are relative to the `resources` directory, so we need to change the current + // working directory back to that location first. + std::env::set_current_dir(self.working_directory_path.clone())?; + println!("Retrieving sample peers. This can take a minute."); + // Todo: RPC into nodes to fetch the multiaddr. + let peers = remaining_nodes_inventory + .par_iter() + .filter_map(|(vm_name, ip_address)| { + let ip_address = *ip_address; + match self.ssh_client.run_script( + ip_address, + "safe", + PathBuf::from("scripts").join("get_peer_multiaddr.sh"), + true, + ) { + Ok(output) => Some(output), + Err(err) => { + println!("Failed to SSH into {vm_name:?}: {ip_address} with err: {err:?}"); + None + } + } + }) + .flatten() + .collect::>(); + // The VM list includes the genesis node and the build machine, hence the subtraction of 2 // from the total VM count. After that, add one node for genesis, since this machine only // runs a single node. @@ -894,7 +906,6 @@ struct NodeManagerInventory { #[derive(Deserialize)] struct Node { rpc_port: u16, - peer_id: Option, } fn get_node_manager_inventory(inventory_file_path: &PathBuf) -> Result {