[−][src]Struct core_cbc_casper::blockchain::Block
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]
prevblock_message: Option<Message<Block<D>>>,
incomplete_block: Block<D>
) -> Self
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]
&self,
latest_messages_honest: &LatestMessagesHonest<Self>,
weights: &Weights<D::ValidatorName, U>
) -> U
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]
&self,
protocol_state: &HashSet<&'z Self>
) -> HashSet<&'z Self>
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]
&self,
protocol_state: &HashSet<&'z Self>,
latest_messages_honest: &LatestMessagesHonest<Self>,
weights: &Weights<D::ValidatorName, U>
) -> HashSet<&'z Self>
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]
latest_messages_honest: &LatestMessagesHonest<Self>,
weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
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]
latest_messages_honest: &LatestMessagesHonest<Self>,
weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
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]
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>>
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]
latest_messages: &LatestMessagesHonest<Self>
) -> (HashMap<Block<D>, HashSet<Block<D>>>, HashSet<Block<D>>, HashMap<Block<D>, <D as BlockData>::ValidatorName>)
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]
latest_messages: &LatestMessagesHonest<Self>
) -> HashSet<Block<D>>
pub fn old_ghost<U: WeightUnit>(
latest_messages: &LatestMessagesHonest<Self>,
validators_weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
[src]
latest_messages: &LatestMessagesHonest<Self>,
validators_weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Error>
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
fn estimate<U: WeightUnit>(
latest_messages: &LatestMessagesHonest<Self>,
validators_weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Self::Error>
[src]
latest_messages: &LatestMessagesHonest<Self>,
validators_weights: &Weights<D::ValidatorName, U>
) -> Result<Self, Self::Error>
impl<'_, D: BlockData> From<&'_ Message<Block<D>>> for Block<D>
[src]
impl<D: BlockData> Hash for Block<D>
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<D: BlockData> Id for Block<D>
[src]
type ID = Hash
fn hash(data: &[u8]) -> Self::ID
[src]
fn serialize(&self) -> Vec<u8>
[src]
fn deserialize<'z>(bin: &'z [u8]) -> Result<Self, Error> where
Self: Sized + Deserialize<'z>,
[src]
Self: Sized + Deserialize<'z>,
fn id(&self) -> Self::ID
[src]
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,
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,
D: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,