fn generate_fake_tree_r_last<TreeArity>(
        nodes_count: usize,
        tree_count: usize,
        tree_r_last_config: StoreConfig,
        replica_path: PathBuf,
    ) -> Result<LCTree<Tree::Hasher, Tree::Arity, Tree::SubTreeArity, Tree::TopTreeArity>>
    where
        TreeArity: PoseidonArity,
    {
        let (configs, replica_config) = split_config_and_replica(
            tree_r_last_config.clone(),
            replica_path,
            nodes_count,
            tree_count,
        )?;

        if settings::SETTINGS.use_gpu_tree_builder {
            info!("generating tree r last using the GPU");
            let max_gpu_tree_batch_size = settings::SETTINGS.max_gpu_tree_batch_size as usize;

            let mut tree_builder = TreeBuilder::<Tree::Arity>::new(
                Some(BatcherType::GPU),
                nodes_count,
                max_gpu_tree_batch_size,
                tree_r_last_config.rows_to_discard,
            )
            .expect("failed to create TreeBuilder");

            // Allocate zeros once and reuse.
            let zero_leaves: Vec<Fr> = vec![Fr::zero(); max_gpu_tree_batch_size];
            for (i, config) in configs.iter().enumerate() {
                let mut consumed = 0;
                while consumed < nodes_count {
                    let batch_size = usize::min(max_gpu_tree_batch_size, nodes_count - consumed);

                    consumed += batch_size;

                    if consumed != nodes_count {
                        tree_builder
                            .add_leaves(&zero_leaves[0..batch_size])
                            .expect("failed to add leaves");
                        continue;
                    };

                    // If we get here, this is a final leaf batch: build a sub-tree.
                    info!(
                        "building base tree_r_last with GPU {}/{}",
                        i + 1,
                        tree_count
                    );

                    let (_, tree_data) = tree_builder
                        .add_final_leaves(&zero_leaves[0..batch_size])
                        .expect("failed to add final leaves");
                    let tree_data_len = tree_data.len();
                    let cache_size = get_merkle_tree_cache_size(
                        get_merkle_tree_leafs(
                            config.size.expect("config size failure"),
                            Tree::Arity::to_usize(),
                        )
                        .expect("failed to get merkle tree leaves"),
                        Tree::Arity::to_usize(),
                        config.rows_to_discard,
                    )
                    .expect("failed to get merkle tree cache size");
                    assert_eq!(tree_data_len, cache_size);

                    let flat_tree_data: Vec<_> = tree_data
                        .into_par_iter()
                        .flat_map(|el| fr_into_bytes(&el))
                        .collect();

                    // Persist the data to the store based on the current config.
                    let tree_r_last_path = StoreConfig::data_path(&config.path, &config.id);
                    trace!(
                        "persisting tree r of len {} with {} rows to discard at path {:?}",
                        tree_data_len,
                        config.rows_to_discard,
                        tree_r_last_path
                    );
                    let mut f = OpenOptions::new()
                        .create(true)
                        .write(true)
                        .open(&tree_r_last_path)
                        .expect("failed to open file for tree_r_last");
                    f.write_all(&flat_tree_data)
                        .expect("failed to wrote tree_r_last data");
                }
            }
        } else {
            info!("generating tree r last using the CPU");
            for (i, config) in configs.iter().enumerate() {
                let encoded_data = vec![<Tree::Hasher as Hasher>::Domain::default(); nodes_count];

                info!(
                    "building base tree_r_last with CPU {}/{}",
                    i + 1,
                    tree_count
                );
                LCTree::<Tree::Hasher, Tree::Arity, typenum::U0, typenum::U0>::from_par_iter_with_config(encoded_data, config.clone())?;
            }
        };

        create_lc_tree::<LCTree<Tree::Hasher, Tree::Arity, Tree::SubTreeArity, Tree::TopTreeArity>>(
            tree_r_last_config.size.expect("config size failure"),
            &configs,
            &replica_config,
        )
    }
// Assumes data is all zeros.
// Replica path is used to create configs, but is not read.
// Instead new zeros are provided (hence the need for replica to be all zeros).
Assumes data is all zeros.
Replica path is used to create configs, but is not read.
Instead new zeros are provided (hence the need for replica to be all zeros).
Assumes data is all zeros . Replica path is used to create configs but is not read . Instead new zeros are provided ( hence the need for replica to be all zeros ) .
fn generate_fake_tree_r_last<TreeArity>(
        nodes_count: usize,
        tree_count: usize,
        tree_r_last_config: StoreConfig,
        replica_path: PathBuf,
    ) -> Result<LCTree<Tree::Hasher, Tree::Arity, Tree::SubTreeArity, Tree::TopTreeArity>>
    where
        TreeArity: PoseidonArity,
    {
        let (configs, replica_config) = split_config_and_replica(
            tree_r_last_config.clone(),
            replica_path,
            nodes_count,
            tree_count,
        )?;
        if settings::SETTINGS.use_gpu_tree_builder {
            info!("generating tree r last using the GPU");
            let max_gpu_tree_batch_size = settings::SETTINGS.max_gpu_tree_batch_size as usize;
            let mut tree_builder = TreeBuilder::<Tree::Arity>::new(
                Some(BatcherType::GPU),
                nodes_count,
                max_gpu_tree_batch_size,
                tree_r_last_config.rows_to_discard,
            )
            .expect("failed to create TreeBuilder");
            // Allocate zeros once and reuse.
            let zero_leaves: Vec<Fr> = vec![Fr::zero(); max_gpu_tree_batch_size];
            for (i, config) in configs.iter().enumerate() {
                let mut consumed = 0;
                while consumed < nodes_count {
                    let batch_size = usize::min(max_gpu_tree_batch_size, nodes_count - consumed);
                    consumed += batch_size;
                    if consumed != nodes_count {
                        tree_builder
                            .add_leaves(&zero_leaves[0..batch_size])
                            .expect("failed to add leaves");
                        continue;
                    };
                    // If we get here, this is a final leaf batch: build a sub-tree.
                    info!(
                        "building base tree_r_last with GPU {}/{}",
                        i + 1,
                        tree_count
                    );
                    let (_, tree_data) = tree_builder
                        .add_final_leaves(&zero_leaves[0..batch_size])
                        .expect("failed to add final leaves");
                    let tree_data_len = tree_data.len();
                    let cache_size = get_merkle_tree_cache_size(
                        get_merkle_tree_leafs(
                            config.size.expect("config size failure"),
                            Tree::Arity::to_usize(),
                        )
                        .expect("failed to get merkle tree leaves"),
                        Tree::Arity::to_usize(),
                        config.rows_to_discard,
                    )
                    .expect("failed to get merkle tree cache size");
                    assert_eq!(tree_data_len, cache_size);
                    let flat_tree_data: Vec<_> = tree_data
                        .into_par_iter()
                        .flat_map(|el| fr_into_bytes(&el))
                        .collect();
                    // Persist the data to the store based on the current config.
                    let tree_r_last_path = StoreConfig::data_path(&config.path, &config.id);
                    trace!(
                        "persisting tree r of len {} with {} rows to discard at path {:?}",
                        tree_data_len,
                        config.rows_to_discard,
                        tree_r_last_path
                    );
                    let mut f = OpenOptions::new()
                        .create(true)
                        .write(true)
                        .open(&tree_r_last_path)
                        .expect("failed to open file for tree_r_last");
                    f.write_all(&flat_tree_data)
                        .expect("failed to wrote tree_r_last data");
                }
            }
        } else {
            info!("generating tree r last using the CPU");
            for (i, config) in configs.iter().enumerate() {
                let encoded_data = vec![<Tree::Hasher as Hasher>::Domain::default(); nodes_count];
                info!(
                    "building base tree_r_last with CPU {}/{}",
                    i + 1,
                    tree_count
                );
                LCTree::<Tree::Hasher, Tree::Arity, typenum::U0, typenum::U0>::from_par_iter_with_config(encoded_data, config.clone())?;
            }
        };
        create_lc_tree::<LCTree<Tree::Hasher, Tree::Arity, Tree::SubTreeArity, Tree::TopTreeArity>>(
            tree_r_last_config.size.expect("config size failure"),
            &configs,
            &replica_config,
        )
    }
fn generate_fake_tree_r_last < TreeArity > ( nodes_count : usize , tree_count : usize , tree_r_last_config : StoreConfig , replica_path : PathBuf , ) -> Result < LCTree < Tree :: Hasher , Tree :: Arity , Tree :: SubTreeArity , Tree :: TopTreeArity > > where TreeArity : PoseidonArity , { let ( configs , replica_config ) = split_config_and_replica ( tree_r_last_config . clone ( ) , replica_path , nodes_count , tree_count , ) ? ; if settings :: SETTINGS . use_gpu_tree_builder { info ! ( " " ) ; let max_gpu_tree_batch_size = settings :: SETTINGS . max_gpu_tree_batch_size as usize ; let mut tree_builder = TreeBuilder :: < Tree :: Arity > :: new ( Some ( BatcherType :: GPU ) , nodes_count , max_gpu_tree_batch_size , tree_r_last_config . rows_to_discard , ) . expect ( " " ) ; // Allocate zeros once and reuse. let zero_leaves : Vec < Fr > = vec ! [ Fr zero ( ) max_gpu_tree_batch_size ] ; for ( i , config ) in configs . iter ( ) . enumerate ( ) { let mut consumed = 0 ; while consumed < nodes_count { let batch_size = usize :: min ( max_gpu_tree_batch_size , nodes_count - consumed ) ; consumed += batch_size ; if consumed != nodes_count { tree_builder . add_leaves ( & zero_leaves [ 0 .. batch_size ] ) . expect ( " " ) ; continue ; } ; // If we get here, this is a final leaf batch: build a sub-tree. info ! ( " " i 1 tree_count ) ; let ( _ , tree_data ) = tree_builder . add_final_leaves ( & zero_leaves [ 0 .. batch_size ] ) . expect ( " " ) ; let tree_data_len = tree_data . len ( ) ; let cache_size = get_merkle_tree_cache_size ( get_merkle_tree_leafs ( config . size . expect ( " " ) , Tree :: Arity :: to_usize ( ) , ) . expect ( " " ) , Tree :: Arity :: to_usize ( ) , config . rows_to_discard , ) . expect ( " " ) ; assert_eq ! ( tree_data_len cache_size ) ; let flat_tree_data : Vec < _ > = tree_data . into_par_iter ( ) . flat_map ( | el | fr_into_bytes ( & el ) ) . collect ( ) ; // Persist the data to the store based on the current config. let tree_r_last_path = StoreConfig :: data_path ( & config . path , & config . id ) ; trace ! ( " " tree_data_len config rows_to_discard tree_r_last_path ) ; let mut f = OpenOptions :: new ( ) . create ( true ) . write ( true ) . open ( & tree_r_last_path ) . expect ( " " ) ; f . write_all ( & flat_tree_data ) . expect ( " " ) ; } } } else { info ! ( " " ) ; for ( i , config ) in configs . iter ( ) . enumerate ( ) { let encoded_data = vec ! [ Tree Hasher as Hasher Domain default ( ) nodes_count ] ; info ! ( " " i 1 tree_count ) ; LCTree :: < Tree :: Hasher , Tree :: Arity , typenum :: U0 , typenum :: U0 > :: from_par_iter_with_config ( encoded_data , config . clone ( ) ) ? ; } } ; create_lc_tree :: < LCTree < Tree :: Hasher , Tree :: Arity , Tree :: SubTreeArity , Tree :: TopTreeArity > > ( tree_r_last_config . size . expect ( " " ) , & configs , & replica_config , ) }
Assumes data is all zeros.
Assumes data is all zeros .
nodes_count
usize
tree_count
usize
tree_r_last_config
StoreConfig
replica_path
PathBuf
nodes_count
usize
tree_count
usize
tree_r_last_config
StoreConfig
replica_path
PathBuf