2018-07-31 13:27:22 -07:00
|
|
|
use bincode;
|
2018-11-26 06:35:24 -08:00
|
|
|
use failure::Fail;
|
2018-07-31 13:27:22 -07:00
|
|
|
|
2018-12-18 07:17:46 -08:00
|
|
|
use crate::fault_log;
|
2018-12-11 05:44:36 -08:00
|
|
|
use crate::subset;
|
|
|
|
use crate::threshold_decrypt;
|
2018-07-31 13:27:22 -07:00
|
|
|
|
|
|
|
/// Honey badger error variants.
|
|
|
|
#[derive(Debug, Fail)]
|
2018-11-26 06:35:24 -08:00
|
|
|
pub enum Error {
|
|
|
|
/// Failed to serialize contribution.
|
|
|
|
#[fail(display = "Error serializing contribution: {}", _0)]
|
2018-07-31 13:27:22 -07:00
|
|
|
ProposeBincode(bincode::ErrorKind),
|
2018-11-26 06:35:24 -08:00
|
|
|
/// Failed to instantiate `Subset`.
|
2018-08-14 06:06:51 -07:00
|
|
|
#[fail(display = "Failed to instantiate Subset: {}", _0)]
|
|
|
|
CreateSubset(subset::Error),
|
2018-11-26 06:35:24 -08:00
|
|
|
/// Failed to input contribution to `Subset`.
|
2018-08-14 06:06:51 -07:00
|
|
|
#[fail(display = "Failed to input contribution to Subset: {}", _0)]
|
|
|
|
InputSubset(subset::Error),
|
2018-11-26 06:35:24 -08:00
|
|
|
/// Failed to handle `Subset` message.
|
2018-08-14 06:06:51 -07:00
|
|
|
#[fail(display = "Failed to handle Subset message: {}", _0)]
|
|
|
|
HandleSubsetMessage(subset::Error),
|
2018-11-26 06:35:24 -08:00
|
|
|
/// Failed to decrypt a contribution.
|
2018-08-03 02:18:06 -07:00
|
|
|
#[fail(display = "Threshold decryption error: {}", _0)]
|
2018-11-07 08:13:10 -08:00
|
|
|
ThresholdDecrypt(threshold_decrypt::Error),
|
2018-11-26 06:35:24 -08:00
|
|
|
/// Unknown sender
|
2018-10-09 07:07:56 -07:00
|
|
|
#[fail(display = "Unknown sender")]
|
|
|
|
UnknownSender,
|
2018-07-31 13:27:22 -07:00
|
|
|
}
|
|
|
|
|
2018-11-26 06:35:24 -08:00
|
|
|
/// The result of `HoneyBadger` handling an input or a message.
|
2018-07-31 13:27:22 -07:00
|
|
|
pub type Result<T> = ::std::result::Result<T, Error>;
|
2018-12-18 07:17:46 -08:00
|
|
|
|
|
|
|
/// Faults detectable from receiving honey badger messages
|
|
|
|
#[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>;
|