fix regression in approval-voting introduced in #3747 (#3831)

Fixes #3826.

The docs on the `candidates` field of `BlockEntry` were incorrectly
stating that they are sorted by core index. The (incorrect) optimization
was introduced in #3747 based on this assumption. The actual ordering is
based on `CandidateIncluded` events ordering in the runtime. We revert
this optimization here.

- [x] verify the underlying issue
- [x] add a regression test

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
ordian
2024-03-26 23:59:47 +01:00
committed by GitHub
parent ed907819c6
commit 3fc5b82653
3 changed files with 171 additions and 4 deletions
@@ -1285,10 +1285,10 @@ fn cores_to_candidate_indices(
// Map from core index to candidate index.
for claimed_core_index in core_indices.iter_ones() {
// Candidates are sorted by core index.
if let Ok(candidate_index) = block_entry
if let Some(candidate_index) = block_entry
.candidates()
.binary_search_by_key(&(claimed_core_index as u32), |(core_index, _)| core_index.0)
.iter()
.position(|(core_index, _)| core_index.0 == claimed_core_index as u32)
{
candidate_indices.push(candidate_index as _);
}