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> RefUnwindSafe for VoteGraph<H, N, V>where H: RefUnwindSafe, N: RefUnwindSafe, V: RefUnwindSafe,

§

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>where H: UnwindSafe + RefUnwindSafe, N: UnwindSafe + RefUnwindSafe, V: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.