Struct finality_grandpa::vote_graph::VoteGraph
source · [−]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
sourceimpl<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,
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,
sourcepub fn new(base_hash: H, base_number: N, base_node: V) -> Self
pub fn new(base_hash: H, base_number: N, base_node: V) -> Self
Create a new VoteGraph
with base node as given.
sourcepub fn adjust_base(&mut self, ancestry_proof: &[H])
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.
sourcepub 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>,
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.
sourcepub fn find_ancestor<'a, F>(
&'a self,
hash: H,
number: N,
condition: F
) -> Option<(H, N)> where
F: Fn(&V) -> bool,
pub fn find_ancestor<'a, F>(
&'a 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.
sourcepub fn cumulative_vote<'a>(&'a self, hash: H, number: N) -> V
pub fn cumulative_vote<'a>(&'a self, hash: H, number: N) -> V
Find the total vote on a given block.
sourcepub fn find_ghost<'a, F>(
&'a self,
current_best: Option<(H, N)>,
condition: F
) -> Option<(H, N)> where
F: Fn(&V) -> bool,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more