mirror of https://github.com/poanetwork/hbbft.git
Replace HexBytes with the hex_fmt crate.
This commit is contained in:
parent
b5acac439c
commit
7345132066
|
@ -22,6 +22,7 @@ bincode = "1.0.0"
|
|||
byteorder = "1.2.3"
|
||||
env_logger = "0.5.10"
|
||||
failure = "0.1"
|
||||
hex_fmt = "0.1"
|
||||
init_with = "1.1.0"
|
||||
log = "0.4.1"
|
||||
pairing = { version = "0.14.2", features = ["u128-support"] }
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::fmt::{self, Debug};
|
|||
use std::sync::Arc;
|
||||
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use hex_fmt::{HexFmt, HexList};
|
||||
use rand;
|
||||
use reed_solomon_erasure as rse;
|
||||
use reed_solomon_erasure::ReedSolomon;
|
||||
|
@ -10,7 +11,6 @@ use reed_solomon_erasure::ReedSolomon;
|
|||
use super::merkle::{Digest, MerkleTree, Proof};
|
||||
use super::{Error, Result};
|
||||
use fault_log::{Fault, FaultKind};
|
||||
use fmt::{HexBytes, HexList, HexProof};
|
||||
use {DistAlgorithm, NetworkInfo, NodeIdT, Target};
|
||||
|
||||
/// The three kinds of message sent during the reliable broadcast stage of the
|
||||
|
@ -50,7 +50,7 @@ impl Debug for Message {
|
|||
match *self {
|
||||
Message::Value(ref v) => f.debug_tuple("Value").field(&HexProof(v)).finish(),
|
||||
Message::Echo(ref v) => f.debug_tuple("Echo").field(&HexProof(v)).finish(),
|
||||
Message::Ready(ref b) => f.debug_tuple("Ready").field(&HexBytes(b)).finish(),
|
||||
Message::Ready(ref b) => f.debug_tuple("Ready").field(&HexFmt(b)).finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -502,6 +502,21 @@ fn glue_shards(m: MerkleTree<Vec<u8>>, n: usize) -> Option<Vec<u8>> {
|
|||
_ => return None, // The proposing node is faulty: no payload size.
|
||||
};
|
||||
let payload: Vec<u8> = bytes.take(payload_len).collect();
|
||||
debug!("Glued data shards {:?}", HexBytes(&payload));
|
||||
debug!("Glued data shards {:?}", HexFmt(&payload));
|
||||
Some(payload)
|
||||
}
|
||||
|
||||
/// Wrapper for a `Proof`, to print the bytes as a shortened hexadecimal number.
|
||||
struct HexProof<'a, T: 'a>(pub &'a Proof<T>);
|
||||
|
||||
impl<'a, T: AsRef<[u8]>> fmt::Debug for HexProof<'a, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Proof {{ #{}, root_hash: {:?}, value: {:?}, .. }}",
|
||||
&self.0.index(),
|
||||
HexFmt(self.0.root_hash()),
|
||||
HexFmt(self.0.value())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
49
src/fmt.rs
49
src/fmt.rs
|
@ -1,49 +0,0 @@
|
|||
use broadcast::merkle::Proof;
|
||||
use std::fmt;
|
||||
|
||||
/// Wrapper for a byte array, whose `Debug` implementation outputs shortened hexadecimal strings.
|
||||
pub struct HexBytes<'a>(pub &'a [u8]);
|
||||
|
||||
impl<'a> fmt::Debug for HexBytes<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.0.len() > 6 {
|
||||
for byte in &self.0[..3] {
|
||||
write!(f, "{:02x}", byte)?;
|
||||
}
|
||||
write!(f, "..")?;
|
||||
for byte in &self.0[(self.0.len() - 3)..] {
|
||||
write!(f, "{:02x}", byte)?;
|
||||
}
|
||||
} else {
|
||||
for byte in self.0 {
|
||||
write!(f, "{:02x}", byte)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper for a list of byte arrays, whose `Debug` implementation outputs shortened hexadecimal
|
||||
/// strings.
|
||||
pub struct HexList<'a, T: 'a>(pub &'a [T]);
|
||||
|
||||
impl<'a, T: AsRef<[u8]>> fmt::Debug for HexList<'a, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let v: Vec<_> = self.0.iter().map(|t| HexBytes(t.as_ref())).collect();
|
||||
v.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HexProof<'a, T: 'a>(pub &'a Proof<T>);
|
||||
|
||||
impl<'a, T: AsRef<[u8]>> fmt::Debug for HexProof<'a, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Proof {{ #{}, root_hash: {:?}, value: {:?}, .. }}",
|
||||
&self.0.index(),
|
||||
HexBytes(self.0.root_hash().as_ref()),
|
||||
HexBytes(self.0.value().as_ref())
|
||||
)
|
||||
}
|
||||
}
|
|
@ -122,6 +122,7 @@ extern crate bincode;
|
|||
extern crate byteorder;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
extern crate hex_fmt;
|
||||
extern crate init_with;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -141,7 +142,6 @@ pub mod broadcast;
|
|||
pub mod coin;
|
||||
pub mod dynamic_honey_badger;
|
||||
pub mod fault_log;
|
||||
mod fmt;
|
||||
pub mod honey_badger;
|
||||
mod messaging;
|
||||
mod network_info;
|
||||
|
|
|
@ -27,9 +27,10 @@ use std::collections::{BTreeMap, BTreeSet};
|
|||
use std::result;
|
||||
use std::sync::Arc;
|
||||
|
||||
use hex_fmt::HexFmt;
|
||||
|
||||
use binary_agreement::{self, BinaryAgreement};
|
||||
use broadcast::{self, Broadcast};
|
||||
use fmt::HexBytes;
|
||||
use rand::Rand;
|
||||
use {DistAlgorithm, NetworkInfo, NodeIdT};
|
||||
|
||||
|
@ -94,11 +95,7 @@ impl<N: NodeIdT + Rand> DistAlgorithm for Subset<N> {
|
|||
type Error = Error;
|
||||
|
||||
fn handle_input(&mut self, input: Self::Input) -> Result<Step<N>> {
|
||||
debug!(
|
||||
"{:?} Proposing {:?}",
|
||||
self.netinfo.our_id(),
|
||||
HexBytes(&input)
|
||||
);
|
||||
debug!("{:?} Proposing {:?}", self.netinfo.our_id(), HexFmt(&input));
|
||||
self.send_proposed_value(input)
|
||||
}
|
||||
|
||||
|
@ -228,7 +225,7 @@ impl<N: NodeIdT + Rand> Subset<N> {
|
|||
};
|
||||
|
||||
let val_to_insert = if let Some(true) = self.ba_results.get(proposer_id) {
|
||||
debug!(" {:?} → {:?}", proposer_id, HexBytes(&value));
|
||||
debug!(" {:?} → {:?}", proposer_id, HexFmt(&value));
|
||||
step.output
|
||||
.extend(Some(SubsetOutput::Contribution(proposer_id.clone(), value)));
|
||||
None
|
||||
|
@ -316,7 +313,7 @@ impl<N: NodeIdT + Rand> Subset<N> {
|
|||
}
|
||||
}
|
||||
if let Some(Some(value)) = self.broadcast_results.insert(proposer_id.clone(), None) {
|
||||
debug!(" {:?} → {:?}", proposer_id, HexBytes(&value));
|
||||
debug!(" {:?} → {:?}", proposer_id, HexFmt(&value));
|
||||
step.output
|
||||
.extend(Some(SubsetOutput::Contribution(proposer_id.clone(), value)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue