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(Error::PohRecorderError(PohRecorderError::MaxHeightReached))?;
        if self.tick_height < working_bank.min_tick_height {
            return Err(Error::PohRecorderError(
                PohRecorderError::MinHeightNotReached,
            ));
        }
        if tick && self.tick_height == working_bank.min_tick_height {
            return Err(Error::PohRecorderError(
                PohRecorderError::MinHeightNotReached,
            ));
        }

        let entry_count = self
            .tick_cache
            .iter()
            .take_while(|x| x.1 <= working_bank.max_tick_height)
            .count();
        let send_result = if entry_count > 0 {
            debug!(
                "flush_cache: bank_slot: {} tick_height: {} max: {} sending: {}",
                working_bank.bank.slot(),
                working_bank.bank.tick_height(),
                working_bank.max_tick_height,
                entry_count,
            );
            let cache = &self.tick_cache[..entry_count];
            for t in cache {
                working_bank.bank.register_tick(&t.0.hash);
            }
            self.sender
                .send((working_bank.bank.clone(), cache.to_vec()))
        } else {
            Ok(())
        };
        if self.tick_height >= working_bank.max_tick_height {
            // info!(
            //     "{}",
            //     Info(format!("poh_record: max_tick_height reached, setting working bank {} to None",
            //     working_bank.bank.slot()).to_string())
            // );
            let info:String = format!(
                "waterClockRecorder: max timmer reached, setting current treasury {} to None",
                working_bank.bank.slot()
            ).to_string();
            println!("{}", printLn(info, module_path!().to_string()));

            self.start_slot = working_bank.max_tick_height / working_bank.bank.ticks_per_slot();
            self.start_tick = (self.start_slot + 1) * working_bank.bank.ticks_per_slot();
            self.clear_bank();
        }
        if send_result.is_err() {
            // info!("{}", Info(format!("WorkingBank::sender disconnected {:?}", send_result).to_string()));
            println!("{}",
                printLn(
                    format!("WorkingBank::sender disconnected {:?}", send_result).to_string(),
                    module_path!().to_string()
                )
            );
            // 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(Error::PohRecorderError(PohRecorderError::MaxHeightReached))?;
        if self.tick_height < working_bank.min_tick_height {
            return Err(Error::PohRecorderError(
                PohRecorderError::MinHeightNotReached,
            ));
        }
        if tick && self.tick_height == working_bank.min_tick_height {
            return Err(Error::PohRecorderError(
                PohRecorderError::MinHeightNotReached,
            ));
        }
        let entry_count = self
            .tick_cache
            .iter()
            .take_while(|x| x.1 <= working_bank.max_tick_height)
            .count();
        let send_result = if entry_count > 0 {
            debug!(
                "flush_cache: bank_slot: {} tick_height: {} max: {} sending: {}",
                working_bank.bank.slot(),
                working_bank.bank.tick_height(),
                working_bank.max_tick_height,
                entry_count,
            );
            let cache = &self.tick_cache[..entry_count];
            for t in cache {
                working_bank.bank.register_tick(&t.0.hash);
            }
            self.sender
                .send((working_bank.bank.clone(), cache.to_vec()))
        } else {
            Ok(())
        };
        if self.tick_height >= working_bank.max_tick_height {
            // info!(
            //     "{}",
            //     Info(format!("poh_record: max_tick_height reached, setting working bank {} to None",
            //     working_bank.bank.slot()).to_string())
            // );
            let info:String = format!(
                "waterClockRecorder: max timmer reached, setting current treasury {} to None",
                working_bank.bank.slot()
            ).to_string();
            println!("{}", printLn(info, module_path!().to_string()));
            self.start_slot = working_bank.max_tick_height / working_bank.bank.ticks_per_slot();
            self.start_tick = (self.start_slot + 1) * working_bank.bank.ticks_per_slot();
            self.clear_bank();
        }
        if send_result.is_err() {
            // info!("{}", Info(format!("WorkingBank::sender disconnected {:?}", send_result).to_string()));
            println!("{}",
                printLn(
                    format!("WorkingBank::sender disconnected {:?}", send_result).to_string(),
                    module_path!().to_string()
                )
            );
            // 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 ( Error :: PohRecorderError ( PohRecorderError :: MaxHeightReached ) ) ? ; if self . tick_height < working_bank . min_tick_height { return Err ( Error :: PohRecorderError ( PohRecorderError :: MinHeightNotReached , ) ) ; } if tick && self . tick_height == working_bank . min_tick_height { return Err ( Error :: PohRecorderError ( PohRecorderError :: MinHeightNotReached , ) ) ; } let entry_count = self . tick_cache . iter ( ) . take_while ( | x | x . 1 <= working_bank . max_tick_height ) . count ( ) ; let send_result = if entry_count > 0 { debug ! ( " " working_bank bank slot ( ) working_bank bank tick_height ( ) working_bank max_tick_height entry_count ) ; let cache = & self . tick_cache [ .. entry_count ] ; for t in cache { working_bank . bank . register_tick ( & t . 0 . hash ) ; } self . sender . send ( ( working_bank . bank . clone ( ) , cache . to_vec ( ) ) ) } else { Ok ( ( ) ) } ; if self . tick_height >= working_bank . max_tick_height { // info!( //     "{}", //     Info(format!("poh_record: max_tick_height reached, setting working bank {} to None", //     working_bank.bank.slot()).to_string()) // ); let info : String = format ! ( " " working_bank bank slot ( ) ) . to_string ( ) ; println ! ( " " printLn ( info module_path ( ) to_string ( ) ) ) ; self . start_slot = working_bank . max_tick_height / working_bank . bank . ticks_per_slot ( ) ; self . start_tick = ( self . start_slot + 1 ) * working_bank . bank . ticks_per_slot ( ) ; self . clear_bank ( ) ; } if send_result . is_err ( ) { // info!("{}", Info(format!("WorkingBank::sender disconnected {:?}", send_result).to_string())); println ! ( " " printLn ( format ( " " send_result ) to_string ( ) module_path ( ) to_string ( ) ) ) ; // 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
&mut self
tick
bool