Improve example logging, add BinaryPath.

This commit is contained in:
Andreas Fackler 2018-05-09 13:38:41 +02:00
parent b98bbe9dcd
commit c790a1feba
3 changed files with 31 additions and 8 deletions

View File

@ -39,7 +39,7 @@ use std::collections::HashSet;
use std::fmt::Debug; use std::fmt::Debug;
use std::marker::{Send, Sync}; use std::marker::{Send, Sync};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::{io, iter, process}; use std::{io, iter, process, thread, time};
use hbbft::broadcast; use hbbft::broadcast;
use network::commst; use network::commst;
@ -131,8 +131,9 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
).run() ).run()
{ {
Ok(t) => { Ok(t) => {
debug!( println!(
"Broadcast succeeded: {}", "Broadcast succeeded! Node {} output: {}",
our_id,
String::from_utf8(T::into(t)).unwrap() String::from_utf8(T::into(t)).unwrap()
); );
} }
@ -167,6 +168,9 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
// messaging task. // messaging task.
broadcast_handle.join(); broadcast_handle.join();
// Wait another second so that pending messages get sent out.
thread::sleep(time::Duration::from_secs(1));
// Stop the messaging task. // Stop the messaging task.
stop_tx stop_tx
.send(()) .send(())

View File

@ -1,5 +1,7 @@
#! /bin/bash #! /bin/bash
export RUST_LOG=hbbft=debug
cargo build --example consensus-node cargo build --example consensus-node
cargo run --example consensus-node -- --bind-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5002 --remote-address=127.0.0.1:5003 --value=Foo & cargo run --example consensus-node -- --bind-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5002 --remote-address=127.0.0.1:5003 --value=Foo &
sleep 1 sleep 1
@ -8,3 +10,4 @@ sleep 1
cargo run --example consensus-node -- --bind-address=127.0.0.1:5002 --remote-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5003 & cargo run --example consensus-node -- --bind-address=127.0.0.1:5002 --remote-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5003 &
sleep 1 sleep 1
cargo run --example consensus-node -- --bind-address=127.0.0.1:5003 --remote-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5002 & cargo run --example consensus-node -- --bind-address=127.0.0.1:5003 --remote-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5002 &
wait

View File

@ -299,18 +299,34 @@ impl LemmaProto {
} }
} }
/// The path of a lemma in a Merkle tree
struct BinaryPath(Vec<bool>);
/// The path of the lemma, as a binary string /// The path of the lemma, as a binary string
fn path_of_lemma(mut lemma: &Lemma) -> String { fn path_of_lemma(mut lemma: &Lemma) -> BinaryPath {
let mut result = String::new(); let mut result = Vec::new();
loop { loop {
match lemma.sibling_hash { match lemma.sibling_hash {
None => (), None => (),
Some(Positioned::Left(_)) => result.push('1'), Some(Positioned::Left(_)) => result.push(true),
Some(Positioned::Right(_)) => result.push('0'), Some(Positioned::Right(_)) => result.push(false),
} }
lemma = match lemma.sub_lemma.as_ref() { lemma = match lemma.sub_lemma.as_ref() {
Some(lemma) => lemma, Some(lemma) => lemma,
None => return result, None => return BinaryPath(result),
} }
} }
} }
impl fmt::Display for BinaryPath {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for b in &self.0 {
if *b {
write!(f, "1")?;
} else {
write!(f, "0")?;
}
}
Ok(())
}
}