/// Processes the dealings received from peer dealers
Processes the dealings received from peer dealers
Processes the dealings received from peer dealers
fn validate_dealings(
        &self,
        ecdsa_pool: &dyn EcdsaPool,
        block_reader: &dyn EcdsaBlockReader,
    ) -> EcdsaChangeSet {
        // Pass 1: collection of <TranscriptId, DealerId>
        let mut dealing_keys = BTreeSet::new();
        let mut duplicate_keys = BTreeSet::new();
        for (_, signed_dealing) in ecdsa_pool.unvalidated().signed_dealings() {
            let dealing = signed_dealing.get();
            let key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
            );
            if !dealing_keys.insert(key) {
                duplicate_keys.insert(key);
            }
        }
        let mut ret = Vec::new();
        for (id, signed_dealing) in ecdsa_pool.unvalidated().signed_dealings() {
            let dealing = signed_dealing.get();
            // Remove the duplicate entries
            let key = (
                dealing.idkg_dealing.transcript_id,
                dealing.idkg_dealing.dealer_id,
            );
            if duplicate_keys.contains(&key) {
                self.metrics
                    .pre_sign_errors_inc("duplicate_dealing_in_batch");
                ret.push(EcdsaChangeAction::HandleInvalid(
                    id,
                    format!(
                        "Duplicate dealing in unvalidated batch: dealer = {:?}, height = {:?},
                          transcript_id = {:?}",
                        dealing.idkg_dealing.dealer_id,
                        dealing.requested_height,
                        dealing.idkg_dealing.transcript_id
                    ),
                ));
                continue;
            }
            match Action::action(
                block_reader,
                dealing.requested_height,
                &dealing.idkg_dealing.transcript_id,
            ) {
                Action::Process(transcript_params) => {
                    if transcript_params
                        .dealers()
                        .position(dealing.idkg_dealing.dealer_id)
                        .is_none()
                    {
                        // The node is not in the dealer list for this transcript
                        self.metrics.pre_sign_errors_inc("unexpected_dealing");
                        ret.push(EcdsaChangeAction::HandleInvalid(
                            id,
                            format!(
                                "Dealing from unexpected node: dealer = {:?}, height = {:?},
                                  transcript_id = {:?}",
                                dealing.idkg_dealing.dealer_id,
                                dealing.requested_height,
                                dealing.idkg_dealing.transcript_id
                            ),
                        ))
                    } else if self.has_dealer_issued_dealing(
                        ecdsa_pool,
                        &dealing.idkg_dealing.transcript_id,
                        &dealing.idkg_dealing.dealer_id,
                    ) {
                        // The node already sent a valid dealing for this transcript
                        self.metrics.pre_sign_errors_inc("duplicate_dealing");
                        ret.push(EcdsaChangeAction::HandleInvalid(
                            id,
                            format!(
                                "Duplicate dealing: dealer = {:?}, height = {:?},
                                  transcript_id = {:?}",
                                dealing.idkg_dealing.dealer_id,
                                dealing.requested_height,
                                dealing.idkg_dealing.transcript_id
                            ),
                        ))
                    } else {
                        let mut changes =
                            self.crypto_verify_dealing(&id, transcript_params, signed_dealing);
                        ret.append(&mut changes);
                    }
                }
                Action::Drop => ret.push(EcdsaChangeAction::RemoveUnvalidated(id)),
                Action::Defer => {}
            }
        }
        ret
    }
fn validate_dealings ( & self , ecdsa_pool : & dyn EcdsaPool , block_reader : & dyn EcdsaBlockReader , ) -> EcdsaChangeSet { // Pass 1: collection of <TranscriptId, DealerId> let mut dealing_keys = BTreeSet :: new ( ) ; let mut duplicate_keys = BTreeSet :: new ( ) ; for ( _ , signed_dealing ) in ecdsa_pool . unvalidated ( ) . signed_dealings ( ) { let dealing = signed_dealing . get ( ) ; let key = ( dealing . idkg_dealing . transcript_id , dealing . idkg_dealing . dealer_id , ) ; if ! dealing_keys . insert ( key ) { duplicate_keys . insert ( key ) ; } } let mut ret = Vec :: new ( ) ; for ( id , signed_dealing ) in ecdsa_pool . unvalidated ( ) . signed_dealings ( ) { let dealing = signed_dealing . get ( ) ; // Remove the duplicate entries let key = ( dealing . idkg_dealing . transcript_id , dealing . idkg_dealing . dealer_id , ) ; if duplicate_keys . contains ( & 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 ) , ) ) ; continue ; } match Action :: action ( block_reader , dealing . requested_height , & dealing . idkg_dealing . transcript_id , ) { Action :: Process ( transcript_params ) => { if transcript_params . dealers ( ) . position ( dealing . idkg_dealing . dealer_id ) . is_none ( ) { // The node is not in the dealer list for this transcript 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 self . has_dealer_issued_dealing ( ecdsa_pool , & dealing . idkg_dealing . transcript_id , & dealing . idkg_dealing . dealer_id , ) { // The node already sent a valid dealing for this transcript 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 { let mut changes = self . crypto_verify_dealing ( & id , transcript_params , signed_dealing ) ; ret . append ( & mut changes ) ; } } Action :: Drop => ret . push ( EcdsaChangeAction :: RemoveUnvalidated ( id ) ) , Action :: Defer => { } } } ret }
Processes the dealings received from peer dealers
Processes the dealings received from peer dealers
&self
ecdsa_pool
&dyn EcdsaPool
block_reader
&dyn EcdsaBlockReader