-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
10 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:?}",); | ||
} | ||
} | ||
} |