Skip to content

Commit

Permalink
chore: revert sample peer and progress bar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Jan 23, 2024
1 parent b13065a commit 17c688e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion resources/scripts/get_peer_multiaddr.sh
Original file line number Diff line number Diff line change
@@ -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'
47 changes: 29 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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::<Result<Vec<(NodeManagerInventory, IpAddr)>>>()?
};
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::<Vec<_>>();

// 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.
Expand Down Expand Up @@ -894,7 +906,6 @@ struct NodeManagerInventory {
#[derive(Deserialize)]
struct Node {
rpc_port: u16,
peer_id: Option<String>,
}

fn get_node_manager_inventory(inventory_file_path: &PathBuf) -> Result<NodeManagerInventory> {
Expand Down

0 comments on commit 17c688e

Please sign in to comment.