fn flush_cache(&mut self, tick: bool) -> Result<()> {
        // check_tick_height is called before flush cache, so it cannot overrun the bank
        // so a bank that is so late that it's slot fully generated before it starts recording
        // will fail instead of broadcasting any ticks
        let working_bank = self
            .working_bank
            .as_ref()
            .ok_or(PohRecorderError::MaxHeightReached)?;
        if self.tick_height < working_bank.min_tick_height {
            return Err(PohRecorderError::MinHeightNotReached);
        }
        if tick && self.tick_height == working_bank.min_tick_height {
            return Err(PohRecorderError::MinHeightNotReached);
        }

        let entry_count = self
            .tick_cache
            .iter()
            .take_while(|x| x.1 <= working_bank.max_tick_height)
            .count();
        let mut send_result: std::result::Result<(), SendError<WorkingBankEntry>> = Ok(());

        if entry_count > 0 {
            trace!(
                "flush_cache: bank_slot: {} tick_height: {} max: {} sending: {}",
                working_bank.bank.slot(),
                working_bank.bank.tick_height(),
                working_bank.max_tick_height,
                entry_count,
            );

            for tick in &self.tick_cache[..entry_count] {
                working_bank.bank.register_tick(&tick.0.hash);
                send_result = self.sender.send((working_bank.bank.clone(), tick.clone()));
                if send_result.is_err() {
                    break;
                }
            }
        }
        if self.tick_height >= working_bank.max_tick_height {
            info!(
                "poh_record: max_tick_height {} reached, clearing working_bank {}",
                working_bank.max_tick_height,
                working_bank.bank.slot()
            );
            self.start_bank = working_bank.bank.clone();
            let working_slot = self.start_slot();
            self.start_tick_height = working_slot * self.ticks_per_slot + 1;
            self.clear_bank();
        }
        if send_result.is_err() {
            info!("WorkingBank::sender disconnected {:?}", send_result);
            // revert the cache, but clear the working bank
            self.clear_bank();
        } else {
            // commit the flush
            let _ = self.tick_cache.drain(..entry_count);
        }

        Ok(())
    }
// Flush cache will delay flushing the cache for a bank until it past the WorkingBank::min_tick_height
// On a record flush will flush the cache at the WorkingBank::min_tick_height, since a record
// occurs after the min_tick_height was generated
Flush cache will delay flushing the cache for a bank until it past the WorkingBank::min_tick_height
On a record flush will flush the cache at the WorkingBank::min_tick_height, since a record
occurs after the min_tick_height was generated
Flush cache will delay flushing the cache for a bank until it past the WorkingBank :: min_tick_height On a record flush will flush the cache at the WorkingBank :: min_tick_height since a record occurs after the min_tick_height was generated
fn flush_cache(&mut self, tick: bool) -> Result<()> {
        // check_tick_height is called before flush cache, so it cannot overrun the bank
        // so a bank that is so late that it's slot fully generated before it starts recording
        // will fail instead of broadcasting any ticks
        let working_bank = self
            .working_bank
            .as_ref()
            .ok_or(PohRecorderError::MaxHeightReached)?;
        if self.tick_height < working_bank.min_tick_height {
            return Err(PohRecorderError::MinHeightNotReached);
        }
        if tick && self.tick_height == working_bank.min_tick_height {
            return Err(PohRecorderError::MinHeightNotReached);
        }
        let entry_count = self
            .tick_cache
            .iter()
            .take_while(|x| x.1 <= working_bank.max_tick_height)
            .count();
        let mut send_result: std::result::Result<(), SendError<WorkingBankEntry>> = Ok(());
        if entry_count > 0 {
            trace!(
                "flush_cache: bank_slot: {} tick_height: {} max: {} sending: {}",
                working_bank.bank.slot(),
                working_bank.bank.tick_height(),
                working_bank.max_tick_height,
                entry_count,
            );
            for tick in &self.tick_cache[..entry_count] {
                working_bank.bank.register_tick(&tick.0.hash);
                send_result = self.sender.send((working_bank.bank.clone(), tick.clone()));
                if send_result.is_err() {
                    break;
                }
            }
        }
        if self.tick_height >= working_bank.max_tick_height {
            info!(
                "poh_record: max_tick_height {} reached, clearing working_bank {}",
                working_bank.max_tick_height,
                working_bank.bank.slot()
            );
            self.start_bank = working_bank.bank.clone();
            let working_slot = self.start_slot();
            self.start_tick_height = working_slot * self.ticks_per_slot + 1;
            self.clear_bank();
        }
        if send_result.is_err() {
            info!("WorkingBank::sender disconnected {:?}", send_result);
            // revert the cache, but clear the working bank
            self.clear_bank();
        } else {
            // commit the flush
            let _ = self.tick_cache.drain(..entry_count);
        }
        Ok(())
    }
fn flush_cache ( & mut self , tick : bool ) -> Result < ( ) > { // check_tick_height is called before flush cache, so it cannot overrun the bank // so a bank that is so late that it's slot fully generated before it starts recording // will fail instead of broadcasting any ticks let working_bank = self . working_bank . as_ref ( ) . ok_or ( PohRecorderError :: MaxHeightReached ) ? ; if self . tick_height < working_bank . min_tick_height { return Err ( PohRecorderError :: MinHeightNotReached ) ; } if tick && self . tick_height == working_bank . min_tick_height { return Err ( PohRecorderError :: MinHeightNotReached ) ; } let entry_count = self . tick_cache . iter ( ) . take_while ( | x | x . 1 <= working_bank . max_tick_height ) . count ( ) ; let mut send_result : std :: result :: Result < ( ) , SendError < WorkingBankEntry > > = Ok ( ( ) ) ; if entry_count > 0 { trace ! ( " " working_bank bank slot ( ) working_bank bank tick_height ( ) working_bank max_tick_height entry_count ) ; for tick in & self . tick_cache [ .. entry_count ] { working_bank . bank . register_tick ( & tick . 0 . hash ) ; send_result = self . sender . send ( ( working_bank . bank . clone ( ) , tick . clone ( ) ) ) ; if send_result . is_err ( ) { break ; } } } if self . tick_height >= working_bank . max_tick_height { info ! ( " " working_bank max_tick_height working_bank bank slot ( ) ) ; self . start_bank = working_bank . bank . clone ( ) ; let working_slot = self . start_slot ( ) ; self . start_tick_height = working_slot * self . ticks_per_slot + 1 ; self . clear_bank ( ) ; } if send_result . is_err ( ) { info ! ( " " send_result ) ; // revert the cache, but clear the working bank self . clear_bank ( ) ; } else { // commit the flush let _ = self . tick_cache . drain ( .. entry_count ) ; } Ok ( ( ) ) }
Flush cache will delay flushing the cache for a bank until it past the WorkingBank::min_tick_height
On a record flush will flush the cache at the WorkingBank::min_tick_height, since a record
occurs after the min_tick_height was generated
Flush cache will delay flushing the cache for a bank until it past the WorkingBank :: min_tick_height On a record flush will flush the cache at the WorkingBank :: min_tick_height since a record occurs after the min_tick_height was generated
&mut self
tick
bool