From 59c80ed6bf57e5e61938d611c4bbeb1637cc29f4 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Mon, 26 Feb 2024 17:45:11 +0100 Subject: [PATCH] Change CLI to use gossip layer --- code/node/bin/cli.rs | 17 ----------------- code/node/bin/main.rs | 37 ++++++++++--------------------------- 2 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 code/node/bin/cli.rs diff --git a/code/node/bin/cli.rs b/code/node/bin/cli.rs deleted file mode 100644 index 919dab5c2..000000000 --- a/code/node/bin/cli.rs +++ /dev/null @@ -1,17 +0,0 @@ -use malachite_node::network::PeerId; - -pub struct Cli { - pub peer_id: PeerId, -} - -impl Cli { - pub fn from_env() -> Self { - let peer_id = std::env::args() - .nth(1) - .expect("Usage: node ") - .parse() - .expect("Error: Invalid PEER_ID"); - - Self { peer_id } - } -} diff --git a/code/node/bin/main.rs b/code/node/bin/main.rs index b5daceeef..4158c0e52 100644 --- a/code/node/bin/main.rs +++ b/code/node/bin/main.rs @@ -1,54 +1,37 @@ -use malachite_node::util::make_broadcast_node; -use malachite_node::util::make_config; +use malachite_node::util::make_gossip_node; use malachite_test::utils::make_validators; use malachite_test::ValidatorSet; use tracing::info; -mod cli; -use cli::Cli; - const VOTING_POWERS: [u64; 3] = [5, 20, 10]; #[tokio::main(flavor = "current_thread")] pub async fn main() { tracing_subscriber::fmt::init(); - let args = Cli::from_env(); + let index: usize = std::env::args() + .nth(1) + .expect("Error: missing index") + .parse() + .expect("Error: invalid index"); // Validators keys are deterministic and match the ones in the config file let vs = make_validators(VOTING_POWERS); - let config = make_config(vs.iter().map(|(v, _)| v)); - - let peer_config = config - .peers - .iter() - .find(|p| p.id == args.peer_id) - .expect("Error: invalid peer id"); - - let (my_sk, my_addr) = vs - .iter() - .find(|(v, _)| v.public_key == peer_config.public_key) - .map(|(v, pk)| (pk.clone(), v.address)) - .expect("Error: invalid peer id"); + let (val, sk) = vs[index].clone(); let (vs, _): (Vec<_>, Vec<_>) = vs.into_iter().unzip(); - - let peer_info = peer_config.peer_info(); let vs = ValidatorSet::new(vs); - let node = make_broadcast_node(vs, my_sk, my_addr, peer_info, config.into()).await; + let node = make_gossip_node(vs, sk, val.address).await; - info!("[{}] Starting...", args.peer_id); + info!("[{index}] Starting..."); let mut handle = node.run().await; loop { if let Some((height, round, value)) = handle.wait_decision().await { - info!( - "[{}] Decision at height {height} and round {round}: {value:?}", - args.peer_id - ); + info!("[{index}] Decision at height {height} and round {round}: {value:?}",); } } }