/// 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.
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.
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 .
pub fn find_ghost<'a, F>(&'a self, current_best: Option<(H, N)>, condition: F) -> Option<(H, N)>
	where
		F: Fn(&V) -> bool,
	{
		let entries = &self.entries;
		let get_node = |hash: &_| -> &'a _ {
			entries
				.get(hash)
				.expect("node either base or referenced by other in graph; qed")
		};
		let (mut node_key, mut force_constrain) = current_best
			.clone()
			.and_then(|(hash, number)| match self.find_containing_nodes(hash.clone(), number) {
				None => Some((hash, false)),
				Some(ref x) if !x.is_empty() => {
					let ancestor = get_node(&x[0])
						.ancestor_node()
						.expect("node containing non-node in history always has ancestor; qed");
					Some((ancestor, true))
				},
				Some(_) => None,
			})
			.unwrap_or_else(|| (self.base.clone(), false));
		let mut active_node = get_node(&node_key);
		if !condition(&active_node.cumulative_vote) {
			return None
		}
		// breadth-first search starting from this node.
		loop {
			let next_descendent = active_node
				.descendents
				.iter()
				.map(|d| (d.clone(), get_node(d)))
				.filter(|&(_, node)| {
					// take only descendents with our block in the ancestry.
					if let (true, Some(&(ref h, n))) = (force_constrain, current_best.as_ref()) {
						node.in_direct_ancestry(h, n).unwrap_or(false)
					} else {
						true
					}
				})
				.find(|&(_, node)| condition(&node.cumulative_vote));
			match next_descendent {
				Some((key, node)) => {
					// once we've made at least one hop, we don't need to constrain
					// ancestry anymore.
					force_constrain = false;
					node_key = key;
					active_node = node;
				},
				None => break,
			}
		}
		// active_node and node_key now correspond to the vote-node with enough cumulative votes.
		// its descendents comprise frontier of vote-nodes which individually don't have enough votes
		// to pass the threshold but some subset of them join either at `active_node`'s block or at some
		// descendent block of it, giving that block sufficient votes.
		self.ghost_find_merge_point(
			node_key,
			active_node,
			if force_constrain { current_best } else { None },
			condition,
		)
		.best()
	}
pub fn find_ghost < ' a , F > ( & ' a self , current_best : Option < ( H , N ) > , condition : F ) -> Option < ( H , N ) > where F : Fn ( & V ) -> bool , { let entries = & self . entries ; let get_node = | hash : & _ | -> & ' a _ { entries . get ( hash ) . expect ( " " ) } ; let ( mut node_key , mut force_constrain ) = current_best . clone ( ) . and_then ( | ( hash , number ) | match self . find_containing_nodes ( hash . clone ( ) , number ) { None => Some ( ( hash , false ) ) , Some ( ref x ) if ! x . is_empty ( ) => { let ancestor = get_node ( & x [ 0 ] ) . ancestor_node ( ) . expect ( " " ) ; Some ( ( ancestor , true ) ) } , Some ( _ ) => None , } ) . unwrap_or_else ( | | ( self . base . clone ( ) , false ) ) ; let mut active_node = get_node ( & node_key ) ; if ! condition ( & active_node . cumulative_vote ) { return None } // breadth-first search starting from this node. loop { let next_descendent = active_node . descendents . iter ( ) . map ( | d | ( d . clone ( ) , get_node ( d ) ) ) . filter ( | & ( _ , node ) | { // take only descendents with our block in the ancestry. if let ( true , Some ( & ( ref h , n ) ) ) = ( force_constrain , current_best . as_ref ( ) ) { node . in_direct_ancestry ( h , n ) . unwrap_or ( false ) } else { true } } ) . find ( | & ( _ , node ) | condition ( & node . cumulative_vote ) ) ; match next_descendent { Some ( ( key , node ) ) => { // once we've made at least one hop, we don't need to constrain // ancestry anymore. force_constrain = false ; node_key = key ; active_node = node ; } , None => break , } } // active_node and node_key now correspond to the vote-node with enough cumulative votes. // its descendents comprise frontier of vote-nodes which individually don't have enough votes // to pass the threshold but some subset of them join either at `active_node`'s block or at some // descendent block of it, giving that block sufficient votes. self . ghost_find_merge_point ( node_key , active_node , if force_constrain { current_best } else { None } , condition , ) . best ( ) }
Find the best GHOST descendent of the given block.
Find the best GHOST descendent of the given block .
&'a self
current_best
Option<(H, N)>
condition
F