// Validates all unvalidated artifacts and returns corresponding change set.
Validates all unvalidated artifacts and returns corresponding change set.
Validates all unvalidated artifacts and returns corresponding change set .
fn validate(
        &self,
        consensus_cache: &dyn ConsensusPoolCache,
        certification_pool: &dyn CertificationPool,
        state_hashes: &[(Height, CryptoHashOfPartialState)],
    ) -> ChangeSet {
        // Iterate over all state hashes, obtain list of corresponding unvalidated
        // artifacts by the height and try to verify their signatures.
        state_hashes
            .iter()
            .flat_map(|(height, hash)| -> Box<dyn Iterator<Item = ChangeAction>> {
                // First we check if we have any valid full certification available for the
                // given height and if yes, our job is done for this height.
                let mut cert_change_set = Vec::new();
                for certification in
                    certification_pool.unvalidated_certifications_at_height(*height)
                {
                    if let Some(val) =
                        self.validate_certification(consensus_cache, hash, certification)
                    {
                        match val {
                            ChangeAction::MoveToValidated(_) => {
                                cert_change_set.push(val);
                                // We have found one valid certification for the given height, so
                                // our job is done.
                                return Box::new(cert_change_set.into_iter());
                            }
                            _ => {
                                cert_change_set.push(val);
                            }
                        }
                    }
                }
                Box::new(
                    certification_pool
                        .unvalidated_shares_at_height(*height)
                        .filter_map(move |share| {
                            self.validate_share(consensus_cache, certification_pool, hash, share)
                        })
                        .chain(cert_change_set.into_iter()),
                )
            })
            .collect()
    }
fn validate ( & self , consensus_cache : & dyn ConsensusPoolCache , certification_pool : & dyn CertificationPool , state_hashes : & [ ( Height , CryptoHashOfPartialState ) ] , ) -> ChangeSet { // Iterate over all state hashes, obtain list of corresponding unvalidated // artifacts by the height and try to verify their signatures. state_hashes . iter ( ) . flat_map ( | ( height , hash ) | -> Box < dyn Iterator < Item = ChangeAction > > { // First we check if we have any valid full certification available for the // given height and if yes, our job is done for this height. let mut cert_change_set = Vec :: new ( ) ; for certification in certification_pool . unvalidated_certifications_at_height ( * height ) { if let Some ( val ) = self . validate_certification ( consensus_cache , hash , certification ) { match val { ChangeAction :: MoveToValidated ( _ ) => { cert_change_set . push ( val ) ; // We have found one valid certification for the given height, so // our job is done. return Box :: new ( cert_change_set . into_iter ( ) ) ; } _ => { cert_change_set . push ( val ) ; } } } } Box :: new ( certification_pool . unvalidated_shares_at_height ( * height ) . filter_map ( move | share | { self . validate_share ( consensus_cache , certification_pool , hash , share ) } ) . chain ( cert_change_set . into_iter ( ) ) , ) } ) . collect ( ) }
Validates all unvalidated artifacts and returns corresponding change set.
Validates all unvalidated artifacts and returns corresponding change set .
&self
consensus_cache
&dyn ConsensusPoolCache
certification_pool
&dyn CertificationPool
state_hashes
&[(Height, CryptoHashOfPartialState)]