Skip to content

Commit

Permalink
Merge pull request AleoNet#2250 from AleoHQ/fix/bound-candidate-solut…
Browse files Browse the repository at this point in the history
…ions

Add proper bound for valid candidate solutions
  • Loading branch information
howardwu authored Dec 18, 2023
2 parents 5e71c1e + 02101fc commit c5f609e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions ledger/src/advance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,29 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
let coinbase_verifying_key = self.coinbase_puzzle.coinbase_verifying_key();
// Retrieve the latest epoch challenge.
let latest_epoch_challenge = self.latest_epoch_challenge()?;
// TODO: For mainnet - Add `aborted_solution_ids` to the block. And optimize this logic.
// Verify the candidate solutions.
let verification_results: Vec<_> = cfg_into_iter!(candidate_solutions)
.map(|solution| {
(
solution,
solution
.verify(coinbase_verifying_key, &latest_epoch_challenge, self.latest_proof_target())
.unwrap_or(false),
)
})
.collect();
// Separate the candidate solutions into valid and aborted solutions.
// TODO: Add `aborted_solution_ids` to the block.
let (valid_candidate_solutions, _aborted_candidate_solutions): (Vec<_>, Vec<_>) =
cfg_into_iter!(candidate_solutions).partition(|solution| {
solution
.verify(coinbase_verifying_key, &latest_epoch_challenge, self.latest_proof_target())
.unwrap_or(false)
});
let mut valid_candidate_solutions = Vec::with_capacity(N::MAX_SOLUTIONS);
let mut aborted_candidate_solutions = Vec::new();
for (solution, is_valid) in verification_results.into_iter() {
if is_valid && valid_candidate_solutions.len() < N::MAX_SOLUTIONS {
valid_candidate_solutions.push(solution);
} else {
aborted_candidate_solutions.push(solution);
}
}

// Check if there are any valid solutions.
match valid_candidate_solutions.is_empty() {
true => (None, Field::<N>::zero(), 0u128),
Expand Down

0 comments on commit c5f609e

Please sign in to comment.