/// If a beacon share should be proposed, propose it.
If a beacon share should be proposed, propose it.
If a beacon share should be proposed propose it .
pub fn on_state_change(&self, pool: &PoolReader<'_>) -> Option<RandomBeaconShare> {
        trace!(self.log, "on_state_change");
        let my_node_id = self.replica_config.node_id;
        let height = pool.get_notarized_height();
        let beacon = pool.get_random_beacon(height)?;
        let next_height = height.increment();
        let next_beacon = pool.get_random_beacon(next_height);
        match self.membership.node_belongs_to_threshold_committee(
            my_node_id,
            next_height,
            RandomBeacon::committee(),
        ) {
            Err(MembershipError::RegistryClientError(_)) => None,
            Err(MembershipError::NodeNotFound(_)) => {
                panic!("This node does not belong to this subnet")
            }
            Err(MembershipError::UnableToRetrieveDkgSummary(h)) => {
                error!(
                    self.log,
                    "Couldn't find transcript at height {} with finalized height {} and CUP height {}",
                    h,
                    pool.get_finalized_height(),
                    pool.get_catch_up_height()
                );
                None
            }
            Ok(is_beacon_maker)
                if is_beacon_maker
                    && next_beacon.is_none()
                    && !pool
                        .get_random_beacon_shares(next_height)
                        .any(|s| s.signature.signer == my_node_id) =>
            {
                let content =
                    RandomBeaconContent::new(next_height, ic_crypto::crypto_hash(&beacon));
                // One might wonder whether it is appropriate to use the
                // dkg_id from the start_block at h to generate the
                // random beacon at height h. The reason this is
                // possible is because we actually generate the random
                // beacon at height h only after there exists a block at
                // height h, and we only use the random beacon at height
                // h-1 in the validation of blocks at height h.
                if let Some(transcript) =
                    active_low_threshold_transcript(pool.as_cache(), next_height)
                {
                    match self.crypto.sign(&content, my_node_id, transcript.dkg_id) {
                        Ok(signature) => Some(RandomBeaconShare { content, signature }),
                        Err(err) => {
                            error!(self.log, "Couldn't create a signature: {:?}", err);
                            None
                        }
                    }
                } else {
                    error!(
                        self.log,
                        "Couldn't find the transcript at height {}", height
                    );
                    None
                }
            }
            _ => None,
        }
    }
pub fn on_state_change ( & self , pool : & PoolReader < ' _ > ) -> Option < RandomBeaconShare > { trace ! ( self log " " ) ; let my_node_id = self . replica_config . node_id ; let height = pool . get_notarized_height ( ) ; let beacon = pool . get_random_beacon ( height ) ? ; let next_height = height . increment ( ) ; let next_beacon = pool . get_random_beacon ( next_height ) ; match self . membership . node_belongs_to_threshold_committee ( my_node_id , next_height , RandomBeacon :: committee ( ) , ) { Err ( MembershipError :: RegistryClientError ( _ ) ) => None , Err ( MembershipError :: NodeNotFound ( _ ) ) => { panic ! ( " " ) } Err ( MembershipError :: UnableToRetrieveDkgSummary ( h ) ) => { error ! ( self log " " h pool get_finalized_height ( ) pool get_catch_up_height ( ) ) ; None } Ok ( is_beacon_maker ) if is_beacon_maker && next_beacon . is_none ( ) && ! pool . get_random_beacon_shares ( next_height ) . any ( | s | s . signature . signer == my_node_id ) => { let content = RandomBeaconContent :: new ( next_height , ic_crypto :: crypto_hash ( & beacon ) ) ; // One might wonder whether it is appropriate to use the // dkg_id from the start_block at h to generate the // random beacon at height h. The reason this is // possible is because we actually generate the random // beacon at height h only after there exists a block at // height h, and we only use the random beacon at height // h-1 in the validation of blocks at height h. if let Some ( transcript ) = active_low_threshold_transcript ( pool . as_cache ( ) , next_height ) { match self . crypto . sign ( & content , my_node_id , transcript . dkg_id ) { Ok ( signature ) => Some ( RandomBeaconShare { content , signature } ) , Err ( err ) => { error ! ( self log " " err ) ; None } } } else { error ! ( self log " " height ) ; None } } _ => None , } }
If a beacon share should be proposed, propose it.
If a beacon share should be proposed propose it .
&self
pool
&PoolReader<'_>