2018-07-08 09:41:50 -07:00
|
|
|
//! Functionality for logging faulty node behavior encountered by each
|
|
|
|
//! algorithm.
|
|
|
|
//!
|
|
|
|
//! Each algorithm can propogate their faulty node logs upwards to a
|
2018-08-29 08:28:02 -07:00
|
|
|
//! calling algorithm via `DistAlgorihm`'s `.handle_input()` and
|
2018-07-08 09:41:50 -07:00
|
|
|
//! `.handle_message()` trait methods.
|
|
|
|
|
2018-10-24 12:23:54 -07:00
|
|
|
pub use sync_key_gen::{AckFault, PartFault};
|
2018-08-06 10:30:38 -07:00
|
|
|
|
2018-07-08 09:41:50 -07:00
|
|
|
/// Represents each reason why a node could be considered faulty.
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
|
|
pub enum FaultKind {
|
2018-08-14 05:56:32 -07:00
|
|
|
/// `Coin` received a signature share from an unverified sender.
|
2018-07-08 09:41:50 -07:00
|
|
|
UnverifiedSignatureShareSender,
|
|
|
|
/// `HoneyBadger` received a decryption share from an unverified sender.
|
|
|
|
UnverifiedDecryptionShareSender,
|
2018-08-03 06:24:49 -07:00
|
|
|
/// `HoneyBadger` received a decryption share for an unaccepted proposer.
|
|
|
|
UnexpectedDecryptionShare,
|
2018-07-08 09:41:50 -07:00
|
|
|
/// `HoneyBadger` was unable to deserialize a proposer's ciphertext.
|
2018-11-01 03:22:40 -07:00
|
|
|
DeserializeCiphertext,
|
|
|
|
/// `HoneyBadger` received an invalid ciphertext from the proposer.
|
2018-07-08 09:41:50 -07:00
|
|
|
InvalidCiphertext,
|
2018-10-25 08:07:52 -07:00
|
|
|
/// `HoneyBadger` received a message with an invalid epoch.
|
|
|
|
UnexpectedHbMessageEpoch,
|
2018-11-07 08:13:10 -08:00
|
|
|
/// `ThresholdDecrypt` received multiple shares from the same sender.
|
2018-08-03 02:18:06 -07:00
|
|
|
MultipleDecryptionShares,
|
2018-07-08 09:41:50 -07:00
|
|
|
/// `Broadcast` received a `Value` from a node other than the proposer.
|
|
|
|
ReceivedValueFromNonProposer,
|
2018-10-24 05:48:21 -07:00
|
|
|
/// `Broadcast` received multiple different `Value`s from the proposer.
|
|
|
|
MultipleValues,
|
2018-11-01 03:22:40 -07:00
|
|
|
/// `Broadcast` received multiple different `Echo`s from the same sender.
|
|
|
|
MultipleEchos,
|
|
|
|
/// `Broadcast` received multiple different `Ready`s from the same sender.
|
|
|
|
MultipleReadys,
|
2018-07-08 09:41:50 -07:00
|
|
|
/// `Broadcast` recevied an Echo message containing an invalid proof.
|
|
|
|
InvalidProof,
|
2018-11-01 03:22:40 -07:00
|
|
|
/// `Broadcast` received shards with valid proofs, that couldn't be decoded.
|
|
|
|
BroadcastDecoding,
|
2018-07-08 09:41:50 -07:00
|
|
|
/// `HoneyBadger` could not deserialize bytes (i.e. a serialized Batch)
|
|
|
|
/// from a given proposer into a vector of transactions.
|
|
|
|
BatchDeserializationFailed,
|
2018-10-22 07:09:00 -07:00
|
|
|
/// `DynamicHoneyBadger` received a key generation message with an invalid signature.
|
2018-07-11 07:18:32 -07:00
|
|
|
InvalidKeyGenMessageSignature,
|
2018-10-25 08:07:52 -07:00
|
|
|
/// `DynamicHoneyBadger` received a key generation message with an invalid era.
|
|
|
|
InvalidKeyGenMessageEra,
|
2018-08-01 01:41:09 -07:00
|
|
|
/// `DynamicHoneyBadger` received a key generation message when there was no key generation in
|
|
|
|
/// progress.
|
|
|
|
UnexpectedKeyGenMessage,
|
2018-10-22 07:09:00 -07:00
|
|
|
/// `DynamicHoneyBadger` received a signed `Ack` when no key generation in progress.
|
|
|
|
UnexpectedKeyGenAck,
|
|
|
|
/// `DynamicHoneyBadger` received a signed `Part` when no key generation in progress.
|
|
|
|
UnexpectedKeyGenPart,
|
2018-10-23 02:13:55 -07:00
|
|
|
/// `DynamicHoneyBadger` received more key generation messages from the peer than expected.
|
|
|
|
TooManyKeyGenMessages,
|
2018-07-08 09:41:50 -07:00
|
|
|
/// `DynamicHoneyBadger` received a message (Accept, Propose, or Change)
|
|
|
|
/// with an invalid signature.
|
|
|
|
IncorrectPayloadSignature,
|
2018-10-24 12:23:54 -07:00
|
|
|
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Ack` message.
|
|
|
|
SyncKeyGenAck(AckFault),
|
|
|
|
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid `Part` message.
|
|
|
|
SyncKeyGenPart(PartFault),
|
2018-07-11 09:37:54 -07:00
|
|
|
/// `DynamicHoneyBadger` received a change vote with an invalid signature.
|
|
|
|
InvalidVoteSignature,
|
|
|
|
/// A validator committed an invalid vote in `DynamicHoneyBadger`.
|
|
|
|
InvalidCommittedVote,
|
2018-10-25 08:07:52 -07:00
|
|
|
/// `DynamicHoneyBadger` received a message with an invalid era.
|
|
|
|
UnexpectedDhbMessageEra,
|
2018-08-30 01:22:56 -07:00
|
|
|
/// `BinaryAgreement` received a duplicate `BVal` message.
|
2018-07-30 03:04:28 -07:00
|
|
|
DuplicateBVal,
|
2018-08-30 01:22:56 -07:00
|
|
|
/// `BinaryAgreement` received a duplicate `Aux` message.
|
2018-07-30 03:04:28 -07:00
|
|
|
DuplicateAux,
|
2018-11-12 03:15:02 -08:00
|
|
|
/// `BinaryAgreement` received multiple `Conf` messages.
|
|
|
|
MultipleConf,
|
|
|
|
/// `BinaryAgreement` received multiple `Term` messages.
|
|
|
|
MultipleTerm,
|
|
|
|
/// `BinaryAgreement` received a message with an epoch too far ahead.
|
|
|
|
AgreementEpoch,
|
2018-07-08 09:41:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A structure representing the context of a faulty node. This structure
|
|
|
|
/// describes which node is faulty (`node_id`) and which faulty behavior
|
2018-11-27 03:13:42 -08:00
|
|
|
/// the node exhibited ('kind').
|
2018-07-16 06:31:21 -07:00
|
|
|
#[derive(Debug, PartialEq)]
|
2018-08-02 14:27:55 -07:00
|
|
|
pub struct Fault<N> {
|
2018-11-26 06:35:24 -08:00
|
|
|
/// The faulty node's ID.
|
2018-08-02 14:27:55 -07:00
|
|
|
pub node_id: N,
|
2018-11-26 06:35:24 -08:00
|
|
|
/// The kind of fault the node is blamed for.
|
2018-07-08 09:41:50 -07:00
|
|
|
pub kind: FaultKind,
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:27:55 -07:00
|
|
|
impl<N> Fault<N> {
|
2018-11-26 06:35:24 -08:00
|
|
|
/// Creates a new fault, blaming `node_id` for the `kind`.
|
2018-08-02 14:27:55 -07:00
|
|
|
pub fn new(node_id: N, kind: FaultKind) -> Self {
|
2018-07-08 09:41:50 -07:00
|
|
|
Fault { node_id, kind }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new `FaultLog` where `self` is the first element in the log
|
|
|
|
/// vector.
|
2018-08-02 14:27:55 -07:00
|
|
|
impl<N> Into<FaultLog<N>> for Fault<N> {
|
|
|
|
fn into(self) -> FaultLog<N> {
|
2018-07-08 09:41:50 -07:00
|
|
|
FaultLog(vec![self])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A structure used to contain reports of faulty node behavior.
|
2018-07-16 06:31:21 -07:00
|
|
|
#[derive(Debug, PartialEq)]
|
2018-08-02 14:27:55 -07:00
|
|
|
pub struct FaultLog<N>(pub Vec<Fault<N>>);
|
2018-07-08 09:41:50 -07:00
|
|
|
|
2018-08-02 14:27:55 -07:00
|
|
|
impl<N> FaultLog<N> {
|
2018-07-08 09:41:50 -07:00
|
|
|
/// Creates an empty `FaultLog`.
|
|
|
|
pub fn new() -> Self {
|
|
|
|
FaultLog::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new `FaultLog` initialized with a single log.
|
2018-08-02 14:27:55 -07:00
|
|
|
pub fn init(node_id: N, kind: FaultKind) -> Self {
|
2018-07-08 09:41:50 -07:00
|
|
|
Fault::new(node_id, kind).into()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new `Fault` and pushes it onto the fault log.
|
2018-08-02 14:27:55 -07:00
|
|
|
pub fn append(&mut self, node_id: N, kind: FaultKind) {
|
2018-07-08 09:41:50 -07:00
|
|
|
self.0.push(Fault::new(node_id, kind));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Consumes `new_logs`, appending its logs onto the end of `self`.
|
2018-08-02 14:27:55 -07:00
|
|
|
pub fn extend(&mut self, new_logs: FaultLog<N>) {
|
2018-07-08 09:41:50 -07:00
|
|
|
self.0.extend(new_logs.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Consumes `self`, appending its logs onto the end of `logs`.
|
2018-08-02 14:27:55 -07:00
|
|
|
pub fn merge_into(self, logs: &mut FaultLog<N>) {
|
2018-07-08 09:41:50 -07:00
|
|
|
logs.extend(self);
|
|
|
|
}
|
2018-07-11 23:52:38 -07:00
|
|
|
|
|
|
|
/// Returns `true` if there are no fault entries in the log.
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
self.0.is_empty()
|
|
|
|
}
|
2018-07-08 09:41:50 -07:00
|
|
|
}
|
|
|
|
|
2018-08-02 14:27:55 -07:00
|
|
|
impl<N> Default for FaultLog<N> {
|
2018-07-08 09:41:50 -07:00
|
|
|
fn default() -> Self {
|
|
|
|
FaultLog(vec![])
|
|
|
|
}
|
|
|
|
}
|