made FaultKind cloneable and added missing doc comments

This commit is contained in:
Vladimir Komendantskiy 2018-12-26 13:07:53 +00:00
parent 6555b9ecc3
commit 767be50088
11 changed files with 62 additions and 11 deletions

View File

@ -105,18 +105,24 @@ 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(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, PartialEq)]
pub enum FaultKind {
/// `BinaryAgreement` received a duplicate `BVal` message.
#[fail(display = "`BinaryAgreement` received a duplicate `BVal` message.")]
DuplicateBVal,
/// `BinaryAgreement` received a duplicate `Aux` message.
#[fail(display = "`BinaryAgreement` received a duplicate `Aux` message.")]
DuplicateAux,
/// `BinaryAgreement` received multiple `Conf` messages.
#[fail(display = "`BinaryAgreement` received multiple `Conf` messages.")]
MultipleConf,
/// `BinaryAgreement` received multiple `Term` messages.
#[fail(display = "`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.")]
AgreementEpoch,
/// `BinaryAgreement` received a Coin Fault.
#[fail(display = "`BinaryAgreement` received a Coin Fault.")]
CoinFault(threshold_sign::FaultKind),
}

View File

@ -24,18 +24,24 @@ pub enum Error {
pub type Result<T> = ::std::result::Result<T, Error>;
/// Represents each reason why a broadcast message could be faulty.
#[derive(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, 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.")]
ReceivedValueFromNonProposer,
/// `Broadcast` received multiple different `Value`s from the proposer.
#[fail(display = "`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.")]
MultipleEchos,
/// `Broadcast` received multiple different `Ready`s from the same sender.
#[fail(display = "`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.")]
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.")]
BroadcastDecoding,
}

View File

@ -30,49 +30,64 @@ pub enum Error {
/// 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(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, 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."
)]
InvalidKeyGenMessageSignature,
/// `DynamicHoneyBadger` received a key generation message with an invalid era.
#[fail(
display = "`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
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."
)]
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."
)]
UnexpectedKeyGenPart,
/// `DynamicHoneyBadger` received more key generation messages from the peer than expected.
#[fail(
display = "`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
with an invalid signature."
)]
IncorrectPayloadSignature,
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Ack` message.
#[fail(display = "`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.")]
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.")]
InvalidVoteSignature,
/// A validator committed an invalid vote in `DynamicHoneyBadger`.
#[fail(display = "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.")]
UnexpectedDhbMessageEra,
/// `DynamicHoneyBadger` received a fault from `HoneyBadger`.
#[fail(display = "`DynamicHoneyBadger` received a fault from `HoneyBadger`.")]
HbFault(honey_badger::FaultKind),
}

View File

@ -21,6 +21,7 @@ impl<N, F> Fault<N, F>
where
F: Fail,
{
/// Creates a new fault given a node ID and a fault description.
pub fn new(node_id: N, kind: F) -> Self {
Fault { node_id, kind }
}

View File

@ -32,25 +32,34 @@ pub enum Error {
pub type Result<T> = ::std::result::Result<T, Error>;
/// Faults detectable from receiving honey badger messages
#[derive(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, PartialEq)]
pub enum FaultKind {
/// `HoneyBadger` received a decryption share for an unaccepted proposer.
#[fail(display = "`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.")]
DeserializeCiphertext,
/// `HoneyBadger` received an invalid ciphertext from the proposer.
#[fail(display = "`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.")]
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
given proposer into a vector of transactions."
)]
BatchDeserializationFailed,
/// `HoneyBadger` received a fault from `Subset`.
#[fail(display = "`HoneyBadger` received a fault from `Subset`.")]
SubsetFault(subset::FaultKind),
/// `HoneyBadger` received a fault from `ThresholdDecrypt`.
#[fail(display = "`HoneyBadger` received a fault from `ThresholdDecrypt`.")]
DecryptionFault(threshold_decrypt::FaultKind),
}
/// The type of fault log whose entries are `HoneyBadger` faults.
pub type FaultLog<N> = fault_log::FaultLog<N, FaultKind>;

View File

@ -29,10 +29,12 @@ pub enum Error {
pub type Result<T> = result::Result<T, Error>;
/// Subset does not actually have any messages defined, so there's no real FaultKind to define here
#[derive(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, PartialEq)]
pub enum FaultKind {
/// `Subset` received a faulty Broadcast message.
#[fail(display = "`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.")]
BaFault(binary_agreement::FaultKind),
}

View File

@ -45,15 +45,19 @@ pub enum Error {
/// A threshold decryption result.
pub type Result<T> = ::std::result::Result<T, Error>;
/// A threshold decryption message fault
#[derive(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, PartialEq)]
pub enum FaultKind {
/// `ThresholdDecrypt` received multiple shares from the same sender.
#[fail(display = "`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.")]
UnverifiedDecryptionShareSender,
}
/// The type of fault log whose entries are `ThresholdDecrypt` faults.
pub type FaultLog<N> = fault_log::FaultLog<N, FaultKind>;
/// A Threshold Decryption message.

View File

@ -53,12 +53,14 @@ pub enum Error {
pub type Result<T> = ::std::result::Result<T, Error>;
/// A threshold sign message fault
#[derive(Debug, Fail, PartialEq)]
#[derive(Clone, Debug, Fail, 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."
)]
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
is disabled."

View File

@ -21,6 +21,10 @@ impl<C> Contribution for C where C: Eq + Debug + Hash + Send + Sync {}
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 distributed algorithm fault.
pub trait FaultT: Clone + Debug + Fail + PartialEq {}
impl<N> FaultT for N where N: Clone + Debug + Fail + PartialEq {}
/// Messages.
pub trait Message: Debug + Send + Sync {}
impl<M> Message for M where M: Debug + Send + Sync {}
@ -303,7 +307,7 @@ pub trait DistAlgorithm: Send + Sync {
/// The errors that can occur during execution.
type Error: Fail;
/// The kinds of message faults that can be detected during execution.
type FaultKind: Fail;
type FaultKind: FaultT;
/// Handles an input provided by the user, and returns
fn handle_input<R: Rng>(

View File

@ -378,7 +378,7 @@ where
.expect("failed to reconstruct the pivot node");
let (sq, mut sq_step) = SenderQueue::builder(dhb, peer_ids.into_iter()).build(id);
*node.algorithm_mut() = sq;
sq_step.extend(dhb_step.map(|output| output, Message::from));
sq_step.extend(dhb_step.map(|output| output, |fault| fault, Message::from));
net.insert_node(node);
sq_step
}

View File

@ -168,7 +168,7 @@ where
.expect("failed to rebuild the node with a join plan");
let (sq, mut sq_step) = SenderQueue::builder(qhb, peer_ids.into_iter()).build(our_id);
*node.instance_mut() = sq;
sq_step.extend(qhb_step.map(|output| output, Message::from));
sq_step.extend(qhb_step.map(|output| output, |fault| fault, Message::from));
network.nodes.insert(our_id, node);
sq_step
}
@ -192,7 +192,9 @@ fn new_queueing_hb(
.build(&mut rng)
.expect("failed to build QueueingHoneyBadger");
let (sq, mut step) = SenderQueue::builder(qhb, peer_ids).build(our_id);
assert!(step.extend_with(qhb_step, |fault| fault, Message::from).is_empty());
assert!(step
.extend_with(qhb_step, |fault| fault, Message::from)
.is_empty());
(sq, step)
}