[][src]Struct core_cbc_casper::justification::Justification

pub struct Justification<E: Estimator>(_);

This struct holds the set of the Message that justify the current message. It works like a Vec.

Example

Using the VoteCount type message type for brevity's sake.

use core_cbc_casper::justification::Justification;
use core_cbc_casper::message::Message;
use core_cbc_casper::VoteCount;

let message = VoteCount::create_vote_message(0, true);

let mut justification = Justification::empty();

justification.insert(message.clone());

assert_eq!(
    *justification.iter().next().unwrap().estimate(),
    VoteCount { yes: 1, no: 0 },
);

Methods

impl<E: Estimator> Justification<E>[src]

pub fn empty() -> Self[src]

Creates an empty justification.

pub fn from_messages<U: WeightUnit>(
    messages: Vec<Message<E>>,
    state: &mut State<E, U>
) -> Self
[src]

Creates and returns a new justification from a vector of Message and mutates the given validator::State with the updated state.

pub fn iter(&self) -> Iter<Message<E>>[src]

pub fn par_iter(&self) -> Iter<Message<E>>[src]

pub fn contains(&self, message: &Message<E>) -> bool[src]

pub fn len(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

pub fn insert(&mut self, message: Message<E>) -> bool[src]

This function checks if the message is already contained into the underlying Vec. If it is, it does nothing and returns false. Else, it will push the message in the Vec and returns true.

pub fn make_estimate<U: WeightUnit>(
    &self,
    equivocators: &HashSet<E::ValidatorName>,
    validators_weights: &Weights<E::ValidatorName, U>
) -> Result<E, E::Error>
[src]

Runs the estimator on the justification given the set of equivocators and validators' weights.

pub fn faulty_inserts<'a, U: WeightUnit>(
    &mut self,
    messages: &HashSet<&'a Message<E>>,
    state: &mut State<E, U>
) -> HashSet<&'a Message<E>>
[src]

Inserts messages to the justification, accepting up to the threshold faults by weight. In ordering to insert as much messages as possible, the input messages are sorted ascendingly by their validators' weight. Returns a HashSet of messages that got successfully included in the justification.

pub fn faulty_insert<U: WeightUnit>(
    &mut self,
    message: &Message<E>,
    state: &mut State<E, U>
) -> bool
[src]

This function makes no assumption on how to treat the equivocator. It adds the message to the justification only if it will not cross the fault tolerance threshold.

pub fn faulty_insert_with_slash<'a, U: WeightUnit>(
    &mut self,
    message: &Message<E>,
    state: &'a mut State<E, U>
) -> Result<bool, Error<'a, HashMap<E::ValidatorName, U>>>
[src]

This function sets the weight of an equivocator to zero right away (returned in validator::State) and add his message to the state, since his weight is null and doesn't count to the state fault weight anymore.

Trait Implementations

impl<E: Clone + Estimator> Clone for Justification<E>[src]

impl<E: Estimator> Debug for Justification<E>[src]

impl<E: Eq + Estimator> Eq for Justification<E>[src]

impl<'_, E: Estimator> From<&'_ Justification<E>> for LatestMessages<E>[src]

fn from(justification: &Justification<E>) -> Self[src]

Extracts the latest messages of each validator from a justification.

impl<E: Estimator> From<LatestMessagesHonest<E>> for Justification<E>[src]

impl<E: Hash + Estimator> Hash for Justification<E>[src]

impl<E: PartialEq + Estimator> PartialEq<Justification<E>> for Justification<E>[src]

impl<E: Estimator> StructuralEq for Justification<E>[src]

impl<E: Estimator> StructuralPartialEq for Justification<E>[src]

Auto Trait Implementations

impl<E> RefUnwindSafe for Justification<E> where
    E: RefUnwindSafe,
    <E as Estimator>::ValidatorName: RefUnwindSafe

impl<E> Send for Justification<E> where
    <E as Estimator>::ValidatorName: Send + Sync

impl<E> Sync for Justification<E> where
    <E as Estimator>::ValidatorName: Send + Sync

impl<E> Unpin for Justification<E>

impl<E> UnwindSafe for Justification<E> where
    E: RefUnwindSafe,
    <E as Estimator>::ValidatorName: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.