Companion to "Updating scale to v3" (#4958)

* Updating dependencies

* Adapting code to scale v3

* Upgrade bitvec to 1.0.0

* Fix bitvec arithmetics

* Update Cargo.lock

* Update sp-io

* Fixing the build

* Yanked scale-info 2.0.0

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
wigy
2022-02-25 13:07:06 +01:00
committed by GitHub
parent d0c9f75a0b
commit e8cb6cdaac
106 changed files with 680 additions and 556 deletions
@@ -129,7 +129,7 @@ pub fn check_approval(
let n_assigned = assigned_mask.count_ones();
// Filter the amount of assigned validators by those which have approved.
assigned_mask &= approvals.iter().by_val();
assigned_mask &= approvals;
let n_approved = assigned_mask.count_ones();
// note: the process of computing `required` only chooses `exact` if
@@ -326,7 +326,7 @@ fn filled_tranche_iterator<'a>(
/// - if `tick` > `clock_drift`: the value is equal to `tick` + `no_show_duration`.
fn count_no_shows(
assignments: &[(ValidatorIndex, Tick)],
approvals: &BitSlice<BitOrderLsb0, u8>,
approvals: &BitSlice<u8, BitOrderLsb0>,
clock_drift: Tick,
block_tick: Tick,
no_show_duration: Tick,
@@ -367,7 +367,7 @@ fn count_no_shows(
/// Determine the amount of tranches of assignments needed to determine approval of a candidate.
pub fn tranches_to_approve(
approval_entry: &ApprovalEntry,
approvals: &BitSlice<BitOrderLsb0, u8>,
approvals: &BitSlice<u8, BitOrderLsb0>,
tranche_now: DelayTranche,
block_tick: Tick,
no_show_duration: Tick,
@@ -501,7 +501,7 @@ mod tests {
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: BTreeMap::default(),
approvals: bitvec![BitOrderLsb0, u8; 0; 10],
approvals: bitvec![u8, BitOrderLsb0; 0; 10],
}
.into();
@@ -524,7 +524,7 @@ mod tests {
assignments: (5..10).map(|i| (ValidatorIndex(i), 0.into())).collect(),
},
],
assignments: bitvec![BitOrderLsb0, u8; 1; 10],
assignments: bitvec![u8, BitOrderLsb0; 1; 10],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -573,7 +573,7 @@ mod tests {
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: BTreeMap::default(),
approvals: bitvec![BitOrderLsb0, u8; 0; 10],
approvals: bitvec![u8, BitOrderLsb0; 0; 10],
}
.into();
@@ -596,7 +596,7 @@ mod tests {
assignments: (6..10).map(|i| (ValidatorIndex(i), 0.into())).collect(),
},
],
assignments: bitvec![BitOrderLsb0, u8; 1; 10],
assignments: bitvec![u8, BitOrderLsb0; 1; 10],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -649,7 +649,7 @@ mod tests {
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: bitvec![BitOrderLsb0, u8; 0; 5],
assignments: bitvec![u8, BitOrderLsb0; 0; 5],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -665,7 +665,7 @@ mod tests {
approval_entry.import_assignment(2, ValidatorIndex(4), block_tick + 2);
let approvals = bitvec![BitOrderLsb0, u8; 1; 5];
let approvals = bitvec![u8, BitOrderLsb0; 1; 5];
assert_eq!(
tranches_to_approve(
@@ -693,7 +693,7 @@ mod tests {
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: bitvec![BitOrderLsb0, u8; 0; 10],
assignments: bitvec![u8, BitOrderLsb0; 0; 10],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -704,7 +704,7 @@ mod tests {
approval_entry.import_assignment(0, ValidatorIndex(0), block_tick);
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick);
let approvals = bitvec![BitOrderLsb0, u8; 0; 10];
let approvals = bitvec![u8, BitOrderLsb0; 0; 10];
let tranche_now = 2;
assert_eq!(
@@ -733,7 +733,7 @@ mod tests {
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: bitvec![BitOrderLsb0, u8; 0; 10],
assignments: bitvec![u8, BitOrderLsb0; 0; 10],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -746,7 +746,7 @@ mod tests {
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick);
let mut approvals = bitvec![BitOrderLsb0, u8; 0; 10];
let mut approvals = bitvec![u8, BitOrderLsb0; 0; 10];
approvals.set(0, true);
approvals.set(1, true);
@@ -778,7 +778,7 @@ mod tests {
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: bitvec![BitOrderLsb0, u8; 0; n_validators],
assignments: bitvec![u8, BitOrderLsb0; 0; n_validators],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -792,7 +792,7 @@ mod tests {
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick);
approval_entry.import_assignment(1, ValidatorIndex(3), block_tick);
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
let mut approvals = bitvec![u8, BitOrderLsb0; 0; n_validators];
approvals.set(0, true);
approvals.set(1, true);
// skip 2
@@ -845,7 +845,7 @@ mod tests {
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: bitvec![BitOrderLsb0, u8; 0; n_validators],
assignments: bitvec![u8, BitOrderLsb0; 0; n_validators],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -862,7 +862,7 @@ mod tests {
approval_entry.import_assignment(2, ValidatorIndex(4), block_tick + no_show_duration + 2);
approval_entry.import_assignment(2, ValidatorIndex(5), block_tick + no_show_duration + 2);
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
let mut approvals = bitvec![u8, BitOrderLsb0; 0; n_validators];
approvals.set(0, true);
approvals.set(1, true);
// skip 2
@@ -936,7 +936,7 @@ mod tests {
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: bitvec![BitOrderLsb0, u8; 0; n_validators],
assignments: bitvec![u8, BitOrderLsb0; 0; n_validators],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -953,7 +953,7 @@ mod tests {
approval_entry.import_assignment(2, ValidatorIndex(4), block_tick + no_show_duration + 2);
approval_entry.import_assignment(2, ValidatorIndex(5), block_tick + no_show_duration + 2);
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
let mut approvals = bitvec![u8, BitOrderLsb0; 0; n_validators];
approvals.set(0, true);
approvals.set(1, true);
// skip 2
@@ -1033,7 +1033,7 @@ mod tests {
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: BTreeMap::default(),
approvals: bitvec![BitOrderLsb0, u8; 0; 3],
approvals: bitvec![u8, BitOrderLsb0; 0; 3],
}
.into();
@@ -1049,7 +1049,7 @@ mod tests {
assignments: (2..5).map(|i| (ValidatorIndex(i), 1.into())).collect(),
},
],
assignments: bitvec![BitOrderLsb0, u8; 1; 3],
assignments: bitvec![u8, BitOrderLsb0; 1; 3],
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -1057,7 +1057,7 @@ mod tests {
}
.into();
let approvals = bitvec![BitOrderLsb0, u8; 0; 3];
let approvals = bitvec![u8, BitOrderLsb0; 0; 3];
let tranche_now = 10;
assert_eq!(
@@ -1099,7 +1099,7 @@ mod tests {
backing_group: GroupIndex(0),
our_assignment: None,
our_approval_sig: None,
assignments: bitvec![BitOrderLsb0, u8; 0; 3],
assignments: bitvec![u8, BitOrderLsb0; 0; 3],
approved: false,
}
.into();
@@ -1137,7 +1137,7 @@ mod tests {
let n_validators = 4;
let block_tick = 20;
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
let mut approvals = bitvec![u8, BitOrderLsb0; 0; n_validators];
for &v_index in &test.approvals {
approvals.set(v_index, true);
}
@@ -140,7 +140,7 @@ pub struct StoredBlockRange(pub BlockNumber, pub BlockNumber);
pub struct Tick(u64);
/// Convenience type definition
pub type Bitfield = BitVec<BitOrderLsb0, u8>;
pub type Bitfield = BitVec<u8, BitOrderLsb0>;
/// The database config.
#[derive(Debug, Clone, Copy)]
@@ -37,8 +37,8 @@ fn make_db() -> (DbBackend, Arc<dyn KeyValueDB>) {
(DbBackend::new(db_writer.clone(), TEST_CONFIG), db_writer)
}
fn make_bitvec(len: usize) -> BitVec<BitOrderLsb0, u8> {
bitvec::bitvec![BitOrderLsb0, u8; 0; len]
fn make_bitvec(len: usize) -> BitVec<u8, BitOrderLsb0> {
bitvec::bitvec![u8, BitOrderLsb0; 0; len]
}
fn make_block_entry(
@@ -463,9 +463,9 @@ pub(crate) async fn handle_new_head(
block_hash = ?block_hash,
"Insta-approving all candidates",
);
bitvec::bitvec![BitOrderLsb0, u8; 1; num_candidates]
bitvec::bitvec![u8, BitOrderLsb0; 1; num_candidates]
} else {
let mut result = bitvec::bitvec![BitOrderLsb0, u8; 0; num_candidates];
let mut result = bitvec::bitvec![u8, BitOrderLsb0; 0; num_candidates];
for (i, &(_, _, _, backing_group)) in included_candidates.iter().enumerate() {
let backing_group_size =
validator_group_lens.get(backing_group.0 as usize).copied().unwrap_or(0);
@@ -1257,7 +1257,7 @@ async fn handle_approved_ancestor(
let mut block_descriptions = Vec::new();
let mut bits: BitVec<Lsb0, u8> = Default::default();
let mut bits: BitVec<u8, Lsb0> = Default::default();
for (i, block_hash) in std::iter::once(target).chain(ancestry).enumerate() {
// Block entries should be present as the assumption is that
// nothing here is finalized. If we encounter any missing block
@@ -1344,7 +1344,7 @@ async fn handle_approved_ancestor(
let n_approvals = c_entry
.approvals()
.iter()
.by_val()
.by_vals()
.enumerate()
.filter(|(i, approved)| {
*approved && a_entry.is_assigned(ValidatorIndex(*i as _))
@@ -242,7 +242,7 @@ pub fn add_block_entry(
candidate,
session,
block_assignments: BTreeMap::new(),
approvals: bitvec::bitvec![BitOrderLsb0, u8; 0; n_validators],
approvals: bitvec::bitvec![u8, BitOrderLsb0; 0; n_validators],
}
});
@@ -253,7 +253,7 @@ pub fn add_block_entry(
backing_group,
our_assignment.map(|v| v.into()),
None,
bitvec::bitvec![BitOrderLsb0, u8; 0; n_validators],
bitvec::bitvec![u8, BitOrderLsb0; 0; n_validators],
false,
),
);
@@ -80,7 +80,7 @@ pub struct ApprovalEntry {
our_assignment: Option<OurAssignment>,
our_approval_sig: Option<ValidatorSignature>,
// `n_validators` bits.
assignments: BitVec<BitOrderLsb0, u8>,
assignments: BitVec<u8, BitOrderLsb0>,
approved: bool,
}
@@ -92,7 +92,7 @@ impl ApprovalEntry {
our_assignment: Option<OurAssignment>,
our_approval_sig: Option<ValidatorSignature>,
// `n_validators` bits.
assignments: BitVec<BitOrderLsb0, u8>,
assignments: BitVec<u8, BitOrderLsb0>,
approved: bool,
) -> Self {
Self { tranches, backing_group, our_assignment, our_approval_sig, assignments, approved }
@@ -163,9 +163,9 @@ impl ApprovalEntry {
// Produce a bitvec indicating the assignments of all validators up to and
// including `tranche`.
pub fn assignments_up_to(&self, tranche: DelayTranche) -> BitVec<BitOrderLsb0, u8> {
pub fn assignments_up_to(&self, tranche: DelayTranche) -> BitVec<u8, BitOrderLsb0> {
self.tranches.iter().take_while(|e| e.tranche <= tranche).fold(
bitvec::bitvec![BitOrderLsb0, u8; 0; self.assignments.len()],
bitvec::bitvec![u8, BitOrderLsb0; 0; self.assignments.len()],
|mut a, e| {
for &(v, _) in &e.assignments {
a.set(v.0 as _, true);
@@ -253,12 +253,12 @@ pub struct CandidateEntry {
// Assignments are based on blocks, so we need to track assignments separately
// based on the block we are looking at.
pub block_assignments: BTreeMap<Hash, ApprovalEntry>,
pub approvals: BitVec<BitOrderLsb0, u8>,
pub approvals: BitVec<u8, BitOrderLsb0>,
}
impl CandidateEntry {
/// Access the bit-vec of approvals.
pub fn approvals(&self) -> &BitSlice<BitOrderLsb0, u8> {
pub fn approvals(&self) -> &BitSlice<u8, BitOrderLsb0> {
&self.approvals
}
@@ -336,7 +336,7 @@ pub struct BlockEntry {
// A bitfield where the i'th bit corresponds to the i'th candidate in `candidates`.
// The i'th bit is `true` iff the candidate has been approved in the context of this
// block. The block can be considered approved if the bitfield has all bits set to `true`.
pub approved_bitfield: BitVec<BitOrderLsb0, u8>,
pub approved_bitfield: BitVec<u8, BitOrderLsb0>,
pub children: Vec<Hash>,
}