fn consider_block(
        &self,
        pool: &PoolReader<'_>,
        start_block: Block,
    ) -> Option<CatchUpPackageShare> {
        let height = start_block.height();

        // Skip if this node is not in the committee to make CUP shares
        let my_node_id = self.replica_config.node_id;
        if self.membership.node_belongs_to_threshold_committee(
            my_node_id,
            height,
            CatchUpPackage::committee(),
        ) != Ok(true)
        {
            return None;
        }

        // Skip if this node has already made a share
        if pool
            .get_catch_up_package_shares(height)
            .any(|share| share.signature.signer == my_node_id)
        {
            return None;
        }

        // Skip if random beacon does not exist for the height
        let random_beacon = pool.get_random_beacon(height)?;

        // Skip if the state referenced by finalization tip has not caught up to
        // this height. This is to increase the chance that states are available to
        // validate payloads at the chain tip.
        if pool.get_finalized_tip().context.certified_height < height {
            return None;
        }

        match self.state_manager.get_state_hash_at(height) {
            Err(StateHashError::Transient(StateNotCommittedYet(_))) => {
                // TODO: Setup a delay before retry
                debug!(
                    self.log,
                    "Cannot make CUP at height {} because state is not committed yet. Will retry",
                    height
                );
                None
            }
            Err(StateHashError::Transient(HashNotComputedYet(_))) => {
                debug!(self.log, "Cannot make CUP at height {} because state hash is not computed yet. Will retry", height);
                None
            }
            Err(StateHashError::Permanent(StateRemoved(_))) => {
                // This should never happen as we don't want to remove the state
                // for CUP before the hash is fetched.
                panic!(
		    "State at height {} had disappeared before we had a chance to make a CUP. This should not happen.",
		    height,
		);
            }
            Err(StateHashError::Permanent(StateNotFullyCertified(_))) => {
                panic!(
                    "Height {} is not a fully certified height. This should not happen.",
                    height,
                );
            }
            Ok(state_hash) => {
                let content = CatchUpContent::new(
                    HashedBlock::new(ic_crypto::crypto_hash, start_block),
                    HashedRandomBeacon::new(ic_crypto::crypto_hash, random_beacon),
                    state_hash,
                );
                let share_content = CatchUpShareContent::from(&content);
                if let Some(transcript) = active_high_threshold_transcript(pool.as_cache(), height)
                {
                    match self.crypto.sign(&content, my_node_id, transcript.dkg_id) {
                        Ok(signature) => {
                            // Caution: The log string below is checked in replica_determinism_test.
                            // Changing the string might break the test.
                            debug!(
                                self.log,
                                "Proposing a CatchUpPackageShare at height {}", height
                            );
                            Some(CatchUpPackageShare {
                                content: share_content,
                                signature,
                            })
                        }
                        Err(err) => {
                            error!(self.log, "Couldn't create a signature: {:?}", err);
                            None
                        }
                    }
                } else {
                    error!(self.log, "Couldn't find transcript at height {}", height);
                    None
                }
            }
        }
    }
/// Consider the provided block for the creation of a catch up package.
Consider the provided block for the creation of a catch up package.
Consider the provided block for the creation of a catch up package .
fn consider_block(
        &self,
        pool: &PoolReader<'_>,
        start_block: Block,
    ) -> Option<CatchUpPackageShare> {
        let height = start_block.height();
        // Skip if this node is not in the committee to make CUP shares
        let my_node_id = self.replica_config.node_id;
        if self.membership.node_belongs_to_threshold_committee(
            my_node_id,
            height,
            CatchUpPackage::committee(),
        ) != Ok(true)
        {
            return None;
        }
        // Skip if this node has already made a share
        if pool
            .get_catch_up_package_shares(height)
            .any(|share| share.signature.signer == my_node_id)
        {
            return None;
        }
        // Skip if random beacon does not exist for the height
        let random_beacon = pool.get_random_beacon(height)?;
        // Skip if the state referenced by finalization tip has not caught up to
        // this height. This is to increase the chance that states are available to
        // validate payloads at the chain tip.
        if pool.get_finalized_tip().context.certified_height < height {
            return None;
        }
        match self.state_manager.get_state_hash_at(height) {
            Err(StateHashError::Transient(StateNotCommittedYet(_))) => {
                // TODO: Setup a delay before retry
                debug!(
                    self.log,
                    "Cannot make CUP at height {} because state is not committed yet. Will retry",
                    height
                );
                None
            }
            Err(StateHashError::Transient(HashNotComputedYet(_))) => {
                debug!(self.log, "Cannot make CUP at height {} because state hash is not computed yet. Will retry", height);
                None
            }
            Err(StateHashError::Permanent(StateRemoved(_))) => {
                // This should never happen as we don't want to remove the state
                // for CUP before the hash is fetched.
                panic!(
		    "State at height {} had disappeared before we had a chance to make a CUP. This should not happen.",
		    height,
		);
            }
            Err(StateHashError::Permanent(StateNotFullyCertified(_))) => {
                panic!(
                    "Height {} is not a fully certified height. This should not happen.",
                    height,
                );
            }
            Ok(state_hash) => {
                let content = CatchUpContent::new(
                    HashedBlock::new(ic_crypto::crypto_hash, start_block),
                    HashedRandomBeacon::new(ic_crypto::crypto_hash, random_beacon),
                    state_hash,
                );
                let share_content = CatchUpShareContent::from(&content);
                if let Some(transcript) = active_high_threshold_transcript(pool.as_cache(), height)
                {
                    match self.crypto.sign(&content, my_node_id, transcript.dkg_id) {
                        Ok(signature) => {
                            // Caution: The log string below is checked in replica_determinism_test.
                            // Changing the string might break the test.
                            debug!(
                                self.log,
                                "Proposing a CatchUpPackageShare at height {}", height
                            );
                            Some(CatchUpPackageShare {
                                content: share_content,
                                signature,
                            })
                        }
                        Err(err) => {
                            error!(self.log, "Couldn't create a signature: {:?}", err);
                            None
                        }
                    }
                } else {
                    error!(self.log, "Couldn't find transcript at height {}", height);
                    None
                }
            }
        }
    }
fn consider_block ( & self , pool : & PoolReader < ' _ > , start_block : Block , ) -> Option < CatchUpPackageShare > { let height = start_block . height ( ) ; // Skip if this node is not in the committee to make CUP shares let my_node_id = self . replica_config . node_id ; if self . membership . node_belongs_to_threshold_committee ( my_node_id , height , CatchUpPackage :: committee ( ) , ) != Ok ( true ) { return None ; } // Skip if this node has already made a share if pool . get_catch_up_package_shares ( height ) . any ( | share | share . signature . signer == my_node_id ) { return None ; } // Skip if random beacon does not exist for the height let random_beacon = pool . get_random_beacon ( height ) ? ; // Skip if the state referenced by finalization tip has not caught up to // this height. This is to increase the chance that states are available to // validate payloads at the chain tip. if pool . get_finalized_tip ( ) . context . certified_height < height { return None ; } match self . state_manager . get_state_hash_at ( height ) { Err ( StateHashError :: Transient ( StateNotCommittedYet ( _ ) ) ) => { // TODO: Setup a delay before retry debug ! ( self log " " height ) ; None } Err ( StateHashError :: Transient ( HashNotComputedYet ( _ ) ) ) => { debug ! ( self log " " height ) ; None } Err ( StateHashError :: Permanent ( StateRemoved ( _ ) ) ) => { // This should never happen as we don't want to remove the state // for CUP before the hash is fetched. panic ! ( " " height ) ; } Err ( StateHashError :: Permanent ( StateNotFullyCertified ( _ ) ) ) => { panic ! ( " " height ) ; } Ok ( state_hash ) => { let content = CatchUpContent :: new ( HashedBlock :: new ( ic_crypto :: crypto_hash , start_block ) , HashedRandomBeacon :: new ( ic_crypto :: crypto_hash , random_beacon ) , state_hash , ) ; let share_content = CatchUpShareContent :: from ( & content ) ; if let Some ( transcript ) = active_high_threshold_transcript ( pool . as_cache ( ) , height ) { match self . crypto . sign ( & content , my_node_id , transcript . dkg_id ) { Ok ( signature ) => { // Caution: The log string below is checked in replica_determinism_test. // Changing the string might break the test. debug ! ( self log " " height ) ; Some ( CatchUpPackageShare { content : share_content , signature , } ) } Err ( err ) => { error ! ( self log " " err ) ; None } } } else { error ! ( self log " " height ) ; None } } } }
Consider the provided block for the creation of a catch up package.
Consider the provided block for the creation of a catch up package .
&self
pool
&PoolReader<'_>
start_block
Block
&self
pool
&PoolReader<'_>
start_block
Block