pub(crate) fn handle_timer(
        &mut self,
        timestamp: Timestamp,
        state: &State<C>,
        instance_id: C::InstanceId,
    ) -> Vec<Effect<C>> {
        if self.is_faulty(state) {
            warn!("Creator knows it's faulty. Won't create a message.");
            return vec![];
        }
        let mut effects = self.schedule_timer(timestamp, state);
        if self.earliest_unit_time(state) > timestamp {
            warn!(%timestamp, "skipping outdated timer event");
            return effects;
        }
        let r_exp = self.round_exp(state, timestamp);
        let r_id = state::round_id(timestamp, r_exp);
        let r_len = state::round_len(r_exp);
        // Only create new units if enough validators are online.
        if !self.paused && self.enough_validators_online(state, timestamp) {
            if timestamp == r_id && state.leader(r_id) == self.vidx {
                effects.extend(self.request_new_block(state, instance_id, timestamp));
                return effects;
            } else if timestamp == r_id + self.witness_offset(r_len) {
                let panorama = self.panorama_at(state, timestamp);
                if let Some(witness_unit) =
                    self.new_unit(panorama, timestamp, None, state, instance_id)
                {
                    if self
                        .latest_unit(state)
                        .map_or(true, |latest_unit| latest_unit.round_id() != r_id)
                    {
                        info!(round_id = %r_id, "sending witness in round with no proposal");
                    }
                    effects.push(Effect::NewVertex(ValidVertex(Vertex::Unit(witness_unit))));
                    return effects;
                }
            }
        }
        // We are not creating a new unit. Send a ping once per maximum-length round, to show that
        // we're online.
        let one_max_round_ago = timestamp.saturating_sub(state.params().max_round_length());
        if !state.has_ping(self.vidx, one_max_round_ago + 1.into()) {
            warn!(%timestamp, "too many validators offline, sending ping");
            effects.push(self.send_ping(timestamp, instance_id));
        }
        effects
    }
/// Returns actions a validator needs to take at the specified `timestamp`, with the given
/// protocol `state`.
Returns actions a validator needs to take at the specified `timestamp`, with the given
protocol `state`.
Returns actions a validator needs to take at the specified ` timestamp ` with the given protocol ` state ` .
pub(crate) fn handle_timer(
        &mut self,
        timestamp: Timestamp,
        state: &State<C>,
        instance_id: C::InstanceId,
    ) -> Vec<Effect<C>> {
        if self.is_faulty(state) {
            warn!("Creator knows it's faulty. Won't create a message.");
            return vec![];
        }
        let mut effects = self.schedule_timer(timestamp, state);
        if self.earliest_unit_time(state) > timestamp {
            warn!(%timestamp, "skipping outdated timer event");
            return effects;
        }
        let r_exp = self.round_exp(state, timestamp);
        let r_id = state::round_id(timestamp, r_exp);
        let r_len = state::round_len(r_exp);
        // Only create new units if enough validators are online.
        if !self.paused && self.enough_validators_online(state, timestamp) {
            if timestamp == r_id && state.leader(r_id) == self.vidx {
                effects.extend(self.request_new_block(state, instance_id, timestamp));
                return effects;
            } else if timestamp == r_id + self.witness_offset(r_len) {
                let panorama = self.panorama_at(state, timestamp);
                if let Some(witness_unit) =
                    self.new_unit(panorama, timestamp, None, state, instance_id)
                {
                    if self
                        .latest_unit(state)
                        .map_or(true, |latest_unit| latest_unit.round_id() != r_id)
                    {
                        info!(round_id = %r_id, "sending witness in round with no proposal");
                    }
                    effects.push(Effect::NewVertex(ValidVertex(Vertex::Unit(witness_unit))));
                    return effects;
                }
            }
        }
        // We are not creating a new unit. Send a ping once per maximum-length round, to show that
        // we're online.
        let one_max_round_ago = timestamp.saturating_sub(state.params().max_round_length());
        if !state.has_ping(self.vidx, one_max_round_ago + 1.into()) {
            warn!(%timestamp, "too many validators offline, sending ping");
            effects.push(self.send_ping(timestamp, instance_id));
        }
        effects
    }
pub ( crate ) fn handle_timer ( & mut self , timestamp : Timestamp , state : & State < C > , instance_id : C :: InstanceId , ) -> Vec < Effect < C > > { if self . is_faulty ( state ) { warn ! ( " " ) ; return vec ! [ ] ; } let mut effects = self . schedule_timer ( timestamp , state ) ; if self . earliest_unit_time ( state ) > timestamp { warn ! ( timestamp " " ) ; return effects ; } let r_exp = self . round_exp ( state , timestamp ) ; let r_id = state :: round_id ( timestamp , r_exp ) ; let r_len = state :: round_len ( r_exp ) ; // Only create new units if enough validators are online. if ! self . paused && self . enough_validators_online ( state , timestamp ) { if timestamp == r_id && state . leader ( r_id ) == self . vidx { effects . extend ( self . request_new_block ( state , instance_id , timestamp ) ) ; return effects ; } else if timestamp == r_id + self . witness_offset ( r_len ) { let panorama = self . panorama_at ( state , timestamp ) ; if let Some ( witness_unit ) = self . new_unit ( panorama , timestamp , None , state , instance_id ) { if self . latest_unit ( state ) . map_or ( true , | latest_unit | latest_unit . round_id ( ) != r_id ) { info ! ( round_id r_id " " ) ; } effects . push ( Effect :: NewVertex ( ValidVertex ( Vertex :: Unit ( witness_unit ) ) ) ) ; return effects ; } } } // We are not creating a new unit. Send a ping once per maximum-length round, to show that // we're online. let one_max_round_ago = timestamp . saturating_sub ( state . params ( ) . max_round_length ( ) ) ; if ! state . has_ping ( self . vidx , one_max_round_ago + 1 . into ( ) ) { warn ! ( timestamp " " ) ; effects . push ( self . send_ping ( timestamp , instance_id ) ) ; } effects }
Returns actions a validator needs to take at the specified `timestamp`, with the given
protocol `state`.
Returns actions a validator needs to take at the specified ` timestamp ` with the given protocol ` state ` .
&mut self
timestamp
Timestamp
state
&State<C>
instance_id
C::InstanceId
&mut self
timestamp
Timestamp
state
&State<C>
instance_id
C::InstanceId