Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
chore: respond to feedback
Browse files Browse the repository at this point in the history
* Use clap to provide default node count
* Mark `join` arguments as conflicting
* Fix bug with single node on join
* Use `find_map` rather than `find` to eliminate additional step
  • Loading branch information
jacderida committed Jan 10, 2024
1 parent f8d9431 commit 6555e59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use std::process::{Command, Stdio};
use std::str::FromStr;
use sysinfo::{Pid, ProcessExt, System, SystemExt};

const DEFAULT_NODE_COUNT: u16 = 25;

#[cfg_attr(test, automock)]
pub trait Launcher {
fn get_safenode_path(&self) -> PathBuf;
Expand Down Expand Up @@ -159,7 +157,7 @@ pub fn kill_network(node_registry: &NodeRegistry, keep_directories: bool) -> Res
pub struct LocalNetworkOptions {
pub faucet_bin_path: PathBuf,
pub join: bool,
pub node_count: Option<u16>,
pub node_count: u16,
pub peers: Option<Vec<Multiaddr>>,
pub safenode_bin_path: PathBuf,
pub skip_validation: bool,
Expand All @@ -175,16 +173,16 @@ pub async fn run_network(
faucet_bin_path: network_options.faucet_bin_path.to_path_buf(),
};

let peers = if network_options.join {
let (peers, start) = if network_options.join {
if let Some(peers) = network_options.peers {
peers
(peers, 1)
} else {
let peer = node_registry
.nodes
.iter()
.find(|n| n.get_multiaddr().is_some())
.find_map(|n| n.get_multiaddr())
.ok_or_else(|| eyre!("Unable to obtain a peer to connect to"))?;
vec![peer.get_multiaddr().unwrap()]
(vec![peer], 1)
}
} else {
let port = service_control.get_available_port()?;
Expand All @@ -199,10 +197,10 @@ pub async fn run_network(
&rpc_client,
)
.await?;
vec![genesis_multiaddr]
(vec![genesis_multiaddr], 2)
};

for _ in 2..=network_options.node_count.unwrap_or(DEFAULT_NODE_COUNT) {
for _ in start..=network_options.node_count {
let port = service_control.get_available_port()?;
let rpc_port = service_control.get_available_port()?;
let rpc_client = RpcClient::new(&format!("https://127.0.0.1:{rpc_port}"));
Expand Down
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use sn_releases::{ReleaseType, SafeReleaseRepositoryInterface};
use std::path::PathBuf;
use std::str::FromStr;

const DEFAULT_NODE_COUNT: u16 = 25;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub(crate) struct Cmd {
Expand Down Expand Up @@ -123,12 +125,12 @@ pub enum SubCmd {
#[clap(name = "join")]
Join {
/// The number of nodes to run.
#[clap(long)]
count: Option<u16>,
#[clap(long, default_value_t = DEFAULT_NODE_COUNT)]
count: u16,
/// Path to a faucet binary
///
/// The path and version arguments are mutually exclusive.
#[clap(long)]
#[clap(long, conflicts_with = "faucet_version")]
faucet_path: Option<PathBuf>,
/// The version of the faucet to use.
///
Expand All @@ -138,7 +140,7 @@ pub enum SubCmd {
/// Path to a safenode binary
///
/// The path and version arguments are mutually exclusive.
#[clap(long)]
#[clap(long, conflicts_with = "faucet_version")]
node_path: Option<PathBuf>,
/// The version of safenode to use.
///
Expand Down Expand Up @@ -178,8 +180,8 @@ pub enum SubCmd {
#[clap(name = "run")]
Run {
/// The number of nodes to run.
#[clap(long)]
count: Option<u16>,
#[clap(long, default_value_t = DEFAULT_NODE_COUNT)]
count: u16,
/// Path to a faucet binary
///
/// The path and version arguments are mutually exclusive.
Expand Down

0 comments on commit 6555e59

Please sign in to comment.