pub fn read_cached_params(cache_entry_path: &PathBuf) -> Result<groth16::MappedParameters<Bls12>> {
    info!("checking cache_path: {:?} for parameters", cache_entry_path);

    let verify_production_params = settings::SETTINGS.verify_production_params;

    // If the verify production params is set, we make sure that the path being accessed matches a
    // production cache key, found in the 'parameters.json' file. The parameter data file is also
    // hashed and matched against the hash in the `parameters.json` file.
    if verify_production_params {
        let cache_key = cache_entry_path
            .file_name()
            .expect("failed to get cached param filename")
            .to_str()
            .expect("failed to convert to str")
            .to_string();

        match get_parameter_data_from_id(&cache_key) {
            Some(data) => {
                // Verify the actual hash only once per parameters file
                let not_yet_verified = VERIFIED_PARAMETERS
                    .lock()
                    .expect("verified parameters lock failed")
                    .get(&cache_key)
                    .is_none();
                if not_yet_verified {
                    info!("generating consistency digest for parameters");
                    let hash = with_exclusive_read_lock(cache_entry_path, |mut file| {
                        let mut hasher = Blake2bParams::new().to_state();
                        io::copy(&mut file, &mut hasher).expect("copying file into hasher failed");
                        Ok(hasher.finalize())
                    })?;
                    info!("generated consistency digest for parameters");

                    // The hash in the parameters file is truncated to 256 bits.
                    let digest_hex = &hash.to_hex()[..32];

                    if digest_hex != data.digest {
                        return Err(Error::InvalidParameters(
                            cache_entry_path.display().to_string(),
                        )
                        .into());
                    }

                    VERIFIED_PARAMETERS
                        .lock()
                        .expect("verified parameters lock failed")
                        .insert(cache_key);
                }
            }
            None => {
                return Err(Error::InvalidParameters(cache_entry_path.display().to_string()).into())
            }
        }
    }

    with_exclusive_read_lock(cache_entry_path, |_| {
        let mapped_params =
            Parameters::build_mapped_parameters(cache_entry_path.to_path_buf(), false)?;
        info!("read parameters from cache {:?} ", cache_entry_path);

        Ok(mapped_params)
    })
}
// Reads parameter mappings using mmap so that they can be lazily
// loaded later.
Reads parameter mappings using mmap so that they can be lazily
loaded later.
Reads parameter mappings using mmap so that they can be lazily loaded later .
pub fn read_cached_params(cache_entry_path: &PathBuf) -> Result<groth16::MappedParameters<Bls12>> {
    info!("checking cache_path: {:?} for parameters", cache_entry_path);
    let verify_production_params = settings::SETTINGS.verify_production_params;
    // If the verify production params is set, we make sure that the path being accessed matches a
    // production cache key, found in the 'parameters.json' file. The parameter data file is also
    // hashed and matched against the hash in the `parameters.json` file.
    if verify_production_params {
        let cache_key = cache_entry_path
            .file_name()
            .expect("failed to get cached param filename")
            .to_str()
            .expect("failed to convert to str")
            .to_string();
        match get_parameter_data_from_id(&cache_key) {
            Some(data) => {
                // Verify the actual hash only once per parameters file
                let not_yet_verified = VERIFIED_PARAMETERS
                    .lock()
                    .expect("verified parameters lock failed")
                    .get(&cache_key)
                    .is_none();
                if not_yet_verified {
                    info!("generating consistency digest for parameters");
                    let hash = with_exclusive_read_lock(cache_entry_path, |mut file| {
                        let mut hasher = Blake2bParams::new().to_state();
                        io::copy(&mut file, &mut hasher).expect("copying file into hasher failed");
                        Ok(hasher.finalize())
                    })?;
                    info!("generated consistency digest for parameters");
                    // The hash in the parameters file is truncated to 256 bits.
                    let digest_hex = &hash.to_hex()[..32];
                    if digest_hex != data.digest {
                        return Err(Error::InvalidParameters(
                            cache_entry_path.display().to_string(),
                        )
                        .into());
                    }
                    VERIFIED_PARAMETERS
                        .lock()
                        .expect("verified parameters lock failed")
                        .insert(cache_key);
                }
            }
            None => {
                return Err(Error::InvalidParameters(cache_entry_path.display().to_string()).into())
            }
        }
    }
    with_exclusive_read_lock(cache_entry_path, |_| {
        let mapped_params =
            Parameters::build_mapped_parameters(cache_entry_path.to_path_buf(), false)?;
        info!("read parameters from cache {:?} ", cache_entry_path);
        Ok(mapped_params)
    })
}
pub fn read_cached_params ( cache_entry_path : & PathBuf ) -> Result < groth16 :: MappedParameters < Bls12 > > { info ! ( " " cache_entry_path ) ; let verify_production_params = settings :: SETTINGS . verify_production_params ; // If the verify production params is set, we make sure that the path being accessed matches a // production cache key, found in the 'parameters.json' file. The parameter data file is also // hashed and matched against the hash in the `parameters.json` file. if verify_production_params { let cache_key = cache_entry_path . file_name ( ) . expect ( " " ) . to_str ( ) . expect ( " " ) . to_string ( ) ; match get_parameter_data_from_id ( & cache_key ) { Some ( data ) => { // Verify the actual hash only once per parameters file let not_yet_verified = VERIFIED_PARAMETERS . lock ( ) . expect ( " " ) . get ( & cache_key ) . is_none ( ) ; if not_yet_verified { info ! ( " " ) ; let hash = with_exclusive_read_lock ( cache_entry_path , | mut file | { let mut hasher = Blake2bParams :: new ( ) . to_state ( ) ; io :: copy ( & mut file , & mut hasher ) . expect ( " " ) ; Ok ( hasher . finalize ( ) ) } ) ? ; info ! ( " " ) ; // The hash in the parameters file is truncated to 256 bits. let digest_hex = & hash . to_hex ( ) [ .. 32 ] ; if digest_hex != data . digest { return Err ( Error :: InvalidParameters ( cache_entry_path . display ( ) . to_string ( ) , ) . into ( ) ) ; } VERIFIED_PARAMETERS . lock ( ) . expect ( " " ) . insert ( cache_key ) ; } } None => { return Err ( Error :: InvalidParameters ( cache_entry_path . display ( ) . to_string ( ) ) . into ( ) ) } } } with_exclusive_read_lock ( cache_entry_path , | _ | { let mapped_params = Parameters :: build_mapped_parameters ( cache_entry_path . to_path_buf ( ) , false ) ? ; info ! ( " " cache_entry_path ) ; Ok ( mapped_params ) } ) }
Reads parameter mappings using mmap so that they can be lazily
loaded later.
Reads parameter mappings using mmap so that they can be lazily loaded later .
cache_entry_path
&PathBuf
cache_entry_path
&PathBuf