pub fn generate_candidates(
    post_config: PoStConfig,
    randomness: &ChallengeSeed,
    challenge_count: u64,
    replicas: &BTreeMap<SectorId, PrivateReplicaInfo>,
    prover_id: ProverId,
) -> Result<Vec<Candidate>> {
    info!("generate_candidates:start");

    let vanilla_params = post_setup_params(post_config);
    let setup_params = compound_proof::SetupParams {
        vanilla_params,
        partitions: None,
    };
    let public_params: compound_proof::PublicParams<
        election_post::ElectionPoSt<DefaultTreeHasher>,
    > = ElectionPoStCompound::setup(&setup_params)?;

    let sector_count = replicas.len() as u64;
    ensure!(sector_count > 0, "Must supply at least one replica");

    let sectors = replicas.keys().copied().collect();

    let challenged_sectors =
        election_post::generate_sector_challenges(randomness, challenge_count, &sectors)?;

    // Match the replicas to the challenges, as these are the only ones required.
    let challenged_replicas: Vec<_> = challenged_sectors
        .iter()
        .map(|c| {
            if let Some(replica) = replicas.get(c) {
                Ok((c, replica))
            } else {
                Err(anyhow!(
                    "Invalid challenge generated: {}, only {} sectors are being proven",
                    c,
                    sector_count
                ))
            }
        })
        .collect::<Result<_, _>>()?;

    // Generate merkle trees for the challenged replicas.
    // Merkle trees should be generated only once, not multiple times if the same sector is challenged
    // multiple times, so we build a HashMap of trees.

    let mut unique_challenged_replicas = challenged_replicas.clone();
    unique_challenged_replicas.sort_unstable(); // dedup requires a sorted list
    unique_challenged_replicas.dedup();

    let tree_size = get_tree_size(post_config.sector_size);
    let tree_leafs = get_merkle_tree_leafs(tree_size);

    let unique_trees_res: Vec<_> = unique_challenged_replicas
        .into_par_iter()
        .map(|(id, replica)| {
            replica
                .merkle_tree(tree_size, tree_leafs)
                .map(|tree| (*id, tree))
        })
        .collect();

    // resolve results
    let trees: BTreeMap<SectorId, Tree> = unique_trees_res.into_iter().collect::<Result<_, _>>()?;

    let candidates = election_post::generate_candidates::<DefaultTreeHasher>(
        public_params.vanilla_params.sector_size,
        &challenged_sectors,
        &trees,
        &prover_id,
        randomness,
    )?;

    info!("generate_candidates:finish");

    Ok(candidates)
}
/// Generates proof-of-spacetime candidates for ElectionPoSt.
Generates proof-of-spacetime candidates for ElectionPoSt.
Generates proof - of - spacetime candidates for ElectionPoSt .
pub fn generate_candidates(
    post_config: PoStConfig,
    randomness: &ChallengeSeed,
    challenge_count: u64,
    replicas: &BTreeMap<SectorId, PrivateReplicaInfo>,
    prover_id: ProverId,
) -> Result<Vec<Candidate>> {
    info!("generate_candidates:start");
    let vanilla_params = post_setup_params(post_config);
    let setup_params = compound_proof::SetupParams {
        vanilla_params,
        partitions: None,
    };
    let public_params: compound_proof::PublicParams<
        election_post::ElectionPoSt<DefaultTreeHasher>,
    > = ElectionPoStCompound::setup(&setup_params)?;
    let sector_count = replicas.len() as u64;
    ensure!(sector_count > 0, "Must supply at least one replica");
    let sectors = replicas.keys().copied().collect();
    let challenged_sectors =
        election_post::generate_sector_challenges(randomness, challenge_count, &sectors)?;
    // Match the replicas to the challenges, as these are the only ones required.
    let challenged_replicas: Vec<_> = challenged_sectors
        .iter()
        .map(|c| {
            if let Some(replica) = replicas.get(c) {
                Ok((c, replica))
            } else {
                Err(anyhow!(
                    "Invalid challenge generated: {}, only {} sectors are being proven",
                    c,
                    sector_count
                ))
            }
        })
        .collect::<Result<_, _>>()?;
    // Generate merkle trees for the challenged replicas.
    // Merkle trees should be generated only once, not multiple times if the same sector is challenged
    // multiple times, so we build a HashMap of trees.
    let mut unique_challenged_replicas = challenged_replicas.clone();
    unique_challenged_replicas.sort_unstable(); // dedup requires a sorted list
    unique_challenged_replicas.dedup();
    let tree_size = get_tree_size(post_config.sector_size);
    let tree_leafs = get_merkle_tree_leafs(tree_size);
    let unique_trees_res: Vec<_> = unique_challenged_replicas
        .into_par_iter()
        .map(|(id, replica)| {
            replica
                .merkle_tree(tree_size, tree_leafs)
                .map(|tree| (*id, tree))
        })
        .collect();
    // resolve results
    let trees: BTreeMap<SectorId, Tree> = unique_trees_res.into_iter().collect::<Result<_, _>>()?;
    let candidates = election_post::generate_candidates::<DefaultTreeHasher>(
        public_params.vanilla_params.sector_size,
        &challenged_sectors,
        &trees,
        &prover_id,
        randomness,
    )?;
    info!("generate_candidates:finish");
    Ok(candidates)
}
pub fn generate_candidates ( post_config : PoStConfig , randomness : & ChallengeSeed , challenge_count : u64 , replicas : & BTreeMap < SectorId , PrivateReplicaInfo > , prover_id : ProverId , ) -> Result < Vec < Candidate > > { info ! ( " " ) ; let vanilla_params = post_setup_params ( post_config ) ; let setup_params = compound_proof :: SetupParams { vanilla_params , partitions : None , } ; let public_params : compound_proof :: PublicParams < election_post :: ElectionPoSt < DefaultTreeHasher > , > = ElectionPoStCompound :: setup ( & setup_params ) ? ; let sector_count = replicas . len ( ) as u64 ; ensure ! ( sector_count 0 " " ) ; let sectors = replicas . keys ( ) . copied ( ) . collect ( ) ; let challenged_sectors = election_post :: generate_sector_challenges ( randomness , challenge_count , & sectors ) ? ; // Match the replicas to the challenges, as these are the only ones required. let challenged_replicas : Vec < _ > = challenged_sectors . iter ( ) . map ( | c | { if let Some ( replica ) = replicas . get ( c ) { Ok ( ( c , replica ) ) } else { Err ( anyhow ! ( " " c sector_count ) ) } } ) . collect :: < Result < _ , _ > > ( ) ? ; // Generate merkle trees for the challenged replicas. // Merkle trees should be generated only once, not multiple times if the same sector is challenged // multiple times, so we build a HashMap of trees. let mut unique_challenged_replicas = challenged_replicas . clone ( ) ; unique_challenged_replicas . sort_unstable ( ) ; // dedup requires a sorted list unique_challenged_replicas . dedup ( ) ; let tree_size = get_tree_size ( post_config . sector_size ) ; let tree_leafs = get_merkle_tree_leafs ( tree_size ) ; let unique_trees_res : Vec < _ > = unique_challenged_replicas . into_par_iter ( ) . map ( | ( id , replica ) | { replica . merkle_tree ( tree_size , tree_leafs ) . map ( | tree | ( * id , tree ) ) } ) . collect ( ) ; // resolve results let trees : BTreeMap < SectorId , Tree > = unique_trees_res . into_iter ( ) . collect :: < Result < _ , _ > > ( ) ? ; let candidates = election_post :: generate_candidates :: < DefaultTreeHasher > ( public_params . vanilla_params . sector_size , & challenged_sectors , & trees , & prover_id , randomness , ) ? ; info ! ( " " ) ; Ok ( candidates ) }
Generates proof-of-spacetime candidates for ElectionPoSt.
Generates proof - of - spacetime candidates for ElectionPoSt .
post_config
PoStConfig
randomness
&ChallengeSeed
challenge_count
u64
replicas
&BTreeMap<SectorId, PrivateReplicaInfo>
prover_id
ProverId
post_config
PoStConfig
randomness
&ChallengeSeed
challenge_count
u64
replicas
&BTreeMap<SectorId, PrivateReplicaInfo>
prover_id
ProverId