Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions polkadot/runtime/parachains/src/paras_inherent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,16 +1328,24 @@ fn filter_backed_statements_from_disabled_validators<
// The indices of statements from disabled validators in `BackedCandidate`. We have to drop
// these.
let indices_to_drop = disabled_indices.clone() & &validator_indices;
// Apply the bitmask to drop the disabled validator from `validator_indices`
validator_indices &= !disabled_indices;
// Update the backed candidate
bc.set_validator_indices_and_core_index(validator_indices, maybe_injected_core_index);

// Remove the corresponding votes from `validity_votes`
for idx in indices_to_drop.iter_ones().rev() {
bc.validity_votes_mut().remove(idx);
// Map the index in `indices_to_drop` (which is an index into the validator group)
// to the index in the validity votes vector, which might have less number of votes,
// than validators assigned to the group.
//
// For each index `idx` in `indices_to_drop`, the corresponding index in the
// validity votes vector is the number of `1` bits in `validator_indices` before `idx`.
let mapped_idx = validator_indices[..idx].count_ones();
bc.validity_votes_mut().remove(mapped_idx);
Comment thread
sandreim marked this conversation as resolved.
Comment thread
sandreim marked this conversation as resolved.
}

// Apply the bitmask to drop the disabled validator from `validator_indices`
validator_indices &= !disabled_indices;
// Update the backed candidate
bc.set_validator_indices_and_core_index(validator_indices, maybe_injected_core_index);

// By filtering votes we might render the candidate invalid and cause a failure in
// [`process_candidates`]. To avoid this we have to perform a sanity check here. If there
// are not enough backing votes after filtering we will remove the whole candidate.
Expand Down
38 changes: 38 additions & 0 deletions polkadot/runtime/parachains/src/paras_inherent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4776,5 +4776,43 @@ mod sanitizers {
});
}
}

// Disable Bob which is second validator in group for core 0.
// Para 0 candidate has a single valid vote that is removed
Comment thread
sandreim marked this conversation as resolved.
// because Bob is disabled.
//
// This test ensures we remove the right validty votes from the backed candidate
#[test]
fn drop_right_indices() {
new_test_ext(default_config()).execute_with(|| {
let TestData { mut expected_backed_candidates_with_core, .. } =
get_test_data_one_core_per_para();

set_disabled_validators(vec![1]);

let (backed, _) = expected_backed_candidates_with_core
.get_mut(&ParaId::from(1))
.unwrap()
.first_mut()
.unwrap();
let (indices, core) = backed.validator_indices_and_core_index();
let mut indices = BitVec::<_>::from(indices);

indices.set(0, false);
backed.validity_votes_mut().remove(0);
backed.set_validator_indices_and_core_index(indices, core);

let mut untouched = expected_backed_candidates_with_core.clone();

filter_backed_statements_from_disabled_validators::<Test>(
&mut expected_backed_candidates_with_core,
&shared::AllowedRelayParents::<Test>::get(),
);

untouched.remove(&ParaId::from(1)).unwrap();

assert_eq!(expected_backed_candidates_with_core, untouched);
});
}
}
}
Loading