/// A random configuration that selects some dealers and some receivers from
/// a network.
A random configuration that selects some dealers and some receivers from
a network.
A random configuration that selects some dealers and some receivers from a network .
pub fn from_network(
        rng: &mut ChaCha20Rng,
        network: &MockNetwork,
        last_dkg: Option<(MockDkgConfig, CspNiDkgTranscript)>,
    ) -> MockDkgConfig {
        // Metadata
        let num_nodes = network.nodes_by_node_id.len();
        let min_threshold = 1;
        let min_receivers = 1;
        let min_dealers = 1;
        assert!(
            min_receivers <= num_nodes,
            "min_receivers({}) !<= num_nodes({})",
            min_receivers,
            num_nodes
        );
        assert!(
            min_dealers <= num_nodes,
            "min_dealers({}) !<= num_nodes({})",
            min_dealers,
            num_nodes
        );
        // Node IDs
        let all_node_ids: Vec<NodeId> = network.nodes_by_node_id.keys().cloned().collect();
        let dealers = NiDkgDealers::new(
            if let Some((last_config, _last_transcript)) = last_dkg.as_ref() {
                last_config.receivers.get().clone()
            } else {
                all_node_ids
                    .iter()
                    .take(rng.gen_range(min_dealers, num_nodes + 1))
                    .cloned()
                    .collect()
            },
        )
        .expect("Could not create NiDkgDealers struct for test");
        let num_dealers = dealers.get().len();
        let num_receivers = rng.gen_range(min_receivers, num_nodes + 1);
        let receivers =
            NiDkgReceivers::new(all_node_ids.iter().take(num_receivers).cloned().collect())
                .expect("Could not create NiDkgReceivers struct for test");
        // Config values
        let algorithm_id = AlgorithmId::NiDkg_Groth20_Bls12_381;
        let dkg_id = random_ni_dkg_id(rng);
        let max_corrupt_dealers = rng.gen_range(0, num_dealers); // Need at least one honest dealer.
        let threshold = rng.gen_range(min_threshold, num_receivers + 1); // threshold <= num_receivers
        let max_corrupt_receivers =
            rng.gen_range(0, std::cmp::min(num_receivers + 1 - threshold, threshold)); // (max_corrupt_receivers <= num_receivers - threshold) &&
                                                                                       // (max_corrupt_receivers < threshold)
        let epoch = Epoch::from(rng.gen::<u32>());
        let receiver_keys: BTreeMap<NodeIndex, CspFsEncryptionPublicKey> = receivers
            .iter()
            .map(|(index, id)| (index, network.forward_secure_keys[&id]))
            .collect();
        let resharing_transcript = last_dkg.map(|(_last_config, last_transcript)| last_transcript);
        MockDkgConfig {
            algorithm_id,
            dkg_id,
            max_corrupt_dealers: NumberOfNodes::from(max_corrupt_dealers as NodeIndex),
            dealers,
            max_corrupt_receivers: NumberOfNodes::from(max_corrupt_receivers as NodeIndex),
            receivers,
            receiver_keys,
            threshold: NiDkgThreshold::new(NumberOfNodes::from(threshold as NodeIndex))
                .expect("Invalid threshold"),
            epoch,
            resharing_transcript,
        }
    }
pub fn from_network ( rng : & mut ChaCha20Rng , network : & MockNetwork , last_dkg : Option < ( MockDkgConfig , CspNiDkgTranscript ) > , ) -> MockDkgConfig { // Metadata let num_nodes = network . nodes_by_node_id . len ( ) ; let min_threshold = 1 ; let min_receivers = 1 ; let min_dealers = 1 ; assert ! ( min_receivers num_nodes " " min_receivers num_nodes ) ; assert ! ( min_dealers num_nodes " " min_dealers num_nodes ) ; // Node IDs let all_node_ids : Vec < NodeId > = network . nodes_by_node_id . keys ( ) . cloned ( ) . collect ( ) ; let dealers = NiDkgDealers :: new ( if let Some ( ( last_config , _last_transcript ) ) = last_dkg . as_ref ( ) { last_config . receivers . get ( ) . clone ( ) } else { all_node_ids . iter ( ) . take ( rng . gen_range ( min_dealers , num_nodes + 1 ) ) . cloned ( ) . collect ( ) } , ) . expect ( " " ) ; let num_dealers = dealers . get ( ) . len ( ) ; let num_receivers = rng . gen_range ( min_receivers , num_nodes + 1 ) ; let receivers = NiDkgReceivers :: new ( all_node_ids . iter ( ) . take ( num_receivers ) . cloned ( ) . collect ( ) ) . expect ( " " ) ; // Config values let algorithm_id = AlgorithmId :: NiDkg_Groth20_Bls12_381 ; let dkg_id = random_ni_dkg_id ( rng ) ; let max_corrupt_dealers = rng . gen_range ( 0 , num_dealers ) ; // Need at least one honest dealer. let threshold = rng . gen_range ( min_threshold , num_receivers + 1 ) ; // threshold <= num_receivers let max_corrupt_receivers = rng . gen_range ( 0 , std :: cmp :: min ( num_receivers + 1 - threshold , threshold ) ) ; // (max_corrupt_receivers <= num_receivers - threshold) && // (max_corrupt_receivers < threshold) let epoch = Epoch :: from ( rng . gen :: < u32 > ( ) ) ; let receiver_keys : BTreeMap < NodeIndex , CspFsEncryptionPublicKey > = receivers . iter ( ) . map ( | ( index , id ) | ( index , network . forward_secure_keys [ & id ] ) ) . collect ( ) ; let resharing_transcript = last_dkg . map ( | ( _last_config , last_transcript ) | last_transcript ) ; MockDkgConfig { algorithm_id , dkg_id , max_corrupt_dealers : NumberOfNodes :: from ( max_corrupt_dealers as NodeIndex ) , dealers , max_corrupt_receivers : NumberOfNodes :: from ( max_corrupt_receivers as NodeIndex ) , receivers , receiver_keys , threshold : NiDkgThreshold :: new ( NumberOfNodes :: from ( threshold as NodeIndex ) ) . expect ( " " ) , epoch , resharing_transcript , } }
A random configuration that selects some dealers and some receivers from
a network.
A random configuration that selects some dealers and some receivers from a network .
rng
&mut ChaCha20Rng
network
&MockNetwork
last_dkg
Option<(MockDkgConfig, CspNiDkgTranscript)>