/// Returns a list of Registry mutations that add Nodes and Subnets (when
/// applied to a Registry)
///
/// This method will create two subnet records each populated with as many nodes
/// as instructed. It returns the node IDs of the 2nd subnet. If
/// `assign_nodes_to_subnet2` is `false`, the 2nd Subnet will not be created and
/// the nodes that would've been assigned to it are left unassigned.
///
/// Returns:
///     * the initial registry mutate request
///     * the subnet id of the first to-be-created subnet
///     * the IDs of the nodes that are either inserted into the 2nd subnet or
///       unassigned
///     * The mutations that add node records and keys
Returns a list of Registry mutations that add Nodes and Subnets (when
applied to a Registry)

This method will create two subnet records each populated with as many nodes
as instructed. It returns the node IDs of the 2nd subnet. If
`assign_nodes_to_subnet2` is `false`, the 2nd Subnet will not be created and
the nodes that would've been assigned to it are left unassigned.

the initial registry mutate request
the subnet id of the first to-be-created subnet
the IDs of the nodes that are either inserted into the 2nd subnet or
unassigned
The mutations that add node records and keys
Returns a list of Registry mutations that add Nodes and Subnets ( when applied to a Registry ) This method will create two subnet records each populated with as many nodes as instructed . It returns the node IDs of the 2nd subnet . If ` assign_nodes_to_subnet2 ` is ` false ` the 2nd Subnet will not be created and the nodes that would ' ve been assigned to it are left unassigned . the initial registry mutate request the subnet id of the first to - be - created subnet the IDs of the nodes that are either inserted into the 2nd subnet or unassigned The mutations that add node records and keys
pub fn prepare_registry_with_two_node_sets(
    num_nodes_in_subnet1: usize,
    num_nodes_in_subnet2: usize,
    assign_nodes_to_subnet2: bool,
) -> (
    RegistryAtomicMutateRequest,
    SubnetId,
    Vec<NodeId>,
    Vec<RegistryMutation>,
) {
    // Nodes (both assigned and unassigned)
    let mut mutations = invariant_compliant_mutation();
    let mut node_mutations = Vec::<RegistryMutation>::default();
    let node_ids: Vec<NodeId> = (0..num_nodes_in_subnet2 + num_nodes_in_subnet1)
        .map(|idx| {
            let temp_dir = temp_dir();
            let (node_pks, node_id) = get_node_keys_or_generate_if_missing(temp_dir.path());
            mutations.push(insert(
                &make_crypto_node_key(node_id, KeyPurpose::DkgDealingEncryption).as_bytes(),
                encode_or_panic(&node_pks.dkg_dealing_encryption_pk.clone().unwrap()),
            ));
            node_mutations.push(insert(
                &make_crypto_node_key(node_id, KeyPurpose::DkgDealingEncryption).as_bytes(),
                encode_or_panic(&node_pks.dkg_dealing_encryption_pk.unwrap()),
            ));
            let node_key = make_node_record_key(node_id);
            // Connection endpoints must be well-formed and most must be unique
            let ip_addr_prefix = "128.0.0.1:".to_owned();
            let port = 1234;
            let node_record = NodeRecord {
                xnet: Some(connection_endpoint_from_string(
                    &(ip_addr_prefix.clone() + &(port + idx).to_string()),
                )),
                http: Some(connection_endpoint_from_string(
                    &(ip_addr_prefix + &(port - 1 - idx).to_string()),
                )),
                p2p_flow_endpoints: vec!["123,128.0.0.1:10000"]
                    .iter()
                    .map(|x| flow_endpoint_from_string(x))
                    .collect(),
                node_operator_id: PrincipalId::new_user_test_id(999).to_vec(),
                ..Default::default()
            };
            mutations.push(insert(
                &node_key.as_bytes().to_vec(),
                encode_or_panic(&node_record),
            ));
            node_mutations.push(insert(
                &node_key.as_bytes().to_vec(),
                encode_or_panic(&node_record),
            ));
            node_id
        })
        .collect();
    let nodes_in_subnet1_ids = &node_ids[num_nodes_in_subnet2..];
    let nodes_in_subnet2_ids = &node_ids[..num_nodes_in_subnet2];
    let replica_version = ReplicaVersion::default();
    let replica_version_record = ReplicaVersionRecord::default();
    mutations.push(insert(
        &make_replica_version_key(&replica_version.to_string()),
        encode_or_panic(&replica_version_record),
    ));
    // Subnet record 1
    let subnet_record = SubnetRecord {
        replica_version_id: replica_version.to_string(),
        membership: nodes_in_subnet1_ids
            .iter()
            .map(|id| id.get().into_vec())
            .collect(),
        unit_delay_millis: 600,
        gossip_config: Some(build_default_gossip_config()),
        ..Default::default()
    };
    let subnet_id = SubnetId::new(PrincipalId::new_subnet_test_id(17));
    mutations.push(insert(
        make_subnet_record_key(subnet_id).as_bytes(),
        encode_or_panic(&subnet_record),
    ));
    mutations.push(insert(
        make_crypto_threshold_signing_pubkey_key(subnet_id)
            .as_bytes()
            .to_vec(),
        encode_or_panic(&vec![]),
    ));
    // Subnet list record
    let mut subnet_list = decode_registry_value::<SubnetListRecord>(mutations.remove(0).value);
    subnet_list.subnets.push(subnet_id.get().to_vec());
    if assign_nodes_to_subnet2 {
        // Subnet record 2
        let subnet2_record = SubnetRecord {
            replica_version_id: replica_version.to_string(),
            membership: nodes_in_subnet2_ids
                .iter()
                .map(|id| id.get().into_vec())
                .collect(),
            unit_delay_millis: 600,
            gossip_config: Some(build_default_gossip_config()),
            ..Default::default()
        };
        let subnet2_id = SubnetId::new(PrincipalId::new_subnet_test_id(18));
        mutations.push(insert(
            make_subnet_record_key(subnet2_id).as_bytes(),
            encode_or_panic(&subnet2_record),
        ));
        mutations.push(insert(
            make_crypto_threshold_signing_pubkey_key(subnet2_id)
                .as_bytes()
                .to_vec(),
            encode_or_panic(&vec![]),
        ));
        subnet_list.subnets.push(subnet2_id.get().to_vec());
    }
    mutations.push(insert(
        make_subnet_list_record_key().as_bytes(),
        encode_or_panic(&subnet_list),
    ));
    // CUP contents
    let cup_contents_key = make_catch_up_package_contents_key(subnet_id).into_bytes();
    let default_cup_contents = CatchUpPackageContents::default();
    mutations.push(insert(
        cup_contents_key,
        encode_or_panic(&default_cup_contents),
    ));
    let mutate_request = RegistryAtomicMutateRequest {
        mutations,
        preconditions: vec![],
    };
    (
        mutate_request,
        subnet_id,
        nodes_in_subnet2_ids.to_vec(),
        node_mutations,
    )
}
pub fn prepare_registry_with_two_node_sets ( num_nodes_in_subnet1 : usize , num_nodes_in_subnet2 : usize , assign_nodes_to_subnet2 : bool , ) -> ( RegistryAtomicMutateRequest , SubnetId , Vec < NodeId > , Vec < RegistryMutation > , ) { // Nodes (both assigned and unassigned) let mut mutations = invariant_compliant_mutation ( ) ; let mut node_mutations = Vec :: < RegistryMutation > :: default ( ) ; let node_ids : Vec < NodeId > = ( 0 .. num_nodes_in_subnet2 + num_nodes_in_subnet1 ) . map ( | idx | { let temp_dir = temp_dir ( ) ; let ( node_pks , node_id ) = get_node_keys_or_generate_if_missing ( temp_dir . path ( ) ) ; mutations . push ( insert ( & make_crypto_node_key ( node_id , KeyPurpose :: DkgDealingEncryption ) . as_bytes ( ) , encode_or_panic ( & node_pks . dkg_dealing_encryption_pk . clone ( ) . unwrap ( ) ) , ) ) ; node_mutations . push ( insert ( & make_crypto_node_key ( node_id , KeyPurpose :: DkgDealingEncryption ) . as_bytes ( ) , encode_or_panic ( & node_pks . dkg_dealing_encryption_pk . unwrap ( ) ) , ) ) ; let node_key = make_node_record_key ( node_id ) ; // Connection endpoints must be well-formed and most must be unique let ip_addr_prefix = " " . to_owned ( ) ; let port = 1234 ; let node_record = NodeRecord { xnet : Some ( connection_endpoint_from_string ( & ( ip_addr_prefix . clone ( ) + & ( port + idx ) . to_string ( ) ) , ) ) , http : Some ( connection_endpoint_from_string ( & ( ip_addr_prefix + & ( port - 1 - idx ) . to_string ( ) ) , ) ) , p2p_flow_endpoints : vec ! [ " " ] . iter ( ) . map ( | x | flow_endpoint_from_string ( x ) ) . collect ( ) , node_operator_id : PrincipalId :: new_user_test_id ( 999 ) . to_vec ( ) , .. Default :: default ( ) } ; mutations . push ( insert ( & node_key . as_bytes ( ) . to_vec ( ) , encode_or_panic ( & node_record ) , ) ) ; node_mutations . push ( insert ( & node_key . as_bytes ( ) . to_vec ( ) , encode_or_panic ( & node_record ) , ) ) ; node_id } ) . collect ( ) ; let nodes_in_subnet1_ids = & node_ids [ num_nodes_in_subnet2 .. ] ; let nodes_in_subnet2_ids = & node_ids [ .. num_nodes_in_subnet2 ] ; let replica_version = ReplicaVersion :: default ( ) ; let replica_version_record = ReplicaVersionRecord :: default ( ) ; mutations . push ( insert ( & make_replica_version_key ( & replica_version . to_string ( ) ) , encode_or_panic ( & replica_version_record ) , ) ) ; // Subnet record 1 let subnet_record = SubnetRecord { replica_version_id : replica_version . to_string ( ) , membership : nodes_in_subnet1_ids . iter ( ) . map ( | id | id . get ( ) . into_vec ( ) ) . collect ( ) , unit_delay_millis : 600 , gossip_config : Some ( build_default_gossip_config ( ) ) , .. Default :: default ( ) } ; let subnet_id = SubnetId :: new ( PrincipalId :: new_subnet_test_id ( 17 ) ) ; mutations . push ( insert ( make_subnet_record_key ( subnet_id ) . as_bytes ( ) , encode_or_panic ( & subnet_record ) , ) ) ; mutations . push ( insert ( make_crypto_threshold_signing_pubkey_key ( subnet_id ) . as_bytes ( ) . to_vec ( ) , encode_or_panic ( & vec ! [ ] ) , ) ) ; // Subnet list record let mut subnet_list = decode_registry_value :: < SubnetListRecord > ( mutations . remove ( 0 ) . value ) ; subnet_list . subnets . push ( subnet_id . get ( ) . to_vec ( ) ) ; if assign_nodes_to_subnet2 { // Subnet record 2 let subnet2_record = SubnetRecord { replica_version_id : replica_version . to_string ( ) , membership : nodes_in_subnet2_ids . iter ( ) . map ( | id | id . get ( ) . into_vec ( ) ) . collect ( ) , unit_delay_millis : 600 , gossip_config : Some ( build_default_gossip_config ( ) ) , .. Default :: default ( ) } ; let subnet2_id = SubnetId :: new ( PrincipalId :: new_subnet_test_id ( 18 ) ) ; mutations . push ( insert ( make_subnet_record_key ( subnet2_id ) . as_bytes ( ) , encode_or_panic ( & subnet2_record ) , ) ) ; mutations . push ( insert ( make_crypto_threshold_signing_pubkey_key ( subnet2_id ) . as_bytes ( ) . to_vec ( ) , encode_or_panic ( & vec ! [ ] ) , ) ) ; subnet_list . subnets . push ( subnet2_id . get ( ) . to_vec ( ) ) ; } mutations . push ( insert ( make_subnet_list_record_key ( ) . as_bytes ( ) , encode_or_panic ( & subnet_list ) , ) ) ; // CUP contents let cup_contents_key = make_catch_up_package_contents_key ( subnet_id ) . into_bytes ( ) ; let default_cup_contents = CatchUpPackageContents :: default ( ) ; mutations . push ( insert ( cup_contents_key , encode_or_panic ( & default_cup_contents ) , ) ) ; let mutate_request = RegistryAtomicMutateRequest { mutations , preconditions : vec ! [ ] , } ; ( mutate_request , subnet_id , nodes_in_subnet2_ids . to_vec ( ) , node_mutations , ) }
Returns a list of Registry mutations that add Nodes and Subnets (when
applied to a Registry)
Returns a list of Registry mutations that add Nodes and Subnets ( when applied to a Registry )
num_nodes_in_subnet1
usize
num_nodes_in_subnet2
usize
assign_nodes_to_subnet2
bool