Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: better select challenges function #1731

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions filecoin-proofs/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,21 @@ pub fn setup_params(porep_config: &PoRepConfig) -> Result<stacked::SetupParams>
})
}

/// Division of x by y, rounding up.
/// x and y must be > 0
const fn div_ceil(x: usize, y: usize) -> usize {
1 + ((x - 1) / y)
}

fn select_challenges(
partitions: usize,
minimum_total_challenges: usize,
use_synthetic: bool,
) -> LayerChallenges {
let mut count = 1;
let mut guess = LayerChallenges::new(count);
while partitions * guess.challenges_count_all() < minimum_total_challenges {
count += 1;
guess = LayerChallenges::new(count);
}

guess.use_synthetic = use_synthetic;
guess
let challenges = div_ceil(minimum_total_challenges, partitions);
let mut result = LayerChallenges::new(challenges);
result.use_synthetic = use_synthetic;
result
}

#[cfg(test)]
Expand Down