fn validate_dealings_for_dealer(
        &self,
        dkg_pool: &dyn DkgPool,
        configs: &BTreeMap<NiDkgId, NiDkgConfig>,
        dkg_start_height: Height,
        messages: Vec<&Message>,
    ) -> ChangeSet {
        // Because dealing generation is not entirely deterministic, it is
        // actually possible to recieve multiple dealings from an honest dealer.
        // As such, we simply try validating the first message in the list, and
        // get a result for that message. Other messages will be dealt with by
        // subsequent calls to this function.
        let message = if let Some(message) = messages.first() {
            message
        } else {
            return ChangeSet::new();
        };

        let message_dkg_id = message.content.dkg_id;

        // If the dealing refers to a DKG interval starting at a different height,
        // we skip it.
        if message_dkg_id.start_block_height != dkg_start_height {
            return ChangeSet::new();
        }

        // If the dealing refers a config which is not among the ongoing DKGs,
        // we reject it.
        let config = match configs.get(&message_dkg_id) {
            Some(config) => config,
            None => {
                return get_handle_invalid_change_action(
                    message,
                    format!(
                        "No DKG configuration for Id={:?} was found.",
                        message_dkg_id
                    ),
                )
                .into()
            }
        };

        let dealer_id = &message.signature.signer;

        // If the validated pool already contains this exact message, we skip it.
        if dkg_pool.get_validated().any(|item| item.eq(message)) {
            return ChangeSet::new();
        }

        // If the dealing comes from a non-dealer, reject it.
        if !config.dealers().get().contains(dealer_id) {
            return get_handle_invalid_change_action(
                message,
                format!("Replica with Id={:?} is not a dealer.", dealer_id),
            )
            .into();
        }

        // If we already have a dealing from this dealer, we simply remove the
        // message from the pool. Multiple distinguishable valid dealings can be
        // created by an honest node because dkg dealings are not deterministic,
        // and in the case of a restart it is possible it might forget that it
        // has already sent out a dealing. See
        // https://dfinity.atlassian.net/browse/CON-534 for more details.
        if contains_dkg_messages(dkg_pool, config, *dealer_id) {
            return ChangeSet::from(ChangeAction::RemoveFromUnvalidated((*message).clone()));
        }

        // Verify the signature and reject if it's invalid, or skip, if there was an
        // error.
        match self
            .crypto
            .verify(message, config.registry_version())
            .map_err(DkgMessageValidationError::from)
        {
            Ok(()) => (),
            Err(ValidationError::Permanent(err)) => {
                return get_handle_invalid_change_action(
                    message,
                    format!("Invalid signature: {:?}", err),
                )
                .into()
            }
            Err(ValidationError::Transient(err)) => {
                error!(
                    self.logger,
                    "Couldn't verify the signature of a DKG dealing: {:?}", err
                );
                return ChangeSet::new();
            }
        }

        // Verify the dealing and move to validated if it was successful,
        // reject, if it was rejected, or skip, if there was an error.
        match ic_interfaces::crypto::NiDkgAlgorithm::verify_dealing(
            &*self.crypto,
            config,
            *dealer_id,
            &message.content.dealing,
        )
        .map_err(DkgMessageValidationError::from)
        {
            Ok(()) => ChangeAction::MoveToValidated((*message).clone()).into(),
            Err(ValidationError::Permanent(err)) => get_handle_invalid_change_action(
                message,
                format!("Dealing verification failed: {:?}", err),
            )
            .into(),
            Err(ValidationError::Transient(err)) => {
                error!(self.logger, "Couldn't verify a DKG dealing: {:?}", err);
                ChangeSet::new()
            }
        }
    }
// Validates the DKG messages against the provided config.
//
// Invalidates the message if:
// - no DKG config among onging DKGs was found,
// - the dealer is not on the list of dealers wrt. DKG config,
// - the dealing signature is invalid,
// - the dealing is invalid.
//
// We simply remove the message from the pool if we already have a dealing
// from the dealer of the the message, because it is possible for honest
// dealers to provide multiple, non-identical dealings in certain
// situations. We skip the validation if an error occurs during the
// signature or dealing verification.
Validates the DKG messages against the provided config.
Invalidates the message if:
no DKG config among onging DKGs was found,
the dealer is not on the list of dealers wrt. DKG config,
the dealing signature is invalid,
the dealing is invalid.

We simply remove the message from the pool if we already have a dealing
from the dealer of the the message, because it is possible for honest
dealers to provide multiple, non-identical dealings in certain
situations. We skip the validation if an error occurs during the
signature or dealing verification.
Validates the DKG messages against the provided config . Invalidates the message if : no DKG config among onging DKGs was found the dealer is not on the list of dealers wrt . DKG config the dealing signature is invalid the dealing is invalid . We simply remove the message from the pool if we already have a dealing from the dealer of the the message because it is possible for honest dealers to provide multiple non - identical dealings in certain situations . We skip the validation if an error occurs during the signature or dealing verification .
fn validate_dealings_for_dealer(
        &self,
        dkg_pool: &dyn DkgPool,
        configs: &BTreeMap<NiDkgId, NiDkgConfig>,
        dkg_start_height: Height,
        messages: Vec<&Message>,
    ) -> ChangeSet {
        // Because dealing generation is not entirely deterministic, it is
        // actually possible to recieve multiple dealings from an honest dealer.
        // As such, we simply try validating the first message in the list, and
        // get a result for that message. Other messages will be dealt with by
        // subsequent calls to this function.
        let message = if let Some(message) = messages.first() {
            message
        } else {
            return ChangeSet::new();
        };
        let message_dkg_id = message.content.dkg_id;
        // If the dealing refers to a DKG interval starting at a different height,
        // we skip it.
        if message_dkg_id.start_block_height != dkg_start_height {
            return ChangeSet::new();
        }
        // If the dealing refers a config which is not among the ongoing DKGs,
        // we reject it.
        let config = match configs.get(&message_dkg_id) {
            Some(config) => config,
            None => {
                return get_handle_invalid_change_action(
                    message,
                    format!(
                        "No DKG configuration for Id={:?} was found.",
                        message_dkg_id
                    ),
                )
                .into()
            }
        };
        let dealer_id = &message.signature.signer;
        // If the validated pool already contains this exact message, we skip it.
        if dkg_pool.get_validated().any(|item| item.eq(message)) {
            return ChangeSet::new();
        }
        // If the dealing comes from a non-dealer, reject it.
        if !config.dealers().get().contains(dealer_id) {
            return get_handle_invalid_change_action(
                message,
                format!("Replica with Id={:?} is not a dealer.", dealer_id),
            )
            .into();
        }
        // If we already have a dealing from this dealer, we simply remove the
        // message from the pool. Multiple distinguishable valid dealings can be
        // created by an honest node because dkg dealings are not deterministic,
        // and in the case of a restart it is possible it might forget that it
        // has already sent out a dealing. See
        // https://dfinity.atlassian.net/browse/CON-534 for more details.
        if contains_dkg_messages(dkg_pool, config, *dealer_id) {
            return ChangeSet::from(ChangeAction::RemoveFromUnvalidated((*message).clone()));
        }
        // Verify the signature and reject if it's invalid, or skip, if there was an
        // error.
        match self
            .crypto
            .verify(message, config.registry_version())
            .map_err(DkgMessageValidationError::from)
        {
            Ok(()) => (),
            Err(ValidationError::Permanent(err)) => {
                return get_handle_invalid_change_action(
                    message,
                    format!("Invalid signature: {:?}", err),
                )
                .into()
            }
            Err(ValidationError::Transient(err)) => {
                error!(
                    self.logger,
                    "Couldn't verify the signature of a DKG dealing: {:?}", err
                );
                return ChangeSet::new();
            }
        }
        // Verify the dealing and move to validated if it was successful,
        // reject, if it was rejected, or skip, if there was an error.
        match ic_interfaces::crypto::NiDkgAlgorithm::verify_dealing(
            &*self.crypto,
            config,
            *dealer_id,
            &message.content.dealing,
        )
        .map_err(DkgMessageValidationError::from)
        {
            Ok(()) => ChangeAction::MoveToValidated((*message).clone()).into(),
            Err(ValidationError::Permanent(err)) => get_handle_invalid_change_action(
                message,
                format!("Dealing verification failed: {:?}", err),
            )
            .into(),
            Err(ValidationError::Transient(err)) => {
                error!(self.logger, "Couldn't verify a DKG dealing: {:?}", err);
                ChangeSet::new()
            }
        }
    }
fn validate_dealings_for_dealer ( & self , dkg_pool : & dyn DkgPool , configs : & BTreeMap < NiDkgId , NiDkgConfig > , dkg_start_height : Height , messages : Vec < & Message > , ) -> ChangeSet { // Because dealing generation is not entirely deterministic, it is // actually possible to recieve multiple dealings from an honest dealer. // As such, we simply try validating the first message in the list, and // get a result for that message. Other messages will be dealt with by // subsequent calls to this function. let message = if let Some ( message ) = messages . first ( ) { message } else { return ChangeSet :: new ( ) ; } ; let message_dkg_id = message . content . dkg_id ; // If the dealing refers to a DKG interval starting at a different height, // we skip it. if message_dkg_id . start_block_height != dkg_start_height { return ChangeSet :: new ( ) ; } // If the dealing refers a config which is not among the ongoing DKGs, // we reject it. let config = match configs . get ( & message_dkg_id ) { Some ( config ) => config , None => { return get_handle_invalid_change_action ( message , format ! ( " " message_dkg_id ) , ) . into ( ) } } ; let dealer_id = & message . signature . signer ; // If the validated pool already contains this exact message, we skip it. if dkg_pool . get_validated ( ) . any ( | item | item . eq ( message ) ) { return ChangeSet :: new ( ) ; } // If the dealing comes from a non-dealer, reject it. if ! config . dealers ( ) . get ( ) . contains ( dealer_id ) { return get_handle_invalid_change_action ( message , format ! ( " " dealer_id ) , ) . into ( ) ; } // If we already have a dealing from this dealer, we simply remove the // message from the pool. Multiple distinguishable valid dealings can be // created by an honest node because dkg dealings are not deterministic, // and in the case of a restart it is possible it might forget that it // has already sent out a dealing. See // https://dfinity.atlassian.net/browse/CON-534 for more details. if contains_dkg_messages ( dkg_pool , config , * dealer_id ) { return ChangeSet :: from ( ChangeAction :: RemoveFromUnvalidated ( ( * message ) . clone ( ) ) ) ; } // Verify the signature and reject if it's invalid, or skip, if there was an // error. match self . crypto . verify ( message , config . registry_version ( ) ) . map_err ( DkgMessageValidationError :: from ) { Ok ( ( ) ) => ( ) , Err ( ValidationError :: Permanent ( err ) ) => { return get_handle_invalid_change_action ( message , format ! ( " " err ) , ) . into ( ) } Err ( ValidationError :: Transient ( err ) ) => { error ! ( self logger " " err ) ; return ChangeSet :: new ( ) ; } } // Verify the dealing and move to validated if it was successful, // reject, if it was rejected, or skip, if there was an error. match ic_interfaces :: crypto :: NiDkgAlgorithm :: verify_dealing ( & * self . crypto , config , * dealer_id , & message . content . dealing , ) . map_err ( DkgMessageValidationError :: from ) { Ok ( ( ) ) => ChangeAction :: MoveToValidated ( ( * message ) . clone ( ) ) . into ( ) , Err ( ValidationError :: Permanent ( err ) ) => get_handle_invalid_change_action ( message , format ! ( " " err ) , ) . into ( ) , Err ( ValidationError :: Transient ( err ) ) => { error ! ( self logger " " err ) ; ChangeSet :: new ( ) } } }
Validates the DKG messages against the provided config.
Validates the DKG messages against the provided config .
&self
dkg_pool
&dyn DkgPool
configs
&BTreeMap<NiDkgId, NiDkgConfig>
dkg_start_height
Height
messages
Vec<&Message>
&self
dkg_pool
&dyn DkgPool
configs
&BTreeMap<NiDkgId, NiDkgConfig>
dkg_start_height
Height
messages
Vec<&Message>