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
|
|
|
|
//! calling algorithm via `DistAlgorihm`'s `.input()` and
|
|
|
|
//! `.handle_message()` trait methods.
|
|
|
|
|
|
|
|
/// Represents each reason why a node could be considered faulty.
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
|
|
pub enum FaultKind {
|
|
|
|
/// `CommonCoin` received a signature share from an unverified sender.
|
|
|
|
UnverifiedSignatureShareSender,
|
|
|
|
/// `HoneyBadger` received a decryption share from an unverified sender.
|
|
|
|
UnverifiedDecryptionShareSender,
|
|
|
|
/// `HoneyBadger` was unable to deserialize a proposer's ciphertext.
|
|
|
|
InvalidCiphertext,
|
|
|
|
/// `HoneyBadger` was unable to decrypt a share received from a proposer.
|
|
|
|
ShareDecryptionFailed,
|
|
|
|
/// `Broadcast` received a `Value` from a node other than the proposer.
|
|
|
|
ReceivedValueFromNonProposer,
|
|
|
|
/// `Broadcast` recevied an Echo message containing an invalid proof.
|
|
|
|
InvalidProof,
|
|
|
|
/// `HoneyBadger` could not deserialize bytes (i.e. a serialized Batch)
|
|
|
|
/// from a given proposer into a vector of transactions.
|
|
|
|
BatchDeserializationFailed,
|
2018-07-11 07:18:32 -07:00
|
|
|
/// `DynamicHoneyBadger` received a key generation message with an invalid
|
2018-07-08 09:41:50 -07:00
|
|
|
/// signature.
|
2018-07-11 07:18:32 -07:00
|
|
|
InvalidKeyGenMessageSignature,
|
2018-08-01 01:41:09 -07:00
|
|
|
/// `DynamicHoneyBadger` received a key generation message when there was no key generation in
|
|
|
|
/// progress.
|
|
|
|
UnexpectedKeyGenMessage,
|
|
|
|
/// `DynamicHoneyBadger` received more key generation messages from the candidate than expected.
|
|
|
|
TooManyCandidateKeyGenMessages,
|
2018-07-08 09:41:50 -07:00
|
|
|
/// `DynamicHoneyBadger` received a message (Accept, Propose, or Change)
|
|
|
|
/// with an invalid signature.
|
|
|
|
IncorrectPayloadSignature,
|
2018-07-19 03:28:15 -07:00
|
|
|
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid Ack message.
|
|
|
|
InvalidAckMessage,
|
|
|
|
/// `DynamicHoneyBadger`/`SyncKeyGen` received an invalid Part message.
|
|
|
|
InvalidPartMessage,
|
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-07-30 03:04:28 -07:00
|
|
|
/// `Agreement` received a duplicate `BVal` message.
|
|
|
|
DuplicateBVal,
|
|
|
|
/// `Agreement` received a duplicate `Aux` message.
|
|
|
|
DuplicateAux,
|
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
|
|
|
|
/// that the node exhibited ('kind').
|
2018-07-16 06:31:21 -07:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct Fault<NodeUid> {
|
2018-07-08 09:41:50 -07:00
|
|
|
pub node_id: NodeUid,
|
|
|
|
pub kind: FaultKind,
|
|
|
|
}
|
|
|
|
|
2018-07-16 06:31:21 -07:00
|
|
|
impl<NodeUid> Fault<NodeUid> {
|
2018-07-08 09:41:50 -07:00
|
|
|
pub fn new(node_id: NodeUid, kind: FaultKind) -> Self {
|
|
|
|
Fault { node_id, kind }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new `FaultLog` where `self` is the first element in the log
|
|
|
|
/// vector.
|
2018-07-16 06:31:21 -07:00
|
|
|
impl<NodeUid> Into<FaultLog<NodeUid>> for Fault<NodeUid> {
|
2018-07-08 09:41:50 -07:00
|
|
|
fn into(self) -> FaultLog<NodeUid> {
|
|
|
|
FaultLog(vec![self])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A structure used to contain reports of faulty node behavior.
|
2018-07-16 06:31:21 -07:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct FaultLog<NodeUid>(pub Vec<Fault<NodeUid>>);
|
2018-07-08 09:41:50 -07:00
|
|
|
|
2018-07-16 06:31:21 -07:00
|
|
|
impl<NodeUid> FaultLog<NodeUid> {
|
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.
|
|
|
|
pub fn init(node_id: NodeUid, kind: FaultKind) -> Self {
|
|
|
|
Fault::new(node_id, kind).into()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new `Fault` and pushes it onto the fault log.
|
|
|
|
pub fn append(&mut self, node_id: NodeUid, kind: FaultKind) {
|
|
|
|
self.0.push(Fault::new(node_id, kind));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Consumes `new_logs`, appending its logs onto the end of `self`.
|
|
|
|
pub fn extend(&mut self, new_logs: FaultLog<NodeUid>) {
|
|
|
|
self.0.extend(new_logs.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Consumes `self`, appending its logs onto the end of `logs`.
|
|
|
|
pub fn merge_into(self, logs: &mut FaultLog<NodeUid>) {
|
|
|
|
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-07-16 06:31:21 -07:00
|
|
|
impl<NodeUid> Default for FaultLog<NodeUid> {
|
2018-07-08 09:41:50 -07:00
|
|
|
fn default() -> Self {
|
|
|
|
FaultLog(vec![])
|
|
|
|
}
|
|
|
|
}
|