[][src]Struct core_cbc_casper::justification::LatestMessagesHonest

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

Set of latest honest messages for each validator. Works like LatestMessages but ignores equivocations.

Example

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

use core_cbc_casper::justification::{Justification, LatestMessages, LatestMessagesHonest};
use core_cbc_casper::message::Message;
use core_cbc_casper::VoteCount;

use std::collections::HashSet;
use std::iter::FromIterator;

let mut justification = Justification::empty();

let message_0 = Message::new(0, justification.clone(), VoteCount { yes: 1, no: 0 });
justification.insert(message_0.clone());
assert_eq!(
    HashSet::<&Message<_>>::from_iter(LatestMessagesHonest::from_latest_messages(
        &LatestMessages::from(&justification),
        &HashSet::new(),
    ).iter()),
    HashSet::from_iter(vec![&message_0]),
);

// message_1 will replace message_0 in the LatestMessagesHonest.
let message_1 = Message::new(0, justification.clone(), VoteCount { yes: 2, no: 0 });
justification.insert(message_1.clone());
assert_eq!(
    HashSet::<&Message<_>>::from_iter(LatestMessagesHonest::from_latest_messages(
        &LatestMessages::from(&justification),
        &HashSet::new(),
    ).iter()),
    HashSet::from_iter(vec![&message_1]),
);

// As the validator is no longer honest, his messages are ignored.
let message_2 = Message::new(0, justification.clone(), VoteCount { yes: 3, no: 0 });
let message_3 = Message::new(0, justification.clone(), VoteCount { yes: 2, no: 1 });
justification.insert(message_2.clone());
justification.insert(message_3.clone());
assert_eq!(
    HashSet::<&Message<_>>::from_iter(LatestMessagesHonest::from_latest_messages(
        &LatestMessages::from(&justification),
        &HashSet::new(),
    ).iter()),
    HashSet::from_iter(vec![]),
);

Methods

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

pub fn remove(&mut self, validator: &E::ValidatorName)[src]

Removes the messages from a validator.

pub fn from_latest_messages(
    latest_messages: &LatestMessages<E>,
    equivocators: &HashSet<E::ValidatorName>
) -> Self
[src]

Filters the latest messages to retrieve the latest honest messages and remove equivocators.

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

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

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

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

Trait Implementations

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

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

Auto Trait Implementations

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

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

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

impl<E> Unpin for LatestMessagesHonest<E>

impl<E> UnwindSafe for LatestMessagesHonest<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.