Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: revert sample peer and progress bar changes #65

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
59 changes: 36 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl DeploymentInventory {
random_peer.to_string()
}

pub fn print_report(&self) {
pub fn print_report(&self) -> Result<()> {
println!("**************************************");
println!("* *");
println!("* Inventory Report *");
Expand Down Expand Up @@ -168,12 +168,13 @@ impl DeploymentInventory {
println!("{}: {}", vm.0, vm.1);
}
println!("SSH user: {}", self.ssh_user);
println!("Sample Peers");
let testnet_dir = get_data_directory()?;
println!("Sample Peers (Entire list can be found inside {testnet_dir:?})",);
println!("============");
for peer in self.peers.iter().take(10) {
println!("{peer}");
}
println!("Genesis multiaddr: {}", self.genesis_multiaddr);
println!("\nGenesis multiaddr: {}", self.genesis_multiaddr);
println!("Faucet address: {}", self.faucet_address);
println!("Check the faucet:");
println!(
Expand All @@ -187,6 +188,7 @@ impl DeploymentInventory {
println!("{}: {}", file.0, file.1);
}
}
Ok(())
}
}

Expand Down Expand Up @@ -466,7 +468,7 @@ impl TestnetDeploy {
let inventory_path = get_data_directory()?.join(format!("{name}-inventory.json"));
if inventory_path.exists() && !force_regeneration {
let inventory = DeploymentInventory::read(&inventory_path)?;
inventory.print_report();
inventory.print_report()?;
return Ok(());
}

Expand Down Expand Up @@ -527,8 +529,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 +588,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 All @@ -634,7 +648,7 @@ impl TestnetDeploy {
faucet_address: format!("{}:8000", genesis_ip),
uploaded_files: Vec::new(),
};
inventory.print_report();
inventory.print_report()?;
inventory.save(&inventory_path)?;

Ok(())
Expand Down Expand Up @@ -894,7 +908,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
Loading