Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix unoccupied bitfields #4004

Merged
3 commits merged into from
Oct 4, 2021
Merged
Changes from 2 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
32 changes: 24 additions & 8 deletions runtime/parachains/src/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ impl<T: Config> Pallet<T> {
// 3. each bitfield has exactly `expected_bits`
// 4. signature is valid.
let signed_bitfields = {
let occupied_bitmask: BitVec<BitOrderLsb0, u8> = assigned_paras_record
.iter()
.map(|p| {
p.as_ref()
.map_or(false, |(_id, pending_availability)| pending_availability.is_some())
})
.collect();

let mut last_index = None;

let signing_context = SigningContext {
Expand All @@ -289,6 +297,13 @@ impl<T: Config> Pallet<T> {
Error::<T>::ValidatorIndexOutOfBounds,
);

// If there is a bit set that shouldn't bet set, we ignore it.
rphmeier marked this conversation as resolved.
Show resolved Hide resolved
if occupied_bitmask.clone() & unchecked_bitfield.unchecked_payload().0.clone() !=
unchecked_bitfield.unchecked_payload().0
{
continue
}

let validator_public =
&validators[unchecked_bitfield.unchecked_validator_index().0 as usize];

Expand Down Expand Up @@ -329,7 +344,7 @@ impl<T: Config> Pallet<T> {
}) {
*bit = true;
} else if cfg!(debug_assertions) {
ensure!(false, Error::<T>::InternalError);
return Err(Error::<T>::InternalError.into())
}
}

Expand Down Expand Up @@ -1412,13 +1427,14 @@ mod tests {
bare_bitfield,
&signing_context,
));

assert!(ParaInclusion::process_bitfields(
expected_bits(),
vec![signed.into()],
&core_lookup,
)
.is_err());
assert_eq!(
ParaInclusion::process_bitfields(
expected_bits(),
vec![signed.into()],
&core_lookup,
),
Ok(vec![])
);
}

// empty bitfield signed: always OK, but kind of useless.
Expand Down