Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ bincode = "1.2.0"
byteorder = "1.3.2"
derivative = "2.0.2"
env_logger = "0.7.1"
failure = "0.1.6"
hex_fmt = "0.3"
init_with = "1.1.0"
log = "0.4.8"
rand = "0.6.5"
rand = "0.7.3"
rand_derive = "0.5.0"
reed-solomon-erasure = "4.0.1"
serde = { version = "1.0.102", features = ["derive", "rc"] }
threshold_crypto = { rev = "624eeee", git = "https://github.com/poanetwork/threshold_crypto" }
thiserror = "1.0"
threshold_crypto = { rev = "a7fbfa4", git = "https://github.com/poanetwork/threshold_crypto" }
tiny-keccak = { version = "2.0.1", features = ["sha3"]}

[dev-dependencies]
Expand All @@ -44,7 +44,7 @@ docopt = "1.1.0"
hbbft_testing = { path = "hbbft_testing", features = ["use-insecure-test-only-mock-crypto"] }
itertools = "0.9.0"
number_prefix = "0.3.0"
proptest = "0.9.4"
proptest = "0.10.1"

[[example]]
name = "consensus-node"
Expand Down
2 changes: 1 addition & 1 deletion examples/network/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
let tx_from_algo = messaging.tx_from_algo();
let stop_tx = messaging.stop_tx();

let mut rng = rand::rngs::OsRng::new().unwrap();
let mut rng = rand::rngs::OsRng;

// All spawned threads will have exited by the end of the scope.
crossbeam::scope(|scope| {
Expand Down
6 changes: 4 additions & 2 deletions examples/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ struct Args {
}

/// A node identifier. In the simulation, nodes are simply numbered.
#[derive(Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, Rand)]
#[derive(
Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, Rand,
)]
pub struct NodeId(pub usize);

/// A transaction.
Expand Down Expand Up @@ -399,7 +401,7 @@ fn parse_args() -> Result<Args, docopt::Error> {

fn main() {
env_logger::init();
let mut rng = OsRng::new().expect("Could not initialize OS random number generator.");
let mut rng = OsRng;

let args = parse_args().unwrap_or_else(|e| e.exit());
if args.flag_n <= 3 * args.flag_f {
Expand Down
10 changes: 5 additions & 5 deletions hbbft_testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ edition = "2018"
travis-ci = { repository = "poanetwork/hbbft" }

[dependencies]
failure = "0.1.6"
hbbft = { path = ".." }
integer-sqrt = "0.1.2"
proptest = "0.9.4"
rand = "0.6.5"
rand_xorshift = "0.1.1"
threshold_crypto = { rev = "624eeee", git = "https://github.com/poanetwork/threshold_crypto" }
proptest = "0.10.1"
rand = "0.7.3"
rand_xorshift = "0.2.0"
thiserror = "1.0"
threshold_crypto = { rev = "a7fbfa4", git = "https://github.com/poanetwork/threshold_crypto" }

[features]
use-insecure-test-only-mock-crypto = ["hbbft/use-insecure-test-only-mock-crypto"]
15 changes: 0 additions & 15 deletions hbbft_testing/src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::fmt::{self, Debug, Display};
use std::time;

use failure;
use threshold_crypto as crypto;

use hbbft::ConsensusProtocol;
Expand Down Expand Up @@ -165,17 +164,3 @@ where
}
}
}

impl<D> failure::Fail for CrankError<D>
where
D: ConsensusProtocol + 'static,
{
fn cause(&self) -> Option<&dyn failure::Fail> {
match self {
CrankError::HandleInput(err) | CrankError::HandleInputAll(err) => Some(err),
CrankError::HandleMessage { err, .. } => Some(err),
CrankError::InitialKeyGeneration(err) => Some(err),
_ => None,
}
}
}
24 changes: 12 additions & 12 deletions src/binary_agreement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ pub mod bool_set;
mod sbv_broadcast;

use bincode;
use failure::Fail;
use rand::distributions::{Distribution, Standard};
use rand::{seq::SliceRandom, Rng};
use rand_derive::Rand;
use serde::{Deserialize, Serialize};
use thiserror::Error as ThisError;

use self::bool_set::BoolSet;
use crate::threshold_sign;
Expand All @@ -82,17 +82,17 @@ pub use self::binary_agreement::BinaryAgreement;
pub use self::sbv_broadcast::Message as SbvMessage;

/// A `BinaryAgreement` error.
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
#[derive(Clone, Eq, PartialEq, Debug, ThisError)]
pub enum Error {
/// Error handling a `ThresholdSign` message.
#[fail(display = "Error handling ThresholdSign message: {}", _0)]
#[error("Error handling ThresholdSign message: {0}")]
HandleThresholdSign(threshold_sign::Error),
/// Error invoking the common coin.
#[fail(display = "Error invoking the common coin: {}", _0)]
#[error("Error invoking the common coin: {0}")]
InvokeCoin(threshold_sign::Error),
// String because `io` and `bincode` errors lack `Eq` and `Clone`.
/// Error serializing the session ID for the common coin.
#[fail(display = "Error serializing session ID for coin: {}", _0)]
#[error("Error serializing session ID for coin: {0}")]
Serialize(String),
}

Expand All @@ -106,25 +106,25 @@ impl From<bincode::Error> for Error {
pub type Result<T> = ::std::result::Result<T, Error>;

/// A faulty Binary Agreement message received from a peer.
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `BinaryAgreement` received a duplicate `BVal` message.
#[fail(display = "`BinaryAgreement` received a duplicate `BVal` message.")]
#[error("`BinaryAgreement` received a duplicate `BVal` message.")]
DuplicateBVal,
/// `BinaryAgreement` received a duplicate `Aux` message.
#[fail(display = "`BinaryAgreement` received a duplicate `Aux` message.")]
#[error("`BinaryAgreement` received a duplicate `Aux` message.")]
DuplicateAux,
/// `BinaryAgreement` received multiple `Conf` messages.
#[fail(display = "`BinaryAgreement` received multiple `Conf` messages.")]
#[error("`BinaryAgreement` received multiple `Conf` messages.")]
MultipleConf,
/// `BinaryAgreement` received multiple `Term` messages.
#[fail(display = "`BinaryAgreement` received multiple `Term` messages.")]
#[error("`BinaryAgreement` received multiple `Term` messages.")]
MultipleTerm,
/// `BinaryAgreement` received a message with an epoch too far ahead.
#[fail(display = "`BinaryAgreement` received a message with an epoch too far ahead.")]
#[error("`BinaryAgreement` received a message with an epoch too far ahead.")]
AgreementEpoch,
/// `BinaryAgreement` received a Coin Fault.
#[fail(display = "`BinaryAgreement` received a Coin Fault.")]
#[error("`BinaryAgreement` received a Coin Fault.")]
CoinFault(threshold_sign::FaultKind),
}
/// A `BinaryAgreement` step, containing at most one output.
Expand Down
30 changes: 15 additions & 15 deletions src/broadcast/error.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
use failure::Fail;
use thiserror::Error as ThisError;

/// A broadcast error.
#[derive(Clone, PartialEq, Debug, Fail)]
#[derive(Clone, PartialEq, Debug, ThisError)]
pub enum Error {
/// Due to a limitation in `reed_solomon_erasure`, only up to 256 nodes are supported.
#[fail(display = "Number of participants must be between 1 and 256")]
#[error("Number of participants must be between 1 and 256")]
InvalidNodeCount,
/// Observers cannot propose a value.
#[fail(display = "Instance cannot propose")]
#[error("Instance cannot propose")]
InstanceCannotPropose,
/// Multiple inputs received. Only a single value can be proposed.
#[fail(display = "Multiple inputs received")]
#[error("Multiple inputs received")]
MultipleInputs,
/// Failed to construct a Merkle tree proof.
#[fail(display = "Proof construction failed")]
#[error("Proof construction failed")]
ProofConstructionFailed,
/// Unknown sender.
#[fail(display = "Unknown sender")]
#[error("Unknown sender")]
UnknownSender,
}

/// A broadcast result.
pub type Result<T> = ::std::result::Result<T, Error>;

/// Represents each reason why a broadcast message could be faulty.
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `Broadcast` received a `Value` from a node other than the proposer.
#[fail(display = "`Broadcast` received a `Value` from a node other than the proposer.")]
#[error("`Broadcast` received a `Value` from a node other than the proposer.")]
ReceivedValueFromNonProposer,
/// `Broadcast` received multiple different `Value`s from the proposer.
#[fail(display = "`Broadcast` received multiple different `Value`s from the proposer.")]
#[error("`Broadcast` received multiple different `Value`s from the proposer.")]
MultipleValues,
/// `Broadcast` received multiple different `Echo`s from the same sender.
#[fail(display = "`Broadcast` received multiple different `Echo`s from the same sender.")]
#[error("`Broadcast` received multiple different `Echo`s from the same sender.")]
MultipleEchos,
/// `Broadcast` received multiple different `EchoHash`s from the same sender.
#[fail(display = "`Broadcast` received multiple different `EchoHash`s from the same sender.")]
#[error("`Broadcast` received multiple different `EchoHash`s from the same sender.")]
MultipleEchoHashes,
/// `Broadcast` received multiple different `Ready`s from the same sender.
#[fail(display = "`Broadcast` received multiple different `Ready`s from the same sender.")]
#[error("`Broadcast` received multiple different `Ready`s from the same sender.")]
MultipleReadys,
/// `Broadcast` recevied an Echo message containing an invalid proof.
#[fail(display = "`Broadcast` recevied an Echo message containing an invalid proof.")]
#[error("`Broadcast` recevied an Echo message containing an invalid proof.")]
InvalidProof,
///`Broadcast` received shards with valid proofs, that couldn't be decoded.
#[fail(display = "`Broadcast` received shards with valid proofs, that couldn't be decoded.")]
#[error("`Broadcast` received shards with valid proofs, that couldn't be decoded.")]
BroadcastDecoding,
}
2 changes: 1 addition & 1 deletion src/broadcast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
//! const NUM_NODES: u64 = 7;
//! const PROPOSER_ID: u64 = 3;
//!
//! let mut rng = OsRng::new().expect("Could not initialize OS random number generator.");
//! let mut rng = OsRng;
//!
//! let validators = Arc::new(ValidatorSet::from(0..NUM_NODES));
//!
Expand Down
60 changes: 26 additions & 34 deletions src/dynamic_honey_badger/error.rs
Original file line number Diff line number Diff line change
@@ -1,96 +1,88 @@
use bincode;
use failure::Fail;
use thiserror::Error as ThisError;

use crate::honey_badger;
use crate::sync_key_gen;

/// Dynamic honey badger error variants.
#[derive(Debug, Fail)]
#[derive(Debug, ThisError)]
pub enum Error {
/// Failed to serialize a key generation message for signing.
#[fail(display = "Error serializing a key gen message: {}", _0)]
#[error("Error serializing a key gen message: {0}")]
SerializeKeyGen(bincode::ErrorKind),
/// Failed to serialize a vote for signing.
#[fail(display = "Error serializing a vote: {}", _0)]
#[error("Error serializing a vote: {0}")]
SerializeVote(bincode::ErrorKind),
/// Failed to propose a contribution in `HoneyBadger`.
#[fail(display = "Error proposing a contribution in HoneyBadger: {}", _0)]
#[error("Error proposing a contribution in HoneyBadger: {0}")]
ProposeHoneyBadger(honey_badger::Error),
/// Failed to handle a `HoneyBadger` message.
#[fail(display = "Error handling a HoneyBadger message: {}", _0)]
#[error("Error handling a HoneyBadger message: {0}")]
HandleHoneyBadgerMessage(honey_badger::Error),
/// Failed to handle a `SyncKeyGen` message.
#[fail(display = "Error handling SyncKeyGen message: {}", _0)]
#[error("Error handling SyncKeyGen message: {0}")]
SyncKeyGen(sync_key_gen::Error),
/// The join plan contains contradictory information.
#[fail(display = "Invalid Join Plan")]
#[error("Invalid Join Plan")]
InvalidJoinPlan,
/// Unknown sender
#[fail(display = "Unknown sender")]
#[error("Unknown sender")]
UnknownSender,
}

/// The result of `DynamicHoneyBadger` handling an input or message.
pub type Result<T> = ::std::result::Result<T, Error>;
/// Represents each way an an incoming message can be considered faulty.
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `DynamicHoneyBadger` received a key generation message with an invalid signature.
#[fail(
display = "`DynamicHoneyBadger` received a key generation message with an invalid signature."
)]
#[error("`DynamicHoneyBadger` received a key generation message with an invalid signature.")]
InvalidKeyGenMessageSignature,
/// `DynamicHoneyBadger` received a key generation message with an invalid era.
#[fail(
display = "`DynamicHoneyBadger` received a key generation message with an invalid era."
)]
#[error("`DynamicHoneyBadger` received a key generation message with an invalid era.")]
InvalidKeyGenMessageEra,
/// `DynamicHoneyBadger` received a key generation message when there was no key generation in
/// progress.
#[fail(
display = "`DynamicHoneyBadger` received a key generation message when there was no key
#[error(
"`DynamicHoneyBadger` received a key generation message when there was no key
generation in progress."
)]
UnexpectedKeyGenMessage,
/// `DynamicHoneyBadger` received a signed `Ack` when no key generation in progress.
#[fail(
display = "`DynamicHoneyBadger` received a signed `Ack` when no key generation in progress."
)]
#[error("`DynamicHoneyBadger` received a signed `Ack` when no key generation in progress.")]
UnexpectedKeyGenAck,
/// `DynamicHoneyBadger` received a signed `Part` when no key generation in progress.
#[fail(
display = "`DynamicHoneyBadger` received a signed `Part` when no key generation in progress."
)]
#[error("`DynamicHoneyBadger` received a signed `Part` when no key generation in progress.")]
UnexpectedKeyGenPart,
/// `DynamicHoneyBadger` received more key generation messages from the peer than expected.
#[fail(
display = "`DynamicHoneyBadger` received more key generation messages from the peer than
#[error(
"`DynamicHoneyBadger` received more key generation messages from the peer than
expected."
)]
TooManyKeyGenMessages,
/// `DynamicHoneyBadger` received a message (Accept, Propose, or Change with an invalid
/// signature.
#[fail(
display = "`DynamicHoneyBadger` received a message (Accept, Propose, or Change
#[error(
"`DynamicHoneyBadger` received a message (Accept, Propose, or Change
with an invalid signature."
)]
IncorrectPayloadSignature,
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Ack` message.
#[fail(display = "`DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Ack` message.")]
#[error("`DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Ack` message.")]
SyncKeyGenAck(sync_key_gen::AckFault),
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Part` message.
#[fail(display = "`DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Part` message.")]
#[error("`DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Part` message.")]
SyncKeyGenPart(sync_key_gen::PartFault),
/// `DynamicHoneyBadger` received a change vote with an invalid signature.
#[fail(display = "`DynamicHoneyBadger` received a change vote with an invalid signature.")]
#[error("`DynamicHoneyBadger` received a change vote with an invalid signature.")]
InvalidVoteSignature,
/// A validator committed an invalid vote in `DynamicHoneyBadger`.
#[fail(display = "A validator committed an invalid vote in `DynamicHoneyBadger`.")]
#[error("A validator committed an invalid vote in `DynamicHoneyBadger`.")]
InvalidCommittedVote,
/// `DynamicHoneyBadger` received a message with an invalid era.
#[fail(display = "`DynamicHoneyBadger` received a message with an invalid era.")]
#[error("`DynamicHoneyBadger` received a message with an invalid era.")]
UnexpectedDhbMessageEra,
/// `DynamicHoneyBadger` received a fault from `HoneyBadger`.
#[fail(display = "`DynamicHoneyBadger` received a fault from `HoneyBadger`.")]
#[error("`DynamicHoneyBadger` received a fault from `HoneyBadger`.")]
HbFault(honey_badger::FaultKind),
}
2 changes: 1 addition & 1 deletion src/dynamic_honey_badger/votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod tests {
/// the vote by node `i` for making `j` the only validator. Each node signed this for nodes
/// `0`, `1`, ... in order.
fn setup(node_num: usize, era: u64) -> (Vec<VoteCounter<usize>>, Vec<Vec<SignedVote<usize>>>) {
let mut rng = rngs::OsRng::new().expect("could not initialize OsRng");
let mut rng = rngs::OsRng;

// Generate keys for signing and encrypting messages.
let sec_keys: BTreeMap<_, SecretKey> = (0..node_num).map(|id| (id, rng.gen())).collect();
Expand Down
Loading