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

Commit

Permalink
compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Oct 8, 2021
1 parent 6abfab3 commit e412104
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 124 deletions.
2 changes: 1 addition & 1 deletion primitives/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ impl CandidateCommitments {
#[derive(Default, PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct DisputedBitfield(pub BitVec<bitvec::order::Lsb0, u8>);

impl From<BitVec<bitvec::order::Lsb0, u8>> for AvailabilityBitfield {
impl From<BitVec<bitvec::order::Lsb0, u8>> for DisputedBitfield {
fn from(inner: BitVec<bitvec::order::Lsb0, u8>) -> Self {
Self(inner)
}
Expand Down
111 changes: 62 additions & 49 deletions runtime/parachains/src/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
use frame_support::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use primitives::v1::{AvailabilityBitfield, BackedCandidate, CandidateCommitments, CandidateDescriptor, CandidateHash, CandidateReceipt, CommittedCandidateReceipt, CoreIndex, DisputedBitfield, GroupIndex, Hash, HeadData, Id as ParaId, SignedAvailabilityBitfields, SigningContext, UncheckedSignedAvailabilityBitfields, ValidatorIndex, ValidityAttestation};
use primitives::v1::{
AvailabilityBitfield, BackedCandidate, CandidateCommitments, CandidateDescriptor,
CandidateHash, CandidateReceipt, CommittedCandidateReceipt, CoreIndex, GroupIndex, Hash,
HeadData, Id as ParaId, SignedAvailabilityBitfields, SigningContext, ValidatorId,
ValidatorIndex, ValidityAttestation,
};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{One, Saturating},
DispatchError,
};
use sp_std::prelude::*;
use sp_std::{collections::btree_set::BTreeSet, prelude::*};

use crate::{configuration, disputes, dmp, hrmp, paras, scheduler::CoreAssignment, shared, ump};

Expand Down Expand Up @@ -258,23 +263,19 @@ impl<T: Config> Pallet<T> {
expected_bits: usize,
checked_bitfields: SignedAvailabilityBitfields,
core_lookup: impl Fn(CoreIndex) -> Option<ParaId>,
validators: &[ValidatorId],
) -> Vec<(CoreIndex, CandidateHash)> {
let validators = shared::Pallet::<T>::active_validator_keys();
let session_index = shared::Pallet::<T>::session_index();

let mut assigned_paras_record = (0..expected_bits)
.map(|bit_index| core_lookup(CoreIndex::from(bit_index as u32)))
.map(|opt_para_id| {
opt_para_id.map(|para_id| (para_id, PendingAvailability::<T>::get(&para_id)))
})
.collect::<Vec<_>>();


let now = <frame_system::Pallet<T>>::block_number();
for checked_bitfield in checked_bitfields {
for (bit_idx, _) in
checked_bitfield.0.iter().enumerate()
.filter(|(_, is_av)| **is_av)
checked_bitfield.payload().0.iter().enumerate().filter(|(_, is_av)| **is_av)
{
let pending_availability = if let Some((_, pending_availability)) =
assigned_paras_record[bit_idx].as_mut()
Expand All @@ -299,9 +300,9 @@ impl<T: Config> Pallet<T> {
}
}

let validator_index = signed_bitfield.validator_index();
let validator_index = checked_bitfield.validator_index();
let record = AvailabilityBitfieldRecord {
bitfield: signed_bitfield.into_payload(),
bitfield: checked_bitfield.into_payload(),
submitted_at: now,
};

Expand Down Expand Up @@ -773,7 +774,7 @@ impl<T: Config> Pallet<T> {
/// Cleans up all paras pending availability that are in the given list of disputed candidates.
///
/// Returns a vector of cleaned-up core IDs.
pub(crate) fn collect_disputed(disputed: Vec<CandidateHash>) -> Vec<CoreIndex> {
pub(crate) fn collect_disputed(disputed: &BTreeSet<CandidateHash>) -> Vec<CoreIndex> {
let mut cleaned_up_ids = Vec::new();
let mut cleaned_up_cores = Vec::new();

Expand Down Expand Up @@ -1310,12 +1311,14 @@ mod tests {
&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,
),
vec![]
);
}

// wrong number of bits: other way around.
Expand All @@ -1329,12 +1332,14 @@ mod tests {
&signing_context,
));

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

// duplicate.
Expand All @@ -1349,12 +1354,14 @@ mod tests {
))
.into();

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

// out of order.
Expand All @@ -1378,12 +1385,14 @@ mod tests {
))
.into();

assert!(ParaInclusion::process_bitfields(
expected_bits(),
vec![signed_1, signed_0],
&core_lookup,
)
.is_err());
assert_eq!(
ParaInclusion::process_bitfields(
expected_bits(),
vec![signed_1, signed_0],
&core_lookup,
),
vec![]
);
}

// non-pending bit set.
Expand All @@ -1403,7 +1412,7 @@ mod tests {
vec![signed.into()],
&core_lookup,
),
Ok(vec![])
vec![]
);
}

Expand All @@ -1418,12 +1427,14 @@ mod tests {
&signing_context,
));

assert!(ParaInclusion::process_bitfields(
expected_bits(),
vec![signed.into()],
&core_lookup,
)
.is_ok());
assert!(
ParaInclusion::process_bitfields(
expected_bits(),
vec![signed.into()],
&core_lookup,
)
.len() == 1
);
}

// bitfield signed with pending bit signed.
Expand Down Expand Up @@ -1460,12 +1471,14 @@ mod tests {
&signing_context,
));

assert!(ParaInclusion::process_bitfields(
expected_bits(),
vec![signed.into()],
&core_lookup,
)
.is_ok());
assert!(
ParaInclusion::process_bitfields(
expected_bits(),
vec![signed.into()],
&core_lookup,
)
.len() == 1
);

<PendingAvailability<Test>>::remove(chain_a);
PendingAvailabilityCommitments::<Test>::remove(chain_a);
Expand Down Expand Up @@ -1508,7 +1521,7 @@ mod tests {
vec![signed.into()],
&core_lookup,
),
Ok(vec![]),
vec![],
);
}
});
Expand Down
Loading

0 comments on commit e412104

Please sign in to comment.