pub fn reshare(transcript: NiDkgTranscript, max_subnet_size: usize) -> Self {
            let rng = &mut thread_rng();

            // let max_corrupt_dealers = self.0.max_corrupt_receivers();
            let max_corrupt_dealers =
                number_of_nodes_from_usize(get_faults_tolerated(transcript.committee.get().len()));
            let dealers = {
                let lower_bound_u32 = cmp::max(
                    max_corrupt_dealers.get() + 1, // Ensures #dealers > max_corrupt_dealers
                    transcript.threshold.get().get(), // Ensures #dealers >= resharing threshold
                );
                let lower_bound = usize::try_from(lower_bound_u32).expect("conversion error");
                let dealer_count = rng.gen_range(lower_bound, transcript.committee.get().len() + 1);
                let dealers_vec = transcript
                    .committee
                    .get()
                    .iter()
                    .copied()
                    .choose_multiple(rng, dealer_count);
                dealers_vec.into_iter().collect()
            };
            let new_subnet_size = {
                let transcript_committee_len_i32 =
                    i32::try_from(transcript.committee.get().len()).expect("conversion error");
                let new_subnet_size_i32 =
                    cmp::max(1, transcript_committee_len_i32 + rng.gen_range(-2, 3));
                let new_subnet_size =
                    usize::try_from(new_subnet_size_i32).expect("conversion error");
                cmp::min(new_subnet_size, max_subnet_size)
            };
            let mut registry_version = transcript.registry_version;
            let receivers = {
                if new_subnet_size <= transcript.committee.get().len() {
                    // Keep as many receivers as needed from the existing ones
                    let receivers_vec = transcript
                        .committee
                        .get()
                        .iter()
                        .copied()
                        .choose_multiple(rng, new_subnet_size);
                    receivers_vec.into_iter().collect()
                } else {
                    // Keep all existing receivers and add new ones as needed
                    let committee = transcript.committee.get();
                    let additional_receivers_count = new_subnet_size - committee.len();
                    let additional_receivers =
                        random_node_ids_excluding(committee, additional_receivers_count);
                    let receivers = committee.union(&additional_receivers).copied().collect();
                    // Adding of nodes means that new nodes will be added to the registry
                    // which in turn means that the registry version needs to be bumped up
                    registry_version += ONE_REGISTRY_VERSION;
                    receivers
                }
            };
            let dkg_tag = transcript.dkg_id.dkg_tag;
            let config_data = NiDkgConfigData {
                dkg_id: NiDkgId {
                    start_block_height: Height::new(transcript.dkg_id.start_block_height.get() + 1),
                    // Theoretically the subnet ID should change on the _first_ DKG in the new
                    // subnet, but this is not important: relevant is only that
                    // the NiDkgId is different, which is already achieved by
                    // increasing the start_block_height.
                    dealer_subnet: transcript.dkg_id.dealer_subnet,
                    dkg_tag,
                    target_subnet: NiDkgTargetSubnet::Local,
                },
                max_corrupt_dealers,
                dealers,
                max_corrupt_receivers: {
                    number_of_nodes_from_usize(get_faults_tolerated(new_subnet_size))
                },
                receivers,
                threshold: number_of_nodes_from_usize(
                    dkg_tag.threshold_for_subnet_of_size(new_subnet_size),
                ),
                registry_version,
                resharing_transcript: Some(transcript),
            };
            Self(NiDkgConfig::new(config_data).expect("invariant violated"))
        }
/// Reshares the config into a new random NI-DKG config with the given
/// `transcript`.
///
/// The subnet size is changed dynamically in the range [-2, +2] with
/// minimum of 1 and maximum of `max_subnet_size`. If new nodes
/// are added as part of the resizing, the registry version is
/// increased by 1.
Reshares the config into a new random NI-DKG config with the given
`transcript`.

The subnet size is changed dynamically in the range [-2, +2] with
minimum of 1 and maximum of `max_subnet_size`. If new nodes
are added as part of the resizing, the registry version is
increased by 1.
Reshares the config into a new random NI - DKG config with the given ` transcript ` . The subnet size is changed dynamically in the range [ - 2 + 2 ] with minimum of 1 and maximum of ` max_subnet_size ` . If new nodes are added as part of the resizing the registry version is increased by 1 .
pub fn reshare(transcript: NiDkgTranscript, max_subnet_size: usize) -> Self {
            let rng = &mut thread_rng();
            // let max_corrupt_dealers = self.0.max_corrupt_receivers();
            let max_corrupt_dealers =
                number_of_nodes_from_usize(get_faults_tolerated(transcript.committee.get().len()));
            let dealers = {
                let lower_bound_u32 = cmp::max(
                    max_corrupt_dealers.get() + 1, // Ensures #dealers > max_corrupt_dealers
                    transcript.threshold.get().get(), // Ensures #dealers >= resharing threshold
                );
                let lower_bound = usize::try_from(lower_bound_u32).expect("conversion error");
                let dealer_count = rng.gen_range(lower_bound, transcript.committee.get().len() + 1);
                let dealers_vec = transcript
                    .committee
                    .get()
                    .iter()
                    .copied()
                    .choose_multiple(rng, dealer_count);
                dealers_vec.into_iter().collect()
            };
            let new_subnet_size = {
                let transcript_committee_len_i32 =
                    i32::try_from(transcript.committee.get().len()).expect("conversion error");
                let new_subnet_size_i32 =
                    cmp::max(1, transcript_committee_len_i32 + rng.gen_range(-2, 3));
                let new_subnet_size =
                    usize::try_from(new_subnet_size_i32).expect("conversion error");
                cmp::min(new_subnet_size, max_subnet_size)
            };
            let mut registry_version = transcript.registry_version;
            let receivers = {
                if new_subnet_size <= transcript.committee.get().len() {
                    // Keep as many receivers as needed from the existing ones
                    let receivers_vec = transcript
                        .committee
                        .get()
                        .iter()
                        .copied()
                        .choose_multiple(rng, new_subnet_size);
                    receivers_vec.into_iter().collect()
                } else {
                    // Keep all existing receivers and add new ones as needed
                    let committee = transcript.committee.get();
                    let additional_receivers_count = new_subnet_size - committee.len();
                    let additional_receivers =
                        random_node_ids_excluding(committee, additional_receivers_count);
                    let receivers = committee.union(&additional_receivers).copied().collect();
                    // Adding of nodes means that new nodes will be added to the registry
                    // which in turn means that the registry version needs to be bumped up
                    registry_version += ONE_REGISTRY_VERSION;
                    receivers
                }
            };
            let dkg_tag = transcript.dkg_id.dkg_tag;
            let config_data = NiDkgConfigData {
                dkg_id: NiDkgId {
                    start_block_height: Height::new(transcript.dkg_id.start_block_height.get() + 1),
                    // Theoretically the subnet ID should change on the _first_ DKG in the new
                    // subnet, but this is not important: relevant is only that
                    // the NiDkgId is different, which is already achieved by
                    // increasing the start_block_height.
                    dealer_subnet: transcript.dkg_id.dealer_subnet,
                    dkg_tag,
                    target_subnet: NiDkgTargetSubnet::Local,
                },
                max_corrupt_dealers,
                dealers,
                max_corrupt_receivers: {
                    number_of_nodes_from_usize(get_faults_tolerated(new_subnet_size))
                },
                receivers,
                threshold: number_of_nodes_from_usize(
                    dkg_tag.threshold_for_subnet_of_size(new_subnet_size),
                ),
                registry_version,
                resharing_transcript: Some(transcript),
            };
            Self(NiDkgConfig::new(config_data).expect("invariant violated"))
        }
pub fn reshare ( transcript : NiDkgTranscript , max_subnet_size : usize ) -> Self { let rng = & mut thread_rng ( ) ; // let max_corrupt_dealers = self.0.max_corrupt_receivers(); let max_corrupt_dealers = number_of_nodes_from_usize ( get_faults_tolerated ( transcript . committee . get ( ) . len ( ) ) ) ; let dealers = { let lower_bound_u32 = cmp :: max ( max_corrupt_dealers . get ( ) + 1 , // Ensures #dealers > max_corrupt_dealers transcript . threshold . get ( ) . get ( ) , // Ensures #dealers >= resharing threshold ) ; let lower_bound = usize :: try_from ( lower_bound_u32 ) . expect ( " " ) ; let dealer_count = rng . gen_range ( lower_bound , transcript . committee . get ( ) . len ( ) + 1 ) ; let dealers_vec = transcript . committee . get ( ) . iter ( ) . copied ( ) . choose_multiple ( rng , dealer_count ) ; dealers_vec . into_iter ( ) . collect ( ) } ; let new_subnet_size = { let transcript_committee_len_i32 = i32 :: try_from ( transcript . committee . get ( ) . len ( ) ) . expect ( " " ) ; let new_subnet_size_i32 = cmp :: max ( 1 , transcript_committee_len_i32 + rng . gen_range ( - 2 , 3 ) ) ; let new_subnet_size = usize :: try_from ( new_subnet_size_i32 ) . expect ( " " ) ; cmp :: min ( new_subnet_size , max_subnet_size ) } ; let mut registry_version = transcript . registry_version ; let receivers = { if new_subnet_size <= transcript . committee . get ( ) . len ( ) { // Keep as many receivers as needed from the existing ones let receivers_vec = transcript . committee . get ( ) . iter ( ) . copied ( ) . choose_multiple ( rng , new_subnet_size ) ; receivers_vec . into_iter ( ) . collect ( ) } else { // Keep all existing receivers and add new ones as needed let committee = transcript . committee . get ( ) ; let additional_receivers_count = new_subnet_size - committee . len ( ) ; let additional_receivers = random_node_ids_excluding ( committee , additional_receivers_count ) ; let receivers = committee . union ( & additional_receivers ) . copied ( ) . collect ( ) ; // Adding of nodes means that new nodes will be added to the registry // which in turn means that the registry version needs to be bumped up registry_version += ONE_REGISTRY_VERSION ; receivers } } ; let dkg_tag = transcript . dkg_id . dkg_tag ; let config_data = NiDkgConfigData { dkg_id : NiDkgId { start_block_height : Height :: new ( transcript . dkg_id . start_block_height . get ( ) + 1 ) , // Theoretically the subnet ID should change on the _first_ DKG in the new // subnet, but this is not important: relevant is only that // the NiDkgId is different, which is already achieved by // increasing the start_block_height. dealer_subnet : transcript . dkg_id . dealer_subnet , dkg_tag , target_subnet : NiDkgTargetSubnet :: Local , } , max_corrupt_dealers , dealers , max_corrupt_receivers : { number_of_nodes_from_usize ( get_faults_tolerated ( new_subnet_size ) ) } , receivers , threshold : number_of_nodes_from_usize ( dkg_tag . threshold_for_subnet_of_size ( new_subnet_size ) , ) , registry_version , resharing_transcript : Some ( transcript ) , } ; Self ( NiDkgConfig :: new ( config_data ) . expect ( " " ) ) }
Reshares the config into a new random NI-DKG config with the given
`transcript`.
Reshares the config into a new random NI - DKG config with the given ` transcript ` .
transcript
NiDkgTranscript
max_subnet_size
usize
transcript
NiDkgTranscript
max_subnet_size
usize