fn update_quadruples_in_creation(
    ecdsa_transcript: Option<&ecdsa::UnmaskedTranscript>,
    payload: &mut ecdsa::EcdsaDataPayload,
    completed_transcripts: &mut BTreeMap<IDkgTranscriptId, IDkgTranscript>,
    log: ReplicaLogger,
) -> Result<(), EcdsaPayloadError> {
    debug!(
        log,
        "update_quadruples_in_creation: completed transcript = {:?}",
        completed_transcripts.keys()
    );
    let mut newly_available = Vec::new();
    for (key, quadruple) in payload.quadruples_in_creation.iter_mut() {
        // Update quadruple with completed transcripts
        if quadruple.kappa_masked.is_none() {
            if let Some(transcript) =
                completed_transcripts.remove(&quadruple.kappa_config.transcript_id())
            {
                debug!(
                    log,
                    "update_quadruples_in_creation: {:?} kappa_masked transcript is made", key
                );
                quadruple.kappa_masked = Some(ecdsa::Masked::try_from(transcript)?);
            }
        }
        if quadruple.lambda_masked.is_none() {
            if let Some(transcript) =
                completed_transcripts.remove(&quadruple.lambda_config.transcript_id())
            {
                debug!(
                    log,
                    "update_quadruples_in_creation: {:?} lamdba_masked transcript is made", key
                );
                quadruple.lambda_masked = Some(ecdsa::Masked::try_from(transcript)?);
            }
        }
        if quadruple.kappa_unmasked.is_none() {
            if let Some(config) = &quadruple.unmask_kappa_config {
                if let Some(transcript) = completed_transcripts.remove(&config.transcript_id()) {
                    debug!(
                        log,
                        "update_quadruples_in_creation: {:?} kappa_unmasked transcript {:?} is made",
                        key,
                        transcript.get_type()
                    );
                    quadruple.kappa_unmasked = Some(ecdsa::Unmasked::try_from(transcript)?);
                }
            }
        }
        if quadruple.key_times_lambda.is_none() {
            if let Some(config) = &quadruple.key_times_lambda_config {
                if let Some(transcript) = completed_transcripts.remove(&config.transcript_id()) {
                    debug!(
                        log,
                        "update_quadruples_in_creation: {:?} key_times_lambda transcript is made",
                        key
                    );
                    quadruple.key_times_lambda = Some(ecdsa::Masked::try_from(transcript)?);
                }
            }
        }
        if quadruple.kappa_times_lambda.is_none() {
            if let Some(config) = &quadruple.kappa_times_lambda_config {
                if let Some(transcript) = completed_transcripts.remove(&config.transcript_id()) {
                    debug!(
                        log,
                        "update_quadruples_in_creation: {:?} kappa_times_lambda transcript is made",
                        key
                    );
                    quadruple.kappa_times_lambda = Some(ecdsa::Masked::try_from(transcript)?);
                }
            }
        }
        // Check what to do in the next step
        if let (Some(kappa_masked), None) =
            (&quadruple.kappa_masked, &quadruple.unmask_kappa_config)
        {
            quadruple.unmask_kappa_config = Some(IDkgTranscriptParams::new(
                payload.next_unused_transcript_id,
                quadruple.kappa_config.dealers().clone(),
                quadruple.kappa_config.receivers().clone(),
                quadruple.kappa_config.registry_version(),
                quadruple.kappa_config.algorithm_id(),
                IDkgTranscriptOperation::ReshareOfMasked(kappa_masked.clone().into()),
            )?);
            payload.next_unused_transcript_id = payload.next_unused_transcript_id.increment();
        }
        if let (Some(lambda_masked), None, Some(transcript)) = (
            &quadruple.lambda_masked,
            &quadruple.key_times_lambda_config,
            ecdsa_transcript,
        ) {
            quadruple.key_times_lambda_config = Some(IDkgTranscriptParams::new(
                payload.next_unused_transcript_id,
                quadruple.lambda_config.dealers().clone(),
                quadruple.lambda_config.receivers().clone(),
                quadruple.lambda_config.registry_version(),
                quadruple.lambda_config.algorithm_id(),
                IDkgTranscriptOperation::UnmaskedTimesMasked(
                    transcript.clone().into(),
                    lambda_masked.clone().into(),
                ),
            )?);
            payload.next_unused_transcript_id = payload.next_unused_transcript_id.increment();
        }
        if let (Some(lambda_masked), Some(kappa_unmasked), None) = (
            &quadruple.lambda_masked,
            &quadruple.kappa_unmasked,
            &quadruple.kappa_times_lambda_config,
        ) {
            quadruple.kappa_times_lambda_config = Some(IDkgTranscriptParams::new(
                payload.next_unused_transcript_id,
                quadruple.lambda_config.dealers().clone(),
                quadruple.lambda_config.receivers().clone(),
                quadruple.lambda_config.registry_version(),
                quadruple.lambda_config.algorithm_id(),
                IDkgTranscriptOperation::UnmaskedTimesMasked(
                    kappa_unmasked.clone().into(),
                    lambda_masked.clone().into(),
                ),
            )?);
            payload.next_unused_transcript_id = payload.next_unused_transcript_id.increment();
        }
        if let (
            Some(_kappa_unmasked),
            Some(_lambda_masked),
            Some(_key_times_lambda),
            Some(_kappa_times_lambda),
        ) = (
            &quadruple.kappa_unmasked,
            &quadruple.lambda_masked,
            &quadruple.key_times_lambda,
            &quadruple.kappa_times_lambda,
        ) {
            newly_available.push(*key);
        }
    }
    for key in newly_available.into_iter() {
        // the following unwraps are safe
        let quadruple = payload.quadruples_in_creation.remove(&key).unwrap();
        let lambda_masked = quadruple.lambda_masked.unwrap();
        let kappa_unmasked = quadruple.kappa_unmasked.unwrap();
        let key_times_lambda = quadruple.key_times_lambda.unwrap();
        let kappa_times_lambda = quadruple.kappa_times_lambda.unwrap();
        debug!(
            log,
            "update_quadruples_in_creation: making of quadruple {:?} is complete", key
        );
        payload.available_quadruples.insert(
            key,
            PreSignatureQuadruple::new(
                kappa_unmasked.into(),
                lambda_masked.into(),
                kappa_times_lambda.into(),
                key_times_lambda.into(),
            )?,
        );
    }
    Ok(())
}
/// Update the quadruples in the payload by:
/// - making new configs when pre-conditions are met;
/// - gathering ready results (new transcripts) from ecdsa pool;
/// - moving completed quadruples from "in creation" to "available".
Update the quadruples in the payload by:
making new configs when pre-conditions are met;
gathering ready results (new transcripts) from ecdsa pool;
moving completed quadruples from "in creation" to "available".
Update the quadruples in the payload by : making new configs when pre - conditions are met ; gathering ready results ( new transcripts ) from ecdsa pool ; moving completed quadruples from " in creation " to " available " .
fn update_quadruples_in_creation(
    ecdsa_transcript: Option<&ecdsa::UnmaskedTranscript>,
    payload: &mut ecdsa::EcdsaDataPayload,
    completed_transcripts: &mut BTreeMap<IDkgTranscriptId, IDkgTranscript>,
    log: ReplicaLogger,
) -> Result<(), EcdsaPayloadError> {
    debug!(
        log,
        "update_quadruples_in_creation: completed transcript = {:?}",
        completed_transcripts.keys()
    );
    let mut newly_available = Vec::new();
    for (key, quadruple) in payload.quadruples_in_creation.iter_mut() {
        // Update quadruple with completed transcripts
        if quadruple.kappa_masked.is_none() {
            if let Some(transcript) =
                completed_transcripts.remove(&quadruple.kappa_config.transcript_id())
            {
                debug!(
                    log,
                    "update_quadruples_in_creation: {:?} kappa_masked transcript is made", key
                );
                quadruple.kappa_masked = Some(ecdsa::Masked::try_from(transcript)?);
            }
        }
        if quadruple.lambda_masked.is_none() {
            if let Some(transcript) =
                completed_transcripts.remove(&quadruple.lambda_config.transcript_id())
            {
                debug!(
                    log,
                    "update_quadruples_in_creation: {:?} lamdba_masked transcript is made", key
                );
                quadruple.lambda_masked = Some(ecdsa::Masked::try_from(transcript)?);
            }
        }
        if quadruple.kappa_unmasked.is_none() {
            if let Some(config) = &quadruple.unmask_kappa_config {
                if let Some(transcript) = completed_transcripts.remove(&config.transcript_id()) {
                    debug!(
                        log,
                        "update_quadruples_in_creation: {:?} kappa_unmasked transcript {:?} is made",
                        key,
                        transcript.get_type()
                    );
                    quadruple.kappa_unmasked = Some(ecdsa::Unmasked::try_from(transcript)?);
                }
            }
        }
        if quadruple.key_times_lambda.is_none() {
            if let Some(config) = &quadruple.key_times_lambda_config {
                if let Some(transcript) = completed_transcripts.remove(&config.transcript_id()) {
                    debug!(
                        log,
                        "update_quadruples_in_creation: {:?} key_times_lambda transcript is made",
                        key
                    );
                    quadruple.key_times_lambda = Some(ecdsa::Masked::try_from(transcript)?);
                }
            }
        }
        if quadruple.kappa_times_lambda.is_none() {
            if let Some(config) = &quadruple.kappa_times_lambda_config {
                if let Some(transcript) = completed_transcripts.remove(&config.transcript_id()) {
                    debug!(
                        log,
                        "update_quadruples_in_creation: {:?} kappa_times_lambda transcript is made",
                        key
                    );
                    quadruple.kappa_times_lambda = Some(ecdsa::Masked::try_from(transcript)?);
                }
            }
        }
        // Check what to do in the next step
        if let (Some(kappa_masked), None) =
            (&quadruple.kappa_masked, &quadruple.unmask_kappa_config)
        {
            quadruple.unmask_kappa_config = Some(IDkgTranscriptParams::new(
                payload.next_unused_transcript_id,
                quadruple.kappa_config.dealers().clone(),
                quadruple.kappa_config.receivers().clone(),
                quadruple.kappa_config.registry_version(),
                quadruple.kappa_config.algorithm_id(),
                IDkgTranscriptOperation::ReshareOfMasked(kappa_masked.clone().into()),
            )?);
            payload.next_unused_transcript_id = payload.next_unused_transcript_id.increment();
        }
        if let (Some(lambda_masked), None, Some(transcript)) = (
            &quadruple.lambda_masked,
            &quadruple.key_times_lambda_config,
            ecdsa_transcript,
        ) {
            quadruple.key_times_lambda_config = Some(IDkgTranscriptParams::new(
                payload.next_unused_transcript_id,
                quadruple.lambda_config.dealers().clone(),
                quadruple.lambda_config.receivers().clone(),
                quadruple.lambda_config.registry_version(),
                quadruple.lambda_config.algorithm_id(),
                IDkgTranscriptOperation::UnmaskedTimesMasked(
                    transcript.clone().into(),
                    lambda_masked.clone().into(),
                ),
            )?);
            payload.next_unused_transcript_id = payload.next_unused_transcript_id.increment();
        }
        if let (Some(lambda_masked), Some(kappa_unmasked), None) = (
            &quadruple.lambda_masked,
            &quadruple.kappa_unmasked,
            &quadruple.kappa_times_lambda_config,
        ) {
            quadruple.kappa_times_lambda_config = Some(IDkgTranscriptParams::new(
                payload.next_unused_transcript_id,
                quadruple.lambda_config.dealers().clone(),
                quadruple.lambda_config.receivers().clone(),
                quadruple.lambda_config.registry_version(),
                quadruple.lambda_config.algorithm_id(),
                IDkgTranscriptOperation::UnmaskedTimesMasked(
                    kappa_unmasked.clone().into(),
                    lambda_masked.clone().into(),
                ),
            )?);
            payload.next_unused_transcript_id = payload.next_unused_transcript_id.increment();
        }
        if let (
            Some(_kappa_unmasked),
            Some(_lambda_masked),
            Some(_key_times_lambda),
            Some(_kappa_times_lambda),
        ) = (
            &quadruple.kappa_unmasked,
            &quadruple.lambda_masked,
            &quadruple.key_times_lambda,
            &quadruple.kappa_times_lambda,
        ) {
            newly_available.push(*key);
        }
    }
    for key in newly_available.into_iter() {
        // the following unwraps are safe
        let quadruple = payload.quadruples_in_creation.remove(&key).unwrap();
        let lambda_masked = quadruple.lambda_masked.unwrap();
        let kappa_unmasked = quadruple.kappa_unmasked.unwrap();
        let key_times_lambda = quadruple.key_times_lambda.unwrap();
        let kappa_times_lambda = quadruple.kappa_times_lambda.unwrap();
        debug!(
            log,
            "update_quadruples_in_creation: making of quadruple {:?} is complete", key
        );
        payload.available_quadruples.insert(
            key,
            PreSignatureQuadruple::new(
                kappa_unmasked.into(),
                lambda_masked.into(),
                kappa_times_lambda.into(),
                key_times_lambda.into(),
            )?,
        );
    }
    Ok(())
}
fn update_quadruples_in_creation ( ecdsa_transcript : Option < & ecdsa :: UnmaskedTranscript > , payload : & mut ecdsa :: EcdsaDataPayload , completed_transcripts : & mut BTreeMap < IDkgTranscriptId , IDkgTranscript > , log : ReplicaLogger , ) -> Result < ( ) , EcdsaPayloadError > { debug ! ( log " " completed_transcripts keys ( ) ) ; let mut newly_available = Vec :: new ( ) ; for ( key , quadruple ) in payload . quadruples_in_creation . iter_mut ( ) { // Update quadruple with completed transcripts if quadruple . kappa_masked . is_none ( ) { if let Some ( transcript ) = completed_transcripts . remove ( & quadruple . kappa_config . transcript_id ( ) ) { debug ! ( log " " key ) ; quadruple . kappa_masked = Some ( ecdsa :: Masked :: try_from ( transcript ) ? ) ; } } if quadruple . lambda_masked . is_none ( ) { if let Some ( transcript ) = completed_transcripts . remove ( & quadruple . lambda_config . transcript_id ( ) ) { debug ! ( log " " key ) ; quadruple . lambda_masked = Some ( ecdsa :: Masked :: try_from ( transcript ) ? ) ; } } if quadruple . kappa_unmasked . is_none ( ) { if let Some ( config ) = & quadruple . unmask_kappa_config { if let Some ( transcript ) = completed_transcripts . remove ( & config . transcript_id ( ) ) { debug ! ( log " " key transcript get_type ( ) ) ; quadruple . kappa_unmasked = Some ( ecdsa :: Unmasked :: try_from ( transcript ) ? ) ; } } } if quadruple . key_times_lambda . is_none ( ) { if let Some ( config ) = & quadruple . key_times_lambda_config { if let Some ( transcript ) = completed_transcripts . remove ( & config . transcript_id ( ) ) { debug ! ( log " " key ) ; quadruple . key_times_lambda = Some ( ecdsa :: Masked :: try_from ( transcript ) ? ) ; } } } if quadruple . kappa_times_lambda . is_none ( ) { if let Some ( config ) = & quadruple . kappa_times_lambda_config { if let Some ( transcript ) = completed_transcripts . remove ( & config . transcript_id ( ) ) { debug ! ( log " " key ) ; quadruple . kappa_times_lambda = Some ( ecdsa :: Masked :: try_from ( transcript ) ? ) ; } } } // Check what to do in the next step if let ( Some ( kappa_masked ) , None ) = ( & quadruple . kappa_masked , & quadruple . unmask_kappa_config ) { quadruple . unmask_kappa_config = Some ( IDkgTranscriptParams :: new ( payload . next_unused_transcript_id , quadruple . kappa_config . dealers ( ) . clone ( ) , quadruple . kappa_config . receivers ( ) . clone ( ) , quadruple . kappa_config . registry_version ( ) , quadruple . kappa_config . algorithm_id ( ) , IDkgTranscriptOperation :: ReshareOfMasked ( kappa_masked . clone ( ) . into ( ) ) , ) ? ) ; payload . next_unused_transcript_id = payload . next_unused_transcript_id . increment ( ) ; } if let ( Some ( lambda_masked ) , None , Some ( transcript ) ) = ( & quadruple . lambda_masked , & quadruple . key_times_lambda_config , ecdsa_transcript , ) { quadruple . key_times_lambda_config = Some ( IDkgTranscriptParams :: new ( payload . next_unused_transcript_id , quadruple . lambda_config . dealers ( ) . clone ( ) , quadruple . lambda_config . receivers ( ) . clone ( ) , quadruple . lambda_config . registry_version ( ) , quadruple . lambda_config . algorithm_id ( ) , IDkgTranscriptOperation :: UnmaskedTimesMasked ( transcript . clone ( ) . into ( ) , lambda_masked . clone ( ) . into ( ) , ) , ) ? ) ; payload . next_unused_transcript_id = payload . next_unused_transcript_id . increment ( ) ; } if let ( Some ( lambda_masked ) , Some ( kappa_unmasked ) , None ) = ( & quadruple . lambda_masked , & quadruple . kappa_unmasked , & quadruple . kappa_times_lambda_config , ) { quadruple . kappa_times_lambda_config = Some ( IDkgTranscriptParams :: new ( payload . next_unused_transcript_id , quadruple . lambda_config . dealers ( ) . clone ( ) , quadruple . lambda_config . receivers ( ) . clone ( ) , quadruple . lambda_config . registry_version ( ) , quadruple . lambda_config . algorithm_id ( ) , IDkgTranscriptOperation :: UnmaskedTimesMasked ( kappa_unmasked . clone ( ) . into ( ) , lambda_masked . clone ( ) . into ( ) , ) , ) ? ) ; payload . next_unused_transcript_id = payload . next_unused_transcript_id . increment ( ) ; } if let ( Some ( _kappa_unmasked ) , Some ( _lambda_masked ) , Some ( _key_times_lambda ) , Some ( _kappa_times_lambda ) , ) = ( & quadruple . kappa_unmasked , & quadruple . lambda_masked , & quadruple . key_times_lambda , & quadruple . kappa_times_lambda , ) { newly_available . push ( * key ) ; } } for key in newly_available . into_iter ( ) { // the following unwraps are safe let quadruple = payload . quadruples_in_creation . remove ( & key ) . unwrap ( ) ; let lambda_masked = quadruple . lambda_masked . unwrap ( ) ; let kappa_unmasked = quadruple . kappa_unmasked . unwrap ( ) ; let key_times_lambda = quadruple . key_times_lambda . unwrap ( ) ; let kappa_times_lambda = quadruple . kappa_times_lambda . unwrap ( ) ; debug ! ( log " " key ) ; payload . available_quadruples . insert ( key , PreSignatureQuadruple :: new ( kappa_unmasked . into ( ) , lambda_masked . into ( ) , kappa_times_lambda . into ( ) , key_times_lambda . into ( ) , ) ? , ) ; } Ok ( ( ) ) }
Update the quadruples in the payload by:
 making new configs when pre-conditions are met;
 gathering ready results (new transcripts) from ecdsa pool;
 moving completed quadruples from "in creation" to "available".
Update the quadruples in the payload by : making new configs when pre - conditions are met ; gathering ready results ( new transcripts ) from ecdsa pool ; moving completed quadruples from " in creation " to " available " .
ecdsa_transcript
Option<&ecdsa::UnmaskedTranscript>
payload
&mut ecdsa::EcdsaDataPayload
completed_transcripts
&mut BTreeMap<IDkgTranscriptId, IDkgTranscript>
log
ReplicaLogger
ecdsa_transcript
Option<&ecdsa::UnmaskedTranscript>
payload
&mut ecdsa::EcdsaDataPayload
completed_transcripts
&mut BTreeMap<IDkgTranscriptId, IDkgTranscript>
log
ReplicaLogger