finality_grandpa::vote_graph

Struct VoteGraph

Source
pub struct VoteGraph<H: Ord + Eq, N, V> { /* private fields */ }
Expand description

Maintains a DAG of blocks in the chain which have votes attached to them, and vote data which is accumulated along edges.

Implementations§

Source§

impl<H, N, V> VoteGraph<H, N, V>
where H: Eq + Clone + Ord + Debug, V: for<'a> AddAssign<&'a V> + Default + Clone + Debug, N: Copy + Debug + BlockNumberOps,

Source

pub fn new(base_hash: H, base_number: N, base_node: V) -> Self

Create a new VoteGraph with base node as given.

Source

pub fn base(&self) -> (H, N)

Get the base block.

Source

pub fn adjust_base(&mut self, ancestry_proof: &[H])

Adjust the base of the graph. The new base must be an ancestor of the old base.

Provide an ancestry proof from the old base to the new. The proof should be in reverse order from the old base’s parent.

Source

pub fn insert<C: Chain<H, N>, W>( &mut self, hash: H, number: N, vote: W, chain: &C, ) -> Result<(), Error>
where V: for<'a> AddAssign<&'a W>,

Insert a vote with given value into the graph at given hash and number.

Source

pub fn find_ancestor<F>( &self, hash: H, number: N, condition: F, ) -> Option<(H, N)>
where F: Fn(&V) -> bool,

Find the block with the highest block number in the chain with the given head which fulfills the given condition.

Returns None if the given head is not in the graph or no node fulfills the given condition.

Source

pub fn cumulative_vote<'a>(&'a self, hash: H, number: N) -> V

Find the total vote on a given block.

Source

pub fn find_ghost<'a, F>( &'a self, current_best: Option<(H, N)>, condition: F, ) -> Option<(H, N)>
where F: Fn(&V) -> bool,

Find the best GHOST descendent of the given block. Pass a closure used to evaluate the cumulative vote value.

The GHOST (hash, number) returned will be the block with highest number for which the cumulative votes of descendents and itself causes the closure to evaluate to true.

This assumes that the evaluation closure is one which returns true for at most a single descendent of a block, in that only one fork of a block can be “heavy” enough to trigger the threshold.

Returns None when the given current_best does not fulfill the condition.

Auto Trait Implementations§

§

impl<H, N, V> Freeze for VoteGraph<H, N, V>
where H: Freeze, N: Freeze,

§

impl<H, N, V> RefUnwindSafe for VoteGraph<H, N, V>

§

impl<H, N, V> Send for VoteGraph<H, N, V>
where H: Send, N: Send, V: Send,

§

impl<H, N, V> Sync for VoteGraph<H, N, V>
where H: Sync, N: Sync, V: Sync,

§

impl<H, N, V> Unpin for VoteGraph<H, N, V>
where H: Unpin, N: Unpin,

§

impl<H, N, V> UnwindSafe for VoteGraph<H, N, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.