Skip to content

Commit

Permalink
Change CLI to use gossip layer
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Feb 26, 2024
1 parent d12bf3c commit 59c80ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 44 deletions.
17 changes: 0 additions & 17 deletions code/node/bin/cli.rs

This file was deleted.

37 changes: 10 additions & 27 deletions code/node/bin/main.rs
Original file line number Diff line number Diff line change
@@ -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:?}",);
}
}
}

0 comments on commit 59c80ed

Please sign in to comment.