[][src]Struct core_cbc_casper::blockchain::Block

pub struct Block<D: BlockData>(_);

Simplest structure of a block with a prevblock pointer for running Casper on a blockchain. The data contained in these blocks must implement the BlockData trait.

This structure implements the Estimator trait and uses the GHOST algorithm defined in the paper for the estimate function.

Example

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

use core_cbc_casper::blockchain::Block;
use core_cbc_casper::justification::Justification;
use core_cbc_casper::message::Message;
use core_cbc_casper::ValidatorNameBlockData;

let message = Message::new(
    0,
    Justification::empty(),
    Block::new(None, ValidatorNameBlockData::new(1)),
);
let block_1 = Block::from(&message);
let block_2 = Block::new(Some(block_1.clone()), ValidatorNameBlockData::new(2));
assert!(block_1.is_member(&block_2));
assert!(Block::from(&message).is_member(&block_1));
assert!(Block::from(&message).is_member(&block_2));
assert!(!block_2.is_member(&block_1));
assert!(!block_2.is_member(&Block::from(&message)));

Methods

impl<D: BlockData> Block<D>[src]

pub fn new(prevblock: Option<Block<D>>, data: D) -> Self[src]

pub fn from_prevblock_message(
    prevblock_message: Option<Message<Block<D>>>,
    incomplete_block: Block<D>
) -> Self
[src]

Creates a new block from a prevblock message and an incomplete block. An incomplete_block is a block with a None prevblock (i.e., Estimator) AND is not a genesis_block

pub fn is_member(&self, other: &Self) -> bool[src]

Mathematical definition of blockchain membership.

pub fn score<U: WeightUnit>(
    &self,
    latest_messages_honest: &LatestMessagesHonest<Self>,
    weights: &Weights<D::ValidatorName, U>
) -> U
[src]

Direct implementation of the score function from the paper. Contrary to the paper's definition, score directly uses the latest honest messages rather than the latest honest estimates and a protocol state. Source: https://github.com/cbc-casper/cbc-casper-paper/blob/acc66e2ba4461a005262e2d5f434fd2e30ef0ff3/examples.tex#L568

pub fn children<'z>(
    &self,
    protocol_state: &HashSet<&'z Self>
) -> HashSet<&'z Self>
[src]

Direct implementation of the children function from the paper. Contrary to the paper's definition, we are directly parsing blocks to filter children out of rather than taking the estimates out of messages. Source: https://github.com/cbc-casper/cbc-casper-paper/blob/acc66e2ba4461a005262e2d5f434fd2e30ef0ff3/examples.tex#L578

pub fn best_children<'z, U: WeightUnit + PartialOrd>(
    &self,
    protocol_state: &HashSet<&'z Self>,
    latest_messages_honest: &LatestMessagesHonest<Self>,
    weights: &Weights<D::ValidatorName, U>
) -> HashSet<&'z Self>
[src]

Direct implementation of the best children function from the paper. Source: https://github.com/cbc-casper/cbc-casper-paper/blob/acc66e2ba4461a005262e2d5f434fd2e30ef0ff3/examples.tex#L587

pub fn mathematical_ghost<U: WeightUnit + PartialOrd>(
    latest_messages_honest: &LatestMessagesHonest<Self>,
    weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
[src]

This function reconstructs the blocks tree from latest_messages_honest and uses those to return the block with highest score according to the definition 4.30 of the paper. Contrary to the paper's definition, it does not return a set in case of a tie but uses the blocks hashes to tie break. Source: https://github.com/cbc-casper/cbc-casper-paper/blob/acc66e2ba4461a005262e2d5f434fd2e30ef0ff3/examples.tex#L596

pub fn optimized_ghost<U: WeightUnit + PartialOrd>(
    latest_messages_honest: &LatestMessagesHonest<Self>,
    weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
[src]

This function reconstructs the blocks tree from latest_messages_honest and uses those to return the block with highest score according to the definition 4.30 of the paper. Contrary to the paper's definition, it does not return a set in case of a tie but uses the blocks hashes to tie break. It is an optimized version of mathematical_ghost.

pub fn safety_oracles<U: WeightUnit>(
    block: Block<D>,
    latest_messages_honest: &LatestMessagesHonest<Self>,
    equivocators: &HashSet<D::ValidatorName>,
    safety_oracle_threshold: U,
    weights: &Weights<D::ValidatorName, U>
) -> HashSet<BTreeSet<D::ValidatorName>>
[src]

pub fn prevblock(&self) -> Option<Self>[src]

Contrary to the paper's definition 4.24, this does not return Self for a genesis block but None. Source: https://github.com/cbc-casper/cbc-casper-paper/blob/acc66e2ba4461a005262e2d5f434fd2e30ef0ff3/examples.tex#L525

pub fn prev_block_as_ref(&self) -> Option<&Self>[src]

pub fn data(&self) -> D[src]

pub fn ncestor(&self, n: u32) -> Option<Self>[src]

Contrary to the paper's definition 4.25, this does not return Self for a genesis block but None. Source: https://github.com/cbc-casper/cbc-casper-paper/blob/acc66e2ba4461a005262e2d5f434fd2e30ef0ff3/examples.tex#L544

pub fn parse_blockchains(
    latest_messages: &LatestMessagesHonest<Self>
) -> (HashMap<Block<D>, HashSet<Block<D>>>, HashSet<Block<D>>, HashMap<Block<D>, <D as BlockData>::ValidatorName>)
[src]

Parses latest_messages to return a tuple containing:

  • a HashMap mapping blocks to their children;
  • a HashSet containing blocks with None as their prevblock (aka genesis blocks or finalized blocks);
  • a HashMap mapping blocks to their senders.

pub fn find_all_accessible_blocks(
    latest_messages: &LatestMessagesHonest<Self>
) -> HashSet<Block<D>>
[src]

pub fn old_ghost<U: WeightUnit>(
    latest_messages: &LatestMessagesHonest<Self>,
    validators_weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
[src]

Trait Implementations

impl<D: Clone + BlockData> Clone for Block<D>[src]

impl<D: BlockData> Debug for Block<D>[src]

impl<D: Eq + BlockData> Eq for Block<D>[src]

impl<D: BlockData> Estimator for Block<D>[src]

type Error = Error

type ValidatorName = D::ValidatorName

impl<'_, D: BlockData> From<&'_ Message<Block<D>>> for Block<D>[src]

impl<D: BlockData> Hash for Block<D>[src]

impl<D: BlockData> Id for Block<D>[src]

type ID = Hash

impl<D: BlockData> PartialEq<Block<D>> for Block<D>[src]

impl<D: BlockData> Serialize for Block<D>[src]

impl<D: BlockData> StructuralEq for Block<D>[src]

Auto Trait Implementations

impl<D> RefUnwindSafe for Block<D> where
    D: RefUnwindSafe

impl<D> Send for Block<D>

impl<D> Sync for Block<D>

impl<D> Unpin for Block<D>

impl<D> UnwindSafe for Block<D> where
    D: 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.