fn apply_switch_over_to_last_changelog_entry(
        &self,
        changelog: &mut [ChangelogEntry],
        new_nns_subnet_id: SubnetId,
        mut new_nns_subnet_record: SubnetRecord,
    ) {
        use prost::Message;
        let registry_version = RegistryVersion::from(changelog.len() as u64);

        let routing_table = self
            .registry
            .get_routing_table(registry_version)
            .expect("Could not query registry for routing table.")
            .expect("No routing table configured in registry");

        let old_nns_subnet_id = self
            .registry
            .get_root_subnet_id(registry_version)
            .expect("Could not query registry for nns subnet id")
            .expect("No NNS subnet id configured in the registry");

        assert!(!changelog.is_empty());

        let last = changelog.last_mut().expect("can't fail");
        // remove all entries that will be adjusted
        let subnet_record_key = make_subnet_record_key(new_nns_subnet_id);
        last.retain(|k| {
            k.key != ROOT_SUBNET_ID_KEY
                && k.key != make_subnet_list_record_key()
                && k.key != make_routing_table_record_key()
                && k.key != subnet_record_key
        });

        // remove the start_nns flag on the subnet record
        new_nns_subnet_record.start_as_nns = false;
        // force subnet type to be a system subnet
        new_nns_subnet_record.subnet_type = SubnetType::System as i32;
        // adjust subnet record
        let mut subnet_record_bytes = vec![];
        new_nns_subnet_record
            .encode(&mut subnet_record_bytes)
            .expect("encode can't fail");
        last.push(KeyMutation {
            key: subnet_record_key,
            value: Some(subnet_record_bytes),
        });

        // set nns subnet id (actually, root subnet id)
        let new_nns_subnet_id_proto = SubnetIdProto {
            principal_id: Some(PrincipalIdProto {
                raw: new_nns_subnet_id.get().into_vec(),
            }),
        };
        let mut new_nns_subnet_id_bytes = vec![];
        new_nns_subnet_id_proto
            .encode(&mut new_nns_subnet_id_bytes)
            .expect("encoding can't fail");
        last.push(KeyMutation {
            key: ROOT_SUBNET_ID_KEY.to_string(),
            value: Some(new_nns_subnet_id_bytes),
        });

        // adjust subnet list
        let subnet_list_record = SubnetListRecord {
            subnets: vec![new_nns_subnet_id.get().into_vec()],
        };
        let mut subnet_list_record_bytes = vec![];
        subnet_list_record
            .encode(&mut subnet_list_record_bytes)
            .expect("encoding can't fail");
        last.push(KeyMutation {
            key: make_subnet_list_record_key(),
            value: Some(subnet_list_record_bytes),
        });

        // adjust routing table
        let new_routing_table: BTreeMap<CanisterIdRange, SubnetId> = routing_table
            .into_iter()
            .filter_map(|(r, s_id)| {
                if s_id == old_nns_subnet_id {
                    Some((r, new_nns_subnet_id))
                } else {
                    None
                }
            })
            .collect();

        // It's safe to unwrap here because we started from a valid table and
        // removed entries from it.  Removing entries cannot invalidate the
        // table.
        let new_routing_table =
            RoutingTable::try_from(new_routing_table).expect("bug: invalid routing table");
        let pb_routing_table = PbRoutingTable::from(new_routing_table);
        let mut pb_routing_table_bytes = vec![];
        pb_routing_table
            .encode(&mut pb_routing_table_bytes)
            .expect("encode can't fail");
        last.push(KeyMutation {
            key: make_routing_table_record_key(),
            value: Some(pb_routing_table_bytes),
        });
    }
/// Given a `changelog`, this function applies the changes (as described
/// above) to the last changelog entry.
Given a `changelog`, this function applies the changes (as described
above) to the last changelog entry.
Given a ` changelog ` this function applies the changes ( as described above ) to the last changelog entry .
fn apply_switch_over_to_last_changelog_entry(
        &self,
        changelog: &mut [ChangelogEntry],
        new_nns_subnet_id: SubnetId,
        mut new_nns_subnet_record: SubnetRecord,
    ) {
        use prost::Message;
        let registry_version = RegistryVersion::from(changelog.len() as u64);
        let routing_table = self
            .registry
            .get_routing_table(registry_version)
            .expect("Could not query registry for routing table.")
            .expect("No routing table configured in registry");
        let old_nns_subnet_id = self
            .registry
            .get_root_subnet_id(registry_version)
            .expect("Could not query registry for nns subnet id")
            .expect("No NNS subnet id configured in the registry");
        assert!(!changelog.is_empty());
        let last = changelog.last_mut().expect("can't fail");
        // remove all entries that will be adjusted
        let subnet_record_key = make_subnet_record_key(new_nns_subnet_id);
        last.retain(|k| {
            k.key != ROOT_SUBNET_ID_KEY
                && k.key != make_subnet_list_record_key()
                && k.key != make_routing_table_record_key()
                && k.key != subnet_record_key
        });
        // remove the start_nns flag on the subnet record
        new_nns_subnet_record.start_as_nns = false;
        // force subnet type to be a system subnet
        new_nns_subnet_record.subnet_type = SubnetType::System as i32;
        // adjust subnet record
        let mut subnet_record_bytes = vec![];
        new_nns_subnet_record
            .encode(&mut subnet_record_bytes)
            .expect("encode can't fail");
        last.push(KeyMutation {
            key: subnet_record_key,
            value: Some(subnet_record_bytes),
        });
        // set nns subnet id (actually, root subnet id)
        let new_nns_subnet_id_proto = SubnetIdProto {
            principal_id: Some(PrincipalIdProto {
                raw: new_nns_subnet_id.get().into_vec(),
            }),
        };
        let mut new_nns_subnet_id_bytes = vec![];
        new_nns_subnet_id_proto
            .encode(&mut new_nns_subnet_id_bytes)
            .expect("encoding can't fail");
        last.push(KeyMutation {
            key: ROOT_SUBNET_ID_KEY.to_string(),
            value: Some(new_nns_subnet_id_bytes),
        });
        // adjust subnet list
        let subnet_list_record = SubnetListRecord {
            subnets: vec![new_nns_subnet_id.get().into_vec()],
        };
        let mut subnet_list_record_bytes = vec![];
        subnet_list_record
            .encode(&mut subnet_list_record_bytes)
            .expect("encoding can't fail");
        last.push(KeyMutation {
            key: make_subnet_list_record_key(),
            value: Some(subnet_list_record_bytes),
        });
        // adjust routing table
        let new_routing_table: BTreeMap<CanisterIdRange, SubnetId> = routing_table
            .into_iter()
            .filter_map(|(r, s_id)| {
                if s_id == old_nns_subnet_id {
                    Some((r, new_nns_subnet_id))
                } else {
                    None
                }
            })
            .collect();
        // It's safe to unwrap here because we started from a valid table and
        // removed entries from it.  Removing entries cannot invalidate the
        // table.
        let new_routing_table =
            RoutingTable::try_from(new_routing_table).expect("bug: invalid routing table");
        let pb_routing_table = PbRoutingTable::from(new_routing_table);
        let mut pb_routing_table_bytes = vec![];
        pb_routing_table
            .encode(&mut pb_routing_table_bytes)
            .expect("encode can't fail");
        last.push(KeyMutation {
            key: make_routing_table_record_key(),
            value: Some(pb_routing_table_bytes),
        });
    }
fn apply_switch_over_to_last_changelog_entry ( & self , changelog : & mut [ ChangelogEntry ] , new_nns_subnet_id : SubnetId , mut new_nns_subnet_record : SubnetRecord , ) { use prost :: Message ; let registry_version = RegistryVersion :: from ( changelog . len ( ) as u64 ) ; let routing_table = self . registry . get_routing_table ( registry_version ) . expect ( " " ) . expect ( " " ) ; let old_nns_subnet_id = self . registry . get_root_subnet_id ( registry_version ) . expect ( " " ) . expect ( " " ) ; assert ! ( changelog is_empty ( ) ) ; let last = changelog . last_mut ( ) . expect ( " " ) ; // remove all entries that will be adjusted let subnet_record_key = make_subnet_record_key ( new_nns_subnet_id ) ; last . retain ( | k | { k . key != ROOT_SUBNET_ID_KEY && k . key != make_subnet_list_record_key ( ) && k . key != make_routing_table_record_key ( ) && k . key != subnet_record_key } ) ; // remove the start_nns flag on the subnet record new_nns_subnet_record . start_as_nns = false ; // force subnet type to be a system subnet new_nns_subnet_record . subnet_type = SubnetType :: System as i32 ; // adjust subnet record let mut subnet_record_bytes = vec ! [ ] ; new_nns_subnet_record . encode ( & mut subnet_record_bytes ) . expect ( " " ) ; last . push ( KeyMutation { key : subnet_record_key , value : Some ( subnet_record_bytes ) , } ) ; // set nns subnet id (actually, root subnet id) let new_nns_subnet_id_proto = SubnetIdProto { principal_id : Some ( PrincipalIdProto { raw : new_nns_subnet_id . get ( ) . into_vec ( ) , } ) , } ; let mut new_nns_subnet_id_bytes = vec ! [ ] ; new_nns_subnet_id_proto . encode ( & mut new_nns_subnet_id_bytes ) . expect ( " " ) ; last . push ( KeyMutation { key : ROOT_SUBNET_ID_KEY . to_string ( ) , value : Some ( new_nns_subnet_id_bytes ) , } ) ; // adjust subnet list let subnet_list_record = SubnetListRecord { subnets : vec ! [ new_nns_subnet_id get ( ) into_vec ( ) ] , } ; let mut subnet_list_record_bytes = vec ! [ ] ; subnet_list_record . encode ( & mut subnet_list_record_bytes ) . expect ( " " ) ; last . push ( KeyMutation { key : make_subnet_list_record_key ( ) , value : Some ( subnet_list_record_bytes ) , } ) ; // adjust routing table let new_routing_table : BTreeMap < CanisterIdRange , SubnetId > = routing_table . into_iter ( ) . filter_map ( | ( r , s_id ) | { if s_id == old_nns_subnet_id { Some ( ( r , new_nns_subnet_id ) ) } else { None } } ) . collect ( ) ; // It's safe to unwrap here because we started from a valid table and // removed entries from it.  Removing entries cannot invalidate the // table. let new_routing_table = RoutingTable :: try_from ( new_routing_table ) . expect ( " " ) ; let pb_routing_table = PbRoutingTable :: from ( new_routing_table ) ; let mut pb_routing_table_bytes = vec ! [ ] ; pb_routing_table . encode ( & mut pb_routing_table_bytes ) . expect ( " " ) ; last . push ( KeyMutation { key : make_routing_table_record_key ( ) , value : Some ( pb_routing_table_bytes ) , } ) ; }
Given a `changelog`, this function applies the changes (as described
above) to the last changelog entry.
Given a ` changelog ` this function applies the changes ( as described above ) to the last changelog entry .
&self
changelog
&mut [ChangelogEntry]
new_nns_subnet_id
SubnetId
new_nns_subnet_record
SubnetRecord
&self
changelog
&mut [ChangelogEntry]
new_nns_subnet_id
SubnetId
new_nns_subnet_record
SubnetRecord