fn validate_dealing_support(
        &self,
        ecdsa_pool: &dyn EcdsaPool,
        block_reader: &dyn EcdsaBlockReader,
    ) -> EcdsaChangeSet {
        // Get the set of valid dealings <TranscriptId, DealerId>
        let mut valid_dealings = BTreeSet::new();
        for (_, signed_dealing) in ecdsa_pool.validated().signed_dealings() {
            let dealing = signed_dealing.get();
            let dealing_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
            );
            valid_dealings.insert(dealing_key);
        }

        // Pass 1: collection of <TranscriptId, DealerId, SignerId>
        let mut supports = BTreeSet::new();
        let mut duplicate_supports = BTreeSet::new();
        for (_, support) in ecdsa_pool.unvalidated().dealing_support() {
            let dealing = &support.content;
            let support_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
                support.signature.signer,
            );
            if !supports.insert(support_key) {
                duplicate_supports.insert(support_key);
            }
        }

        let mut ret = Vec::new();
        for (id, support) in ecdsa_pool.unvalidated().dealing_support() {
            let dealing = &support.content;
            let dealing_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
            );
            let support_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
                support.signature.signer,
            );

            // Remove the duplicate entries
            if duplicate_supports.contains(&support_key) {
                self.metrics
                    .pre_sign_errors_inc("duplicate_support_in_batch");
                ret.push(EcdsaChangeAction::HandleInvalid(
                    id,
                    format!(
                        "Duplicate support in unvalidated batch: dealer = {:?}, height = {:?},
                          transcript_id = {:?}, signer = {:?}",
                        dealing.idkg_dealing.dealer_id,
                        dealing.requested_height,
                        dealing.idkg_dealing.transcript_id,
                        support.signature.signer,
                    ),
                ));
                continue;
            }

            match Action::action(
                block_reader,
                dealing.requested_height,
                &dealing.idkg_dealing.transcript_id,
            ) {
                Action::Process(transcript_params) => {
                    if transcript_params
                        .receivers()
                        .position(support.signature.signer)
                        .is_none()
                    {
                        // The node is not in the receiver list for this transcript,
                        // support share is not expected from it
                        self.metrics.pre_sign_errors_inc("unexpected_support");
                        ret.push(EcdsaChangeAction::HandleInvalid(
                            id,
                            format!(
                                "Support from unexpected node: dealer = {:?}, height = {:?},
                                  transcript_id = {:?}, signer = support.signature.signer",
                                dealing.idkg_dealing.dealer_id,
                                dealing.requested_height,
                                dealing.idkg_dealing.transcript_id
                            ),
                        ))
                    } else if !valid_dealings.contains(&dealing_key) {
                        // Support for a dealing we don't have yet, defer it
                        continue;
                    } else if self.has_node_issued_dealing_support(
                        ecdsa_pool,
                        &dealing.idkg_dealing.transcript_id,
                        &dealing.idkg_dealing.dealer_id,
                        &support.signature.signer,
                    ) {
                        // The node already sent a valid support for this dealing
                        self.metrics.pre_sign_errors_inc("duplicate_support");
                        ret.push(EcdsaChangeAction::HandleInvalid(
                            id,
                            format!(
                                "Duplicate support: dealer = {:?}, height = {:?},
                                  transcript_id = {:?}, signer = {:?}",
                                dealing.idkg_dealing.dealer_id,
                                dealing.requested_height,
                                dealing.idkg_dealing.transcript_id,
                                support.signature.signer
                            ),
                        ))
                    } else {
                        let mut changes =
                            self.crypto_verify_dealing_support(&id, transcript_params, support);
                        ret.append(&mut changes);
                    }
                }
                Action::Drop => ret.push(EcdsaChangeAction::RemoveUnvalidated(id)),
                Action::Defer => {}
            }
        }

        ret
    }
/// Processes the received dealing support messages
Processes the received dealing support messages
Processes the received dealing support messages
fn validate_dealing_support(
        &self,
        ecdsa_pool: &dyn EcdsaPool,
        block_reader: &dyn EcdsaBlockReader,
    ) -> EcdsaChangeSet {
        // Get the set of valid dealings <TranscriptId, DealerId>
        let mut valid_dealings = BTreeSet::new();
        for (_, signed_dealing) in ecdsa_pool.validated().signed_dealings() {
            let dealing = signed_dealing.get();
            let dealing_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
            );
            valid_dealings.insert(dealing_key);
        }
        // Pass 1: collection of <TranscriptId, DealerId, SignerId>
        let mut supports = BTreeSet::new();
        let mut duplicate_supports = BTreeSet::new();
        for (_, support) in ecdsa_pool.unvalidated().dealing_support() {
            let dealing = &support.content;
            let support_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
                support.signature.signer,
            );
            if !supports.insert(support_key) {
                duplicate_supports.insert(support_key);
            }
        }
        let mut ret = Vec::new();
        for (id, support) in ecdsa_pool.unvalidated().dealing_support() {
            let dealing = &support.content;
            let dealing_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
            );
            let support_key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
                support.signature.signer,
            );
            // Remove the duplicate entries
            if duplicate_supports.contains(&support_key) {
                self.metrics
                    .pre_sign_errors_inc("duplicate_support_in_batch");
                ret.push(EcdsaChangeAction::HandleInvalid(
                    id,
                    format!(
                        "Duplicate support in unvalidated batch: dealer = {:?}, height = {:?},
                          transcript_id = {:?}, signer = {:?}",
                        dealing.idkg_dealing.dealer_id,
                        dealing.requested_height,
                        dealing.idkg_dealing.transcript_id,
                        support.signature.signer,
                    ),
                ));
                continue;
            }
            match Action::action(
                block_reader,
                dealing.requested_height,
                &dealing.idkg_dealing.transcript_id,
            ) {
                Action::Process(transcript_params) => {
                    if transcript_params
                        .receivers()
                        .position(support.signature.signer)
                        .is_none()
                    {
                        // The node is not in the receiver list for this transcript,
                        // support share is not expected from it
                        self.metrics.pre_sign_errors_inc("unexpected_support");
                        ret.push(EcdsaChangeAction::HandleInvalid(
                            id,
                            format!(
                                "Support from unexpected node: dealer = {:?}, height = {:?},
                                  transcript_id = {:?}, signer = support.signature.signer",
                                dealing.idkg_dealing.dealer_id,
                                dealing.requested_height,
                                dealing.idkg_dealing.transcript_id
                            ),
                        ))
                    } else if !valid_dealings.contains(&dealing_key) {
                        // Support for a dealing we don't have yet, defer it
                        continue;
                    } else if self.has_node_issued_dealing_support(
                        ecdsa_pool,
                        &dealing.idkg_dealing.transcript_id,
                        &dealing.idkg_dealing.dealer_id,
                        &support.signature.signer,
                    ) {
                        // The node already sent a valid support for this dealing
                        self.metrics.pre_sign_errors_inc("duplicate_support");
                        ret.push(EcdsaChangeAction::HandleInvalid(
                            id,
                            format!(
                                "Duplicate support: dealer = {:?}, height = {:?},
                                  transcript_id = {:?}, signer = {:?}",
                                dealing.idkg_dealing.dealer_id,
                                dealing.requested_height,
                                dealing.idkg_dealing.transcript_id,
                                support.signature.signer
                            ),
                        ))
                    } else {
                        let mut changes =
                            self.crypto_verify_dealing_support(&id, transcript_params, support);
                        ret.append(&mut changes);
                    }
                }
                Action::Drop => ret.push(EcdsaChangeAction::RemoveUnvalidated(id)),
                Action::Defer => {}
            }
        }
        ret
    }
fn validate_dealing_support ( & self , ecdsa_pool : & dyn EcdsaPool , block_reader : & dyn EcdsaBlockReader , ) -> EcdsaChangeSet { // Get the set of valid dealings <TranscriptId, DealerId> let mut valid_dealings = BTreeSet :: new ( ) ; for ( _ , signed_dealing ) in ecdsa_pool . validated ( ) . signed_dealings ( ) { let dealing = signed_dealing . get ( ) ; let dealing_key = ( dealing . idkg_dealing . transcript_id , dealing . idkg_dealing . dealer_id , ) ; valid_dealings . insert ( dealing_key ) ; } // Pass 1: collection of <TranscriptId, DealerId, SignerId> let mut supports = BTreeSet :: new ( ) ; let mut duplicate_supports = BTreeSet :: new ( ) ; for ( _ , support ) in ecdsa_pool . unvalidated ( ) . dealing_support ( ) { let dealing = & support . content ; let support_key = ( dealing . idkg_dealing . transcript_id , dealing . idkg_dealing . dealer_id , support . signature . signer , ) ; if ! supports . insert ( support_key ) { duplicate_supports . insert ( support_key ) ; } } let mut ret = Vec :: new ( ) ; for ( id , support ) in ecdsa_pool . unvalidated ( ) . dealing_support ( ) { let dealing = & support . content ; let dealing_key = ( dealing . idkg_dealing . transcript_id , dealing . idkg_dealing . dealer_id , ) ; let support_key = ( dealing . idkg_dealing . transcript_id , dealing . idkg_dealing . dealer_id , support . signature . signer , ) ; // Remove the duplicate entries if duplicate_supports . contains ( & support_key ) { self . metrics . pre_sign_errors_inc ( " " ) ; ret . push ( EcdsaChangeAction :: HandleInvalid ( id , format ! ( " " dealing idkg_dealing dealer_id dealing requested_height dealing idkg_dealing transcript_id support signature signer ) , ) ) ; continue ; } match Action :: action ( block_reader , dealing . requested_height , & dealing . idkg_dealing . transcript_id , ) { Action :: Process ( transcript_params ) => { if transcript_params . receivers ( ) . position ( support . signature . signer ) . is_none ( ) { // The node is not in the receiver list for this transcript, // support share is not expected from it self . metrics . pre_sign_errors_inc ( " " ) ; ret . push ( EcdsaChangeAction :: HandleInvalid ( id , format ! ( " " dealing idkg_dealing dealer_id dealing requested_height dealing idkg_dealing transcript_id ) , ) ) } else if ! valid_dealings . contains ( & dealing_key ) { // Support for a dealing we don't have yet, defer it continue ; } else if self . has_node_issued_dealing_support ( ecdsa_pool , & dealing . idkg_dealing . transcript_id , & dealing . idkg_dealing . dealer_id , & support . signature . signer , ) { // The node already sent a valid support for this dealing self . metrics . pre_sign_errors_inc ( " " ) ; ret . push ( EcdsaChangeAction :: HandleInvalid ( id , format ! ( " " dealing idkg_dealing dealer_id dealing requested_height dealing idkg_dealing transcript_id support signature signer ) , ) ) } else { let mut changes = self . crypto_verify_dealing_support ( & id , transcript_params , support ) ; ret . append ( & mut changes ) ; } } Action :: Drop => ret . push ( EcdsaChangeAction :: RemoveUnvalidated ( id ) ) , Action :: Defer => { } } } ret }
Processes the received dealing support messages
Processes the received dealing support messages
&self
ecdsa_pool
&dyn EcdsaPool
block_reader
&dyn EcdsaBlockReader
&self
ecdsa_pool
&dyn EcdsaPool
block_reader
&dyn EcdsaBlockReader