Replaced failure (which is deprecated) with thiserror

This commit is contained in:
David Forstenlechner 2024-01-06 19:49:24 +01:00
parent 40c43ea693
commit 9abc053c77
16 changed files with 165 additions and 186 deletions

View File

@ -25,7 +25,6 @@ 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"
@ -33,6 +32,7 @@ rand = "0.7.3"
rand_derive = "0.5.0"
reed-solomon-erasure = "4.0.1"
serde = { version = "1.0.102", features = ["derive", "rc"] }
thiserror = "1.0"
threshold_crypto = { rev = "a7fbfa4", git = "https://github.com/poanetwork/threshold_crypto" }
tiny-keccak = { version = "2.0.1", features = ["sha3"]}

View File

@ -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.

View File

@ -22,12 +22,12 @@ edition = "2018"
travis-ci = { repository = "poanetwork/hbbft" }
[dependencies]
failure = "0.1.6"
hbbft = { path = ".." }
integer-sqrt = "0.1.2"
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]

View File

@ -3,7 +3,6 @@
use std::fmt::{self, Debug, Display};
use std::time;
use failure;
use threshold_crypto as crypto;
use hbbft::ConsensusProtocol;
@ -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,
}
}
}

View File

@ -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;
@ -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),
}
@ -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.

View File

@ -1,22 +1,22 @@
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,
}
@ -24,27 +24,27 @@ pub enum Error {
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,
}

View File

@ -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),
}

View File

@ -4,13 +4,13 @@
//! Each algorithm can propagate their faulty node logs upwards to a calling algorithm via
//! `ConsensusProtocol`'s `.handle_input()` and `.handle_message()` trait methods.
pub use failure::Fail;
use std::error::Error as StdError;
/// A structure representing the context of a faulty node. This structure
/// describes which node is faulty (`node_id`) and which faulty behavior
/// that the node exhibited (`kind`).
#[derive(Clone, Debug, PartialEq)]
pub struct Fault<N, F: Fail> {
pub struct Fault<N, F: StdError> {
/// The faulty node's ID.
pub node_id: N,
/// The kind of fault the node is blamed for.
@ -19,7 +19,7 @@ pub struct Fault<N, F: Fail> {
impl<N, F> Fault<N, F>
where
F: Fail,
F: StdError,
{
/// Creates a new fault, blaming `node_id` for the `kind`.
pub fn new(node_id: N, kind: F) -> Self {
@ -29,7 +29,7 @@ where
/// Applies `f_fault` to `kind`, leaves `node_id` unchanged
pub fn map<F2, FF>(self, f_fault: FF) -> Fault<N, F2>
where
F2: Fail,
F2: StdError,
FF: FnOnce(F) -> F2,
{
Fault {
@ -43,7 +43,7 @@ where
/// vector.
impl<N, F> Into<FaultLog<N, F>> for Fault<N, F>
where
F: Fail,
F: StdError,
{
fn into(self) -> FaultLog<N, F> {
FaultLog(vec![self])
@ -52,11 +52,11 @@ where
/// A structure used to contain reports of faulty node behavior.
#[derive(Debug, PartialEq)]
pub struct FaultLog<N, F: Fail>(pub Vec<Fault<N, F>>);
pub struct FaultLog<N, F: StdError>(pub Vec<Fault<N, F>>);
impl<N, F> FaultLog<N, F>
where
F: Fail,
F: StdError,
{
/// Creates an empty `FaultLog`.
pub fn new() -> Self {
@ -96,7 +96,7 @@ where
/// Applies `f_fault` to each element in log, modifying its `kind` only
pub fn map<F2, FF>(self, mut f_fault: FF) -> FaultLog<N, F2>
where
F2: Fail,
F2: StdError,
FF: FnMut(F) -> F2,
{
FaultLog(self.into_iter().map(|f| f.map(&mut f_fault)).collect())
@ -105,7 +105,7 @@ where
impl<N, F> Default for FaultLog<N, F>
where
F: Fail,
F: StdError,
{
fn default() -> Self {
FaultLog(vec![])
@ -114,7 +114,7 @@ where
impl<N, F> IntoIterator for FaultLog<N, F>
where
F: Fail,
F: StdError,
{
type Item = Fault<N, F>;
type IntoIter = std::vec::IntoIter<Fault<N, F>>;
@ -126,7 +126,7 @@ where
impl<N, F> std::iter::FromIterator<Fault<N, F>> for FaultLog<N, F>
where
F: Fail,
F: StdError,
{
fn from_iter<I: IntoIterator<Item = Fault<N, F>>>(iter: I) -> Self {
let mut log = FaultLog::new();

View File

@ -1,30 +1,30 @@
use bincode;
use failure::Fail;
use thiserror::Error as ThisError;
use crate::fault_log;
use crate::subset;
use crate::threshold_decrypt;
/// Honey badger error variants.
#[derive(Debug, Fail)]
#[derive(Debug, ThisError)]
pub enum Error {
/// Failed to serialize contribution.
#[fail(display = "Error serializing contribution: {}", _0)]
#[error("Error serializing contribution: {0}")]
ProposeBincode(bincode::ErrorKind),
/// Failed to instantiate `Subset`.
#[fail(display = "Failed to instantiate Subset: {}", _0)]
#[error("Failed to instantiate Subset: {0}")]
CreateSubset(subset::Error),
/// Failed to input contribution to `Subset`.
#[fail(display = "Failed to input contribution to Subset: {}", _0)]
#[error("Failed to input contribution to Subset: {0}")]
InputSubset(subset::Error),
/// Failed to handle `Subset` message.
#[fail(display = "Failed to handle Subset message: {}", _0)]
#[error("Failed to handle Subset message: {0}")]
HandleSubsetMessage(subset::Error),
/// Failed to decrypt a contribution.
#[fail(display = "Threshold decryption error: {}", _0)]
#[error("Threshold decryption error: {0}")]
ThresholdDecrypt(threshold_decrypt::Error),
/// Unknown sender
#[fail(display = "Unknown sender")]
#[error("Unknown sender")]
UnknownSender,
}
@ -32,32 +32,32 @@ pub enum Error {
pub type Result<T> = ::std::result::Result<T, Error>;
/// Faults detectable from receiving honey badger messages
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `HoneyBadger` received a decryption share for an unaccepted proposer.
#[fail(display = "`HoneyBadger` received a decryption share for an unaccepted proposer.")]
#[error("`HoneyBadger` received a decryption share for an unaccepted proposer.")]
UnexpectedDecryptionShare,
/// `HoneyBadger` was unable to deserialize a proposer's ciphertext.
#[fail(display = "`HoneyBadger` was unable to deserialize a proposer's ciphertext.")]
#[error("`HoneyBadger` was unable to deserialize a proposer's ciphertext.")]
DeserializeCiphertext,
/// `HoneyBadger` received an invalid ciphertext from the proposer.
#[fail(display = "`HoneyBadger` received an invalid ciphertext from the proposer.")]
#[error("`HoneyBadger` received an invalid ciphertext from the proposer.")]
InvalidCiphertext,
/// `HoneyBadger` received a message with an invalid epoch.
#[fail(display = "`HoneyBadger` received a message with an invalid epoch.")]
#[error("`HoneyBadger` received a message with an invalid epoch.")]
UnexpectedHbMessageEpoch,
/// `HoneyBadger` could not deserialize bytes (i.e. a serialized Batch) from a given proposer
/// into a vector of transactions.
#[fail(
display = "`HoneyBadger` could not deserialize bytes (i.e. a serialized Batch) from a
#[error(
"`HoneyBadger` could not deserialize bytes (i.e. a serialized Batch) from a
given proposer into a vector of transactions."
)]
BatchDeserializationFailed,
/// `HoneyBadger` received a fault from `Subset`.
#[fail(display = "`HoneyBadger` received a fault from `Subset`.")]
#[error("`HoneyBadger` received a fault from `Subset`.")]
SubsetFault(subset::FaultKind),
/// `HoneyBadger` received a fault from `ThresholdDecrypt`.
#[fail(display = "`HoneyBadger` received a fault from `ThresholdDecrypt`.")]
#[error("`HoneyBadger` received a fault from `ThresholdDecrypt`.")]
DecryptionFault(threshold_decrypt::FaultKind),
}

View File

@ -26,10 +26,10 @@ use std::marker::PhantomData;
use std::{cmp, iter};
use derivative::Derivative;
use failure::Fail;
use rand::distributions::{Distribution, Standard};
use rand::Rng;
use serde::{de::DeserializeOwned, Serialize};
use thiserror::Error as ThisError;
use crate::crypto::{PublicKey, SecretKey};
use crate::dynamic_honey_badger::{
@ -41,19 +41,19 @@ use crate::{ConsensusProtocol, Contribution, NetworkInfo, NodeIdT};
pub use crate::dynamic_honey_badger::{Change, ChangeState, Input};
/// Queueing honey badger error variants.
#[derive(Debug, Fail)]
#[derive(Debug, ThisError)]
pub enum Error {
/// Failed to handle input.
#[fail(display = "Input error: {}", _0)]
#[error("Input error: {0}")]
Input(dynamic_honey_badger::Error),
/// Failed to handle a message.
#[fail(display = "Handle message error: {}", _0)]
#[error("Handle message error: {0}")]
HandleMessage(dynamic_honey_badger::Error),
/// Failed to propose a contribution.
#[fail(display = "Propose error: {}", _0)]
#[error("Propose error: {0}")]
Propose(dynamic_honey_badger::Error),
/// Failed to create a Dynamic Honey Badger instance according to a join plan.
#[fail(display = "New joining error: {}", _0)]
#[error("New joining error: {0}")]
NewJoining(dynamic_honey_badger::Error),
}

View File

@ -1,19 +1,21 @@
use failure::Fail;
use std::error::Error as StdError;
use std::fmt::Debug;
use thiserror::Error as ThisError;
/// Sender queue error variants.
#[derive(Debug, Fail)]
#[derive(Debug, ThisError)]
pub enum Error<E>
where
E: Debug + Fail,
E: Debug + StdError,
{
/// Failed to apply a function to the managed algorithm.
#[fail(display = "Function application failure: {}", _0)]
#[error("Function application failure: {0}")]
Apply(E),
/// Failed to restart `DynamicHoneyBadger` because it had not been removed.
#[fail(display = "DynamicHoneyBadger was not removed before restarting")]
#[error("DynamicHoneyBadger was not removed before restarting")]
DynamicHoneyBadgerNotRemoved,
/// Failed to start a new joining `DynamicHoneyBadger`.
#[fail(display = "Failed to start a new joining DynamicHoneyBadger: {}", _0)]
#[error("Failed to start a new joining DynamicHoneyBadger: {0}")]
DynamicHoneyBadgerNewJoining(E),
}

View File

@ -1,27 +1,27 @@
use failure::Fail;
use std::result;
use thiserror::Error as ThisError;
use crate::binary_agreement;
use crate::broadcast;
/// A subset error.
#[derive(Clone, PartialEq, Debug, Fail)]
#[derive(Clone, PartialEq, Debug, ThisError)]
pub enum Error {
/// Error creating `BinaryAgreement`.
#[fail(display = "Error creating BinaryAgreement: {}", _0)]
#[error("Error creating BinaryAgreement: {0}")]
NewAgreement(binary_agreement::Error),
/// Error creating `Broadcast`.
#[fail(display = "Error creating Broadcast: {}", _0)]
#[error("Error creating Broadcast: {0}")]
NewBroadcast(broadcast::Error),
/// Error handling a `Broadcast` input or message.
#[fail(display = "Error handling Broadcast input/message: {}", _0)]
#[error("Error handling Broadcast input/message: {0}")]
HandleBroadcast(broadcast::Error),
/// Error handling a `BinaryAgreement` input or message.
#[fail(display = "Error handling BinaryAgreement input/message: {}", _0)]
#[error("Error handling BinaryAgreement input/message: {0}")]
HandleAgreement(binary_agreement::Error),
/// Unknown proposer.
#[fail(display = "Unknown proposer ID")]
#[error("Unknown proposer ID")]
UnknownProposer,
}
@ -29,12 +29,12 @@ pub enum Error {
pub type Result<T> = result::Result<T, Error>;
/// Faults that can be detected in Subset.
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `Subset` received a faulty Broadcast message.
#[fail(display = "`Subset` received a faulty Broadcast message.")]
#[error("`Subset` received a faulty Broadcast message.")]
BroadcastFault(broadcast::FaultKind),
/// `Subset` received a faulty Binary Agreement message.
#[fail(display = "`Subset` received a faulty Binary Agreement message.")]
#[error("`Subset` received a faulty Binary Agreement message.")]
BaFault(binary_agreement::FaultKind),
}

View File

@ -178,9 +178,9 @@ use std::string::ToString;
use std::sync::Arc;
use bincode;
use failure::Fail;
use rand::{self, Rng};
use serde::{Deserialize, Serialize};
use thiserror::Error as ThisError;
use crate::crypto::{
self,
@ -252,22 +252,22 @@ where
/// A local error while handling an `Ack` or `Part` message, that was not caused by that message
/// being invalid.
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
#[derive(Clone, Eq, PartialEq, Debug, ThisError)]
pub enum Error {
/// Error creating `SyncKeyGen`.
#[fail(display = "Error creating SyncKeyGen: {}", _0)]
#[error("Error creating SyncKeyGen: {0}")]
Creation(CryptoError),
/// Error generating keys.
#[fail(display = "Error generating keys: {}", _0)]
#[error("Error generating keys: {0}")]
Generation(CryptoError),
/// Unknown sender.
#[fail(display = "Unknown sender")]
#[error("Unknown sender")]
UnknownSender,
/// Failed to serialize message.
#[fail(display = "Serialization error: {}", _0)]
#[error("Serialization error: {0}")]
Serialize(String),
/// Failed to encrypt message parts for a peer.
#[fail(display = "Encryption error: {}", _0)]
#[error("Encryption error: {0}")]
Encrypt(String),
}
@ -610,41 +610,41 @@ impl<N: NodeIdT, PK: PublicKey> SyncKeyGen<N, PK> {
}
/// An error in an `Ack` message sent by a faulty node.
#[derive(Clone, Copy, Eq, PartialEq, Debug, Fail)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, ThisError)]
pub enum AckFault {
/// The number of values differs from the number of nodes.
#[fail(display = "The number of values differs from the number of nodes")]
#[error("The number of values differs from the number of nodes")]
ValueCount,
/// No corresponding Part received.
#[fail(display = "No corresponding Part received")]
#[error("No corresponding Part received")]
MissingPart,
/// Value decryption failed.
#[fail(display = "Value decryption failed")]
#[error("Value decryption failed")]
DecryptValue,
/// Value deserialization failed.
#[fail(display = "Value deserialization failed")]
#[error("Value deserialization failed")]
DeserializeValue,
/// Value doesn't match the commitment.
#[fail(display = "Value doesn't match the commitment")]
#[error("Value doesn't match the commitment")]
ValueCommitment,
}
/// An error in a `Part` message sent by a faulty node.
#[derive(Clone, Copy, Eq, PartialEq, Debug, Fail)]
#[derive(Clone, Copy, Eq, PartialEq, Debug, ThisError)]
pub enum PartFault {
/// The number of rows differs from the number of nodes.
#[fail(display = "The number of rows differs from the number of nodes")]
#[error("The number of rows differs from the number of nodes")]
RowCount,
/// Received multiple different Part messages from the same sender.
#[fail(display = "Received multiple different Part messages from the same sender")]
#[error("Received multiple different Part messages from the same sender")]
MultipleParts,
/// Could not decrypt our row in the Part message.
#[fail(display = "Could not decrypt our row in the Part message")]
#[error("Could not decrypt our row in the Part message")]
DecryptRow,
/// Could not deserialize our row in the Part message.
#[fail(display = "Could not deserialize our row in the Part message")]
#[error("Could not deserialize our row in the Part message")]
DeserializeRow,
/// Row does not match the commitment.
#[fail(display = "Row does not match the commitment")]
#[error("Row does not match the commitment")]
RowCommitment,
}

View File

@ -15,31 +15,31 @@ use std::collections::BTreeMap;
use std::sync::Arc;
use crate::crypto::{self, Ciphertext, DecryptionShare};
use failure::Fail;
use rand::Rng;
use rand_derive::Rand;
use serde::{Deserialize, Serialize};
use thiserror::Error as ThisError;
use crate::fault_log::{self, Fault};
use crate::{ConsensusProtocol, NetworkInfo, NodeIdT, Target};
/// A threshold decryption error.
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
#[derive(Clone, Eq, PartialEq, Debug, ThisError)]
pub enum Error {
/// Redundant input provided.
#[fail(display = "Redundant input provided: {:?}", _0)]
#[error("Redundant input provided: {0:?}")]
MultipleInputs(Box<Ciphertext>),
/// Invalid ciphertext.
#[fail(display = "Invalid ciphertext: {:?}", _0)]
#[error("Invalid ciphertext: {0:?}")]
InvalidCiphertext(Box<Ciphertext>),
/// Unknown sender.
#[fail(display = "Unknown sender")]
#[error("Unknown sender")]
UnknownSender,
/// Decryption failed.
#[fail(display = "Decryption failed: {:?}", _0)]
#[error("Decryption failed: {0:?}")]
Decryption(crypto::error::Error),
/// Tried to decrypt before setting a cipherext.
#[fail(display = "Tried to decrypt before setting ciphertext")]
#[error("Tried to decrypt before setting ciphertext")]
CiphertextIsNone,
}
@ -47,13 +47,13 @@ pub enum Error {
pub type Result<T> = ::std::result::Result<T, Error>;
/// A threshold decryption message fault
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `ThresholdDecrypt` received multiple shares from the same sender.
#[fail(display = "`ThresholdDecrypt` received multiple shares from the same sender.")]
#[error("`ThresholdDecrypt` received multiple shares from the same sender.")]
MultipleDecryptionShares,
/// `HoneyBadger` received a decryption share from an unverified sender.
#[fail(display = "`HoneyBadger` received a decryption share from an unverified sender.")]
#[error("`HoneyBadger` received a decryption share from an unverified sender.")]
UnverifiedDecryptionShareSender,
}

View File

@ -20,32 +20,32 @@ use std::sync::Arc;
use std::{fmt, result};
use crate::crypto::{self, hash_g2, Signature, SignatureShare, G2};
use failure::Fail;
use log::debug;
use rand::Rng;
use rand_derive::Rand;
use serde::{Deserialize, Serialize};
use thiserror::Error as ThisError;
use crate::fault_log::{Fault, FaultLog};
use crate::{ConsensusProtocol, NetworkInfo, NodeIdT, Target};
/// A threshold signing error.
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
#[derive(Clone, Eq, PartialEq, Debug, ThisError)]
pub enum Error {
/// Redundant input provided.
#[fail(display = "Redundant input provided")]
#[error("Redundant input provided")]
MultipleMessagesToSign,
/// Error combining and verifying signature shares.
#[fail(display = "Error combining and verifying signature shares: {}", _0)]
#[error("Error combining and verifying signature shares: {0}")]
CombineAndVerifySigCrypto(crypto::error::Error),
/// Unknown sender
#[fail(display = "Unknown sender")]
#[error("Unknown sender")]
UnknownSender,
/// Signature verification failed.
#[fail(display = "Signature verification failed")]
#[error("Signature verification failed")]
VerificationFailed,
/// Document hash is not set, cannot sign or verify signatures.
#[fail(display = "Document hash is not set, cannot sign or verify signatures")]
#[error("Document hash is not set, cannot sign or verify signatures")]
DocumentHashIsNone,
}
@ -53,16 +53,14 @@ pub enum Error {
pub type Result<T> = ::std::result::Result<T, Error>;
/// A threshold sign message fault
#[derive(Clone, Debug, Fail, PartialEq)]
#[derive(Clone, Debug, ThisError, PartialEq)]
pub enum FaultKind {
/// `ThresholdSign` (`Coin`) received a signature share from an unverified sender.
#[fail(
display = "`ThresholdSign` (`Coin`) received a signature share from an unverified sender."
)]
#[error("`ThresholdSign` (`Coin`) received a signature share from an unverified sender.")]
UnverifiedSignatureShareSender,
/// `HoneyBadger` received a signatures share for the random value even though it is disabled.
#[fail(
display = "`HoneyBadger` received a signatures share for the random value even though it
#[error(
"`HoneyBadger` received a signatures share for the random value even though it
is disabled."
)]
UnexpectedSignatureShare,

View File

@ -1,11 +1,11 @@
//! Common supertraits for consensus protocols.
use std::collections::BTreeMap;
use std::error::Error as StdError;
use std::fmt::{Debug, Display};
use std::hash::Hash;
use std::iter::once;
use failure::Fail;
use rand::Rng;
use serde::{de::DeserializeOwned, Serialize};
@ -22,8 +22,8 @@ pub trait NodeIdT: Eq + Ord + Clone + Debug + Hash + Send + Sync {}
impl<N> NodeIdT for N where N: Eq + Ord + Clone + Debug + Hash + Send + Sync {}
/// A consensus protocol fault.
pub trait FaultT: Clone + Debug + Fail + PartialEq {}
impl<N> FaultT for N where N: Clone + Debug + Fail + PartialEq {}
pub trait FaultT: Clone + Debug + StdError + PartialEq {}
impl<N> FaultT for N where N: Clone + Debug + StdError + PartialEq {}
/// Messages.
pub trait Message: Debug + Send + Sync {}
@ -61,7 +61,7 @@ impl<E> EpochT for E where E: Copy + Message + Default + Eq + Ord + Serialize +
/// catch it, instead of potentially stalling the algorithm.
#[must_use = "The algorithm step result must be used."]
#[derive(Debug)]
pub struct Step<M, O, N, F: Fail> {
pub struct Step<M, O, N, F: StdError> {
/// The algorithm's output, after consensus has been reached. This is guaranteed to be the same
/// in all nodes.
pub output: Vec<O>,
@ -75,7 +75,7 @@ pub struct Step<M, O, N, F: Fail> {
impl<M, O, N, F> Default for Step<M, O, N, F>
where
F: Fail,
F: StdError,
{
fn default() -> Self {
Step {
@ -88,7 +88,7 @@ where
impl<M, O, N, F> Step<M, O, N, F>
where
F: Fail,
F: StdError,
{
/// Returns the same step, with the given additional output.
pub fn with_output<T: Into<Option<O>>>(mut self, output: T) -> Self {
@ -105,7 +105,7 @@ where
mut f_msg: FM,
) -> Step<M2, O2, N, F2>
where
F2: Fail,
F2: StdError,
FO: FnMut(O) -> O2,
FF: FnMut(F) -> F2,
FM: FnMut(M) -> M2,
@ -130,7 +130,7 @@ where
mut f_msg: FM,
) -> Vec<O2>
where
F2: Fail,
F2: StdError,
FF: FnMut(F2) -> F,
FM: FnMut(M2) -> M,
{
@ -162,7 +162,7 @@ where
impl<M, O, N, F> From<FaultLog<N, F>> for Step<M, O, N, F>
where
F: Fail,
F: StdError,
{
fn from(fault_log: FaultLog<N, F>) -> Self {
Step {
@ -174,7 +174,7 @@ where
impl<M, O, N, F> From<Fault<N, F>> for Step<M, O, N, F>
where
F: Fail,
F: StdError,
{
fn from(fault: Fault<N, F>) -> Self {
Step {
@ -186,7 +186,7 @@ where
impl<M, O, N, F> From<TargetedMessage<M, N>> for Step<M, O, N, F>
where
F: Fail,
F: StdError,
{
fn from(msg: TargetedMessage<M, N>) -> Self {
Step {
@ -199,7 +199,7 @@ where
impl<I, M, O, N, F> From<I> for Step<M, O, N, F>
where
I: IntoIterator<Item = TargetedMessage<M, N>>,
F: Fail,
F: StdError,
{
fn from(msgs: I) -> Self {
Step {
@ -232,7 +232,7 @@ impl<'i, M, O, N, F> Step<M, O, N, F>
where
N: NodeIdT,
M: 'i + Clone + SenderQueueableMessage,
F: Fail,
F: StdError,
{
/// Removes and returns any messages that are not yet accepted by remote nodes according to the
/// mapping `remote_epochs`. This way the returned messages are postponed until later, and the
@ -300,7 +300,7 @@ pub trait ConsensusProtocol: Send + Sync {
/// The messages that need to be exchanged between the instances in the participating nodes.
type Message: Message;
/// The errors that can occur during execution.
type Error: Fail;
type Error: StdError;
/// The kinds of message faults that can be detected during execution.
type FaultKind: FaultT;