pub fn finalize(&mut self) -> FinalizedBlock {
        let chains = mem::take(&mut self.chain_set);
        let mut chains = chains.into_iter();

        // extract best chain
        let mut best_chain = chains.next_back().expect("there's at least one chain");
        // extract the rest into side_chains so they can be mutated
        let side_chains = chains;

        // remove the lowest height block from the best_chain to be finalized
        let finalizing = best_chain.pop_root();

        // add best_chain back to `self.chain_set`
        if !best_chain.is_empty() {
            self.chain_set.insert(best_chain);
        }

        // for each remaining chain in side_chains
        for mut chain in side_chains {
            // remove the first block from `chain`
            let chain_start = chain.pop_root();
            // if block equals finalized_block
            if !chain.is_empty() && chain_start.hash == finalizing.hash {
                // add the chain back to `self.chain_set`
                self.chain_set.insert(chain);
            } else {
                // else discard `chain`
                drop(chain);
            }
        }

        self.update_metrics_for_chains();

        finalizing.into()
    }
/// Finalize the lowest height block in the non-finalized portion of the best
/// chain and update all side-chains to match.
Finalize the lowest height block in the non-finalized portion of the best
chain and update all side-chains to match.
Finalize the lowest height block in the non - finalized portion of the best chain and update all side - chains to match .
pub fn finalize(&mut self) -> FinalizedBlock {
        let chains = mem::take(&mut self.chain_set);
        let mut chains = chains.into_iter();
        // extract best chain
        let mut best_chain = chains.next_back().expect("there's at least one chain");
        // extract the rest into side_chains so they can be mutated
        let side_chains = chains;
        // remove the lowest height block from the best_chain to be finalized
        let finalizing = best_chain.pop_root();
        // add best_chain back to `self.chain_set`
        if !best_chain.is_empty() {
            self.chain_set.insert(best_chain);
        }
        // for each remaining chain in side_chains
        for mut chain in side_chains {
            // remove the first block from `chain`
            let chain_start = chain.pop_root();
            // if block equals finalized_block
            if !chain.is_empty() && chain_start.hash == finalizing.hash {
                // add the chain back to `self.chain_set`
                self.chain_set.insert(chain);
            } else {
                // else discard `chain`
                drop(chain);
            }
        }
        self.update_metrics_for_chains();
        finalizing.into()
    }
pub fn finalize ( & mut self ) -> FinalizedBlock { let chains = mem :: take ( & mut self . chain_set ) ; let mut chains = chains . into_iter ( ) ; // extract best chain let mut best_chain = chains . next_back ( ) . expect ( " " ) ; // extract the rest into side_chains so they can be mutated let side_chains = chains ; // remove the lowest height block from the best_chain to be finalized let finalizing = best_chain . pop_root ( ) ; // add best_chain back to `self.chain_set` if ! best_chain . is_empty ( ) { self . chain_set . insert ( best_chain ) ; } // for each remaining chain in side_chains for mut chain in side_chains { // remove the first block from `chain` let chain_start = chain . pop_root ( ) ; // if block equals finalized_block if ! chain . is_empty ( ) && chain_start . hash == finalizing . hash { // add the chain back to `self.chain_set` self . chain_set . insert ( chain ) ; } else { // else discard `chain` drop ( chain ) ; } } self . update_metrics_for_chains ( ) ; finalizing . into ( ) }
Finalize the lowest height block in the non-finalized portion of the best
chain and update all side-chains to match.
Finalize the lowest height block in the non - finalized portion of the best chain and update all side - chains to match .
&mut self