pub fn finalize<F, E>(
		&mut self,
		hash: &H,
		number: N,
		is_descendent_of: &F,
	) -> Result<FinalizationResult<V>, Error<E>>
		where E: std::error::Error,
			  F: Fn(&H, &H) -> Result<bool, E>
	{
		if let Some(ref best_finalized_number) = self.best_finalized_number {
			if number <= *best_finalized_number {
				return Err(Error::Revert);
			}
		}

		// check if one of the current roots is being finalized
		if let Some(root) = self.finalize_root(hash) {
			return Ok(FinalizationResult::Changed(Some(root)));
		}

		// make sure we're not finalizing a descendent of any root
		for root in self.roots.iter() {
			if number > root.number && is_descendent_of(&root.hash, hash)? {
				return Err(Error::UnfinalizedAncestor);
			}
		}

		// we finalized a block earlier than any existing root (or possibly
		// another fork not part of the tree). make sure to only keep roots that
		// are part of the finalized branch
		let mut changed = false;
		self.roots.retain(|root| {
			let retain = root.number > number && is_descendent_of(hash, &root.hash).unwrap_or(false);

			if !retain {
				changed = true;
			}

			retain
		});

		self.best_finalized_number = Some(number);

		if changed {
			Ok(FinalizationResult::Changed(None))
		} else {
			Ok(FinalizationResult::Unchanged)
		}
	}
/// Finalize a node in the tree. This method will make sure that the node
/// being finalized is either an existing root (an return its data), or a
/// node from a competing branch (not in the tree), tree pruning is done
/// accordingly. The given function `is_descendent_of` should return `true`
/// if the second hash (target) is a descendent of the first hash (base).
Finalize a node in the tree. This method will make sure that the node
being finalized is either an existing root (an return its data), or a
node from a competing branch (not in the tree), tree pruning is done
accordingly. The given function `is_descendent_of` should return `true`
if the second hash (target) is a descendent of the first hash (base).
Finalize a node in the tree . This method will make sure that the node being finalized is either an existing root ( an return its data ) or a node from a competing branch ( not in the tree ) tree pruning is done accordingly . The given function ` is_descendent_of ` should return ` true ` if the second hash ( target ) is a descendent of the first hash ( base ) .
pub fn finalize<F, E>(
		&mut self,
		hash: &H,
		number: N,
		is_descendent_of: &F,
	) -> Result<FinalizationResult<V>, Error<E>>
		where E: std::error::Error,
			  F: Fn(&H, &H) -> Result<bool, E>
	{
		if let Some(ref best_finalized_number) = self.best_finalized_number {
			if number <= *best_finalized_number {
				return Err(Error::Revert);
			}
		}
		// check if one of the current roots is being finalized
		if let Some(root) = self.finalize_root(hash) {
			return Ok(FinalizationResult::Changed(Some(root)));
		}
		// make sure we're not finalizing a descendent of any root
		for root in self.roots.iter() {
			if number > root.number && is_descendent_of(&root.hash, hash)? {
				return Err(Error::UnfinalizedAncestor);
			}
		}
		// we finalized a block earlier than any existing root (or possibly
		// another fork not part of the tree). make sure to only keep roots that
		// are part of the finalized branch
		let mut changed = false;
		self.roots.retain(|root| {
			let retain = root.number > number && is_descendent_of(hash, &root.hash).unwrap_or(false);
			if !retain {
				changed = true;
			}
			retain
		});
		self.best_finalized_number = Some(number);
		if changed {
			Ok(FinalizationResult::Changed(None))
		} else {
			Ok(FinalizationResult::Unchanged)
		}
	}
pub fn finalize < F , E > ( & mut self , hash : & H , number : N , is_descendent_of : & F , ) -> Result < FinalizationResult < V > , Error < E > > where E : std :: error :: Error , F : Fn ( & H , & H ) -> Result < bool , E > { if let Some ( ref best_finalized_number ) = self . best_finalized_number { if number <= * best_finalized_number { return Err ( Error :: Revert ) ; } } // check if one of the current roots is being finalized if let Some ( root ) = self . finalize_root ( hash ) { return Ok ( FinalizationResult :: Changed ( Some ( root ) ) ) ; } // make sure we're not finalizing a descendent of any root for root in self . roots . iter ( ) { if number > root . number && is_descendent_of ( & root . hash , hash ) ? { return Err ( Error :: UnfinalizedAncestor ) ; } } // we finalized a block earlier than any existing root (or possibly // another fork not part of the tree). make sure to only keep roots that // are part of the finalized branch let mut changed = false ; self . roots . retain ( | root | { let retain = root . number > number && is_descendent_of ( hash , & root . hash ) . unwrap_or ( false ) ; if ! retain { changed = true ; } retain } ) ; self . best_finalized_number = Some ( number ) ; if changed { Ok ( FinalizationResult :: Changed ( None ) ) } else { Ok ( FinalizationResult :: Unchanged ) } }
Finalize a node in the tree.
Finalize a node in the tree .
&mut self
hash
&H
number
N
is_descendent_of
&F
&mut self
hash
&H
number
N
is_descendent_of
&F