/// Iff at version `latest_version` the node id of this node appears on a
/// subnet record that has the `start_as_nns`-flag set, this function will
/// adjust the registry such that the aforementioned subnet will become the
/// new NNS subnet.
///
/// If this node is not partaking in a switch-over, this function
/// immediately returns Ok(()). If any operation fails, an error is
/// returned.
///
/// In case of a switch-over, and if there are no failures, this function
/// exits the process and hence does not return.
Iff at version `latest_version` the node id of this node appears on a
subnet record that has the `start_as_nns`-flag set, this function will
adjust the registry such that the aforementioned subnet will become the
new NNS subnet.

If this node is not partaking in a switch-over, this function
immediately returns Ok(()). If any operation fails, an error is
returned.

In case of a switch-over, and if there are no failures, this function
exits the process and hence does not return.
Iff at version ` latest_version ` the node id of this node appears on a subnet record that has the ` start_as_nns ` - flag set this function will adjust the registry such that the aforementioned subnet will become the new NNS subnet . If this node is not partaking in a switch - over this function immediately returns Ok (( )) . If any operation fails an error is returned . In case of a switch - over and if there are no failures this function exits the process and hence does not return .
fn start_new_nns_subnet(&mut self, latest_version: RegistryVersion) -> Result<(), String> {
        fn map_to_str<E: Debug>(msg: &str, v: RegistryVersion, e: E) -> String {
            format!("{} at version {}: {:?}", msg, v, e)
        }
        let (subnet_id, subnet_record) = match self
            .registry
            .get_listed_subnet_for_node_id(self.node_id, latest_version)
        {
            Ok(Some((id, r))) if r.start_as_nns => (id, r),
            Err(e) => {
                return Err(map_to_str(
                    "Error retrieving subnet records",
                    latest_version,
                    e,
                ))
            }
            _ => return Ok(()),
        };
        assert!(subnet_record.start_as_nns);
        // let k be the least version at which this node is part of the newly created
        // subnet
        let mut v = latest_version - RegistryVersion::from(1);
        let k = loop {
            if self
                .registry
                .get_subnet_record(subnet_id, v)
                .map_err(|e| map_to_str("Could not retrieve subnet record", v, e))?
                .is_none()
            {
                break v + RegistryVersion::from(1);
            }
            v -= RegistryVersion::from(1);
        };
        // IOErrors are treated as fatal.
        let mut changelog = self
            .local_store
            .get_changelog_since_version(RegistryVersion::from(0))
            .expect("Could not read changelog from disk.");
        changelog.truncate(k.get() as usize);
        self.apply_switch_over_to_last_changelog_entry(
            changelog.as_mut_slice(),
            subnet_id,
            subnet_record,
        );
        self.local_store
            .clear()
            .expect("Could not clear registry local store");
        for (v, cle) in changelog.into_iter().enumerate() {
            self.local_store
                .store(RegistryVersion::from((v + 1) as u64), cle)
                .expect("Could not store change log entry");
        }
        warn!(
            self.log,
            "Rebooting node after switch-over to new NNS subnet."
        );
        std::process::exit(1);
    }
fn start_new_nns_subnet ( & mut self , latest_version : RegistryVersion ) -> Result < ( ) , String > { fn map_to_str < E : Debug > ( msg : & str , v : RegistryVersion , e : E ) -> String { format ! ( " " msg v e ) } let ( subnet_id , subnet_record ) = match self . registry . get_listed_subnet_for_node_id ( self . node_id , latest_version ) { Ok ( Some ( ( id , r ) ) ) if r . start_as_nns => ( id , r ) , Err ( e ) => { return Err ( map_to_str ( " " , latest_version , e , ) ) } _ => return Ok ( ( ) ) , } ; assert ! ( subnet_record start_as_nns ) ; // let k be the least version at which this node is part of the newly created // subnet let mut v = latest_version - RegistryVersion :: from ( 1 ) ; let k = loop { if self . registry . get_subnet_record ( subnet_id , v ) . map_err ( | e | map_to_str ( " " , v , e ) ) ? . is_none ( ) { break v + RegistryVersion :: from ( 1 ) ; } v -= RegistryVersion :: from ( 1 ) ; } ; // IOErrors are treated as fatal. let mut changelog = self . local_store . get_changelog_since_version ( RegistryVersion :: from ( 0 ) ) . expect ( " " ) ; changelog . truncate ( k . get ( ) as usize ) ; self . apply_switch_over_to_last_changelog_entry ( changelog . as_mut_slice ( ) , subnet_id , subnet_record , ) ; self . local_store . clear ( ) . expect ( " " ) ; for ( v , cle ) in changelog . into_iter ( ) . enumerate ( ) { self . local_store . store ( RegistryVersion :: from ( ( v + 1 ) as u64 ) , cle ) . expect ( " " ) ; } warn ! ( self log " " ) ; std :: process :: exit ( 1 ) ; }
Iff at version `latest_version` the node id of this node appears on a
subnet record that has the `start_as_nns`-flag set, this function will
adjust the registry such that the aforementioned subnet will become the
new NNS subnet.
Iff at version ` latest_version ` the node id of this node appears on a subnet record that has the ` start_as_nns ` - flag set this function will adjust the registry such that the aforementioned subnet will become the new NNS subnet .
&mut self
latest_version
RegistryVersion