/// Fetch registry records from the given `nns_url`, and update the local
/// registry store with the new records.
Fetch registry records from the given `nns_url`, and update the local
registry store with the new records.
Fetch registry records from the given ` nns_url ` and update the local registry store with the new records .
async fn update_registry_local_store(nns_url: Url, cmd: UpdateRegistryLocalStoreCmd) {
    eprintln!("RegistryLocalStore path: {:?}", cmd.local_store_path);
    let local_store = Arc::new(LocalStoreImpl::new(cmd.local_store_path));
    let local_client = Arc::new(RegistryClientImpl::new(local_store.clone(), None));
    // maximum number of retries, let the user ctrl+c if necessary
    local_client
        .try_polling_latest_version(usize::MAX)
        .expect("Local registry client try_polling_latest_version failed");
    let latest_version = local_client.get_latest_version();
    eprintln!("RegistryLocalStore latest version: {}", latest_version);
    let nns_pub_key = match get_root_subnet_pub_key(local_client.clone(), latest_version) {
        Ok(pub_key) => {
            eprintln!("Root subnet public key found: {:?}", pub_key);
            pub_key
        }
        Err(err) => {
            if cmd.disable_certificate_validation {
                eprintln!("Root subnet public key is not found in RegistryLocalStore. Ignore.");
                // Try again with validation disabled
                use ic_crypto_internal_types::sign::threshold_sig::public_key::bls12_381::PublicKeyBytes;
                PublicKeyBytes([0; PublicKeyBytes::SIZE]).into()
            } else {
                panic!("Error looking up RegistryLocalStore: {}", err)
            }
        }
    };
    let remote_canister = RegistryCanister::new(vec![nns_url.clone()]);
    let response = remote_canister
        .get_certified_changes_since(latest_version.get(), &nns_pub_key)
        .await;
    let records = match response {
        Ok(response) => response.0,
        Err(err) => {
            let throw_err = |err| panic!("Error retrieving registry records: {:?}", err);
            if cmd.disable_certificate_validation {
                remote_canister
                    .get_changes_since_as_transport_records(latest_version.get())
                    .await
                    .unwrap_or_else(throw_err)
            } else {
                throw_err(err)
            }
            .0
        }
    };
    let changelog = records.iter().fold(Changelog::default(), |mut cl, r| {
        let rel_version = (r.version - latest_version).get();
        if cl.len() < rel_version as usize {
            cl.push(ChangelogEntry::default());
        }
        cl.last_mut().unwrap().push(KeyMutation {
            key: r.key.clone(),
            value: r.value.clone(),
        });
        cl
    });
    changelog
        .into_iter()
        .enumerate()
        .try_for_each(|(i, cle)| {
            let v = latest_version + RegistryVersion::from(i as u64 + 1);
            eprintln!("Writing data of registry version {}", v);
            local_store.store(v, cle)
        })
        .expect("Writing to the filesystem failed: Stop.");
    eprintln!("Finished update.");
}
async fn update_registry_local_store ( nns_url : Url , cmd : UpdateRegistryLocalStoreCmd ) { eprintln ! ( " " cmd local_store_path ) ; let local_store = Arc :: new ( LocalStoreImpl :: new ( cmd . local_store_path ) ) ; let local_client = Arc :: new ( RegistryClientImpl :: new ( local_store . clone ( ) , None ) ) ; // maximum number of retries, let the user ctrl+c if necessary local_client . try_polling_latest_version ( usize :: MAX ) . expect ( " " ) ; let latest_version = local_client . get_latest_version ( ) ; eprintln ! ( " " latest_version ) ; let nns_pub_key = match get_root_subnet_pub_key ( local_client . clone ( ) , latest_version ) { Ok ( pub_key ) => { eprintln ! ( " " pub_key ) ; pub_key } Err ( err ) => { if cmd . disable_certificate_validation { eprintln ! ( " " ) ; // Try again with validation disabled use ic_crypto_internal_types :: sign :: threshold_sig :: public_key :: bls12_381 :: PublicKeyBytes ; PublicKeyBytes ( [ 0 ; PublicKeyBytes :: SIZE ] ) . into ( ) } else { panic ! ( " " err ) } } } ; let remote_canister = RegistryCanister :: new ( vec ! [ nns_url clone ( ) ] ) ; let response = remote_canister . get_certified_changes_since ( latest_version . get ( ) , & nns_pub_key ) . await ; let records = match response { Ok ( response ) => response . 0 , Err ( err ) => { let throw_err = | err | panic ! ( " " err ) ; if cmd . disable_certificate_validation { remote_canister . get_changes_since_as_transport_records ( latest_version . get ( ) ) . await . unwrap_or_else ( throw_err ) } else { throw_err ( err ) } . 0 } } ; let changelog = records . iter ( ) . fold ( Changelog :: default ( ) , | mut cl , r | { let rel_version = ( r . version - latest_version ) . get ( ) ; if cl . len ( ) < rel_version as usize { cl . push ( ChangelogEntry :: default ( ) ) ; } cl . last_mut ( ) . unwrap ( ) . push ( KeyMutation { key : r . key . clone ( ) , value : r . value . clone ( ) , } ) ; cl } ) ; changelog . into_iter ( ) . enumerate ( ) . try_for_each ( | ( i , cle ) | { let v = latest_version + RegistryVersion :: from ( i as u64 + 1 ) ; eprintln ! ( " " v ) ; local_store . store ( v , cle ) } ) . expect ( " " ) ; eprintln ! ( " " ) ; }
Fetch registry records from the given `nns_url`, and update the local
registry store with the new records.
Fetch registry records from the given ` nns_url ` and update the local registry store with the new records .
nns_url
Url
cmd
UpdateRegistryLocalStoreCmd