pub(crate) fn run<'a>(
        &'a mut self,
        highway: &'a Highway<C>,
    ) -> Result<impl Iterator<Item = FinalizedBlock<C>> + 'a, FttExceeded> {
        let state = highway.state();
        let fault_w = state.faulty_weight();
        if fault_w >= self.ftt || fault_w > (state.total_weight() - Weight(1)) / 2 {
            warn!(panorama = ?state.panorama(), "fault tolerance threshold exceeded");
            return Err(FttExceeded(fault_w));
        }
        Ok(iter::from_fn(move || {
            let bhash = self.next_finalized(state)?;
            // Safe to unwrap: Index exists, since we have units from them.
            let to_id = |vidx: ValidatorIndex| highway.validators().id(vidx).unwrap().clone();
            let block = state.block(bhash);
            let unit = state.unit(bhash);
            let terminal_block_data = state
                .is_terminal_block(bhash)
                .then(|| Self::create_terminal_block_data(bhash, unit, highway));
            let finalized_block = FinalizedBlock {
                value: block.value.clone(),
                timestamp: unit.timestamp,
                relative_height: block.height,
                terminal_block_data,
                equivocators: unit.panorama.iter_faulty().map(to_id).collect(),
                proposer: to_id(unit.creator),
            };
            trace!(panorama = ?state.panorama(), ?finalized_block, "finality detected");
            Some(finalized_block)
        }))
    }
/// Returns all blocks that have been finalized since the last call.
Returns all blocks that have been finalized since the last call.
Returns all blocks that have been finalized since the last call .
pub(crate) fn run<'a>(
        &'a mut self,
        highway: &'a Highway<C>,
    ) -> Result<impl Iterator<Item = FinalizedBlock<C>> + 'a, FttExceeded> {
        let state = highway.state();
        let fault_w = state.faulty_weight();
        if fault_w >= self.ftt || fault_w > (state.total_weight() - Weight(1)) / 2 {
            warn!(panorama = ?state.panorama(), "fault tolerance threshold exceeded");
            return Err(FttExceeded(fault_w));
        }
        Ok(iter::from_fn(move || {
            let bhash = self.next_finalized(state)?;
            // Safe to unwrap: Index exists, since we have units from them.
            let to_id = |vidx: ValidatorIndex| highway.validators().id(vidx).unwrap().clone();
            let block = state.block(bhash);
            let unit = state.unit(bhash);
            let terminal_block_data = state
                .is_terminal_block(bhash)
                .then(|| Self::create_terminal_block_data(bhash, unit, highway));
            let finalized_block = FinalizedBlock {
                value: block.value.clone(),
                timestamp: unit.timestamp,
                relative_height: block.height,
                terminal_block_data,
                equivocators: unit.panorama.iter_faulty().map(to_id).collect(),
                proposer: to_id(unit.creator),
            };
            trace!(panorama = ?state.panorama(), ?finalized_block, "finality detected");
            Some(finalized_block)
        }))
    }
pub ( crate ) fn run < ' a > ( & ' a mut self , highway : & ' a Highway < C > , ) -> Result < impl Iterator < Item = FinalizedBlock < C > > + ' a , FttExceeded > { let state = highway . state ( ) ; let fault_w = state . faulty_weight ( ) ; if fault_w >= self . ftt || fault_w > ( state . total_weight ( ) - Weight ( 1 ) ) / 2 { warn ! ( panorama state panorama ( ) " " ) ; return Err ( FttExceeded ( fault_w ) ) ; } Ok ( iter :: from_fn ( move | | { let bhash = self . next_finalized ( state ) ? ; // Safe to unwrap: Index exists, since we have units from them. let to_id = | vidx : ValidatorIndex | highway . validators ( ) . id ( vidx ) . unwrap ( ) . clone ( ) ; let block = state . block ( bhash ) ; let unit = state . unit ( bhash ) ; let terminal_block_data = state . is_terminal_block ( bhash ) . then ( | | Self :: create_terminal_block_data ( bhash , unit , highway ) ) ; let finalized_block = FinalizedBlock { value : block . value . clone ( ) , timestamp : unit . timestamp , relative_height : block . height , terminal_block_data , equivocators : unit . panorama . iter_faulty ( ) . map ( to_id ) . collect ( ) , proposer : to_id ( unit . creator ) , } ; trace ! ( panorama state panorama ( ) finalized_block " " ) ; Some ( finalized_block ) } ) ) }
Returns all blocks that have been finalized since the last call.
Returns all blocks that have been finalized since the last call .
&'a mut self
highway
&'a Highway<C>
&'a mut self
highway
&'a Highway<C>