First step in implementing #4386 (#4437)

* First step in implementing https://github.com/paritytech/polkadot/issues/4386

This PR:

- Reduces MAX_UNSHARED_UPLOAD_TIME to 150ms
- Increases timeout on collation fetching to 1200ms
- Reduces limit on needed backing votes in the runtime

This PR does not yet reduce the number of needed backing votes on the
node as this can only be meaningfully enacted once the changed limit in
the runtime is live.

* Fix tests.

* Guide updates.

* Review remarks.

* Bump minimum required backing votes to 2 in runtime.

* Make sure node side code won't make runtime vomit.

* cargo +nightly fmt
This commit is contained in:
Robert Klotzner
2021-12-23 17:41:34 +01:00
committed by GitHub
parent 4689ccffce
commit 846828f61c
6 changed files with 44 additions and 19 deletions
@@ -169,6 +169,15 @@ impl<H> Default for ProcessedCandidates<H> {
}
}
/// Number of backing votes we need for a valid backing.
pub fn minimum_backing_votes(n_validators: usize) -> usize {
// For considerations on this value see:
// https://github.com/paritytech/polkadot/pull/1656#issuecomment-999734650
// and
// https://github.com/paritytech/polkadot/issues/4386
sp_std::cmp::min(n_validators, 2)
}
#[frame_support::pallet]
pub mod pallet {
use super::*;
@@ -578,7 +587,7 @@ impl<T: Config> Pallet<T> {
match maybe_amount_validated {
Ok(amount_validated) => ensure!(
amount_validated * 2 > group_vals.len(),
amount_validated >= minimum_backing_votes(group_vals.len()),
Error::<T>::InsufficientBacking,
),
Err(()) => {
@@ -113,7 +113,7 @@ pub(crate) async fn back_candidate(
kind: BackingKind,
) -> BackedCandidate {
let mut validator_indices = bitvec::bitvec![BitOrderLsb0, u8; 0; group.len()];
let threshold = (group.len() / 2) + 1;
let threshold = minimum_backing_votes(group.len());
let signing = match kind {
BackingKind::Unanimous => group.len(),
@@ -151,8 +151,8 @@ pub(crate) async fn back_candidate(
Some(validators[group[i].0 as usize].public().into())
})
.ok()
.unwrap_or(0) *
2 > group.len();
.unwrap_or(0) >=
threshold;
match kind {
BackingKind::Unanimous | BackingKind::Threshold => assert!(successfully_backed),
@@ -1651,6 +1651,10 @@ fn backing_works() {
assure_candidate_sorting(candidate_receipt_with_backing_validator_indices)
);
let backers = {
let num_backers = minimum_backing_votes(group_validators(GroupIndex(0)).unwrap().len());
backing_bitfield(&(0..num_backers).collect::<Vec<_>>())
};
assert_eq!(
<PendingAvailability<Test>>::get(&chain_a),
Some(CandidatePendingAvailability {
@@ -1660,7 +1664,7 @@ fn backing_works() {
availability_votes: default_availability_votes(),
relay_parent_number: System::block_number() - 1,
backed_in_number: System::block_number(),
backers: backing_bitfield(&[0, 1]),
backers,
backing_group: GroupIndex::from(0),
})
);
@@ -1669,6 +1673,10 @@ fn backing_works() {
Some(candidate_a.commitments),
);
let backers = {
let num_backers = minimum_backing_votes(group_validators(GroupIndex(0)).unwrap().len());
backing_bitfield(&(0..num_backers).map(|v| v + 2).collect::<Vec<_>>())
};
assert_eq!(
<PendingAvailability<Test>>::get(&chain_b),
Some(CandidatePendingAvailability {
@@ -1678,7 +1686,7 @@ fn backing_works() {
availability_votes: default_availability_votes(),
relay_parent_number: System::block_number() - 1,
backed_in_number: System::block_number(),
backers: backing_bitfield(&[2, 3]),
backers,
backing_group: GroupIndex::from(1),
})
);
@@ -1790,6 +1798,10 @@ fn can_include_candidate_with_ok_code_upgrade() {
assert_eq!(occupied_cores, vec![CoreIndex::from(0)]);
let backers = {
let num_backers = minimum_backing_votes(group_validators(GroupIndex(0)).unwrap().len());
backing_bitfield(&(0..num_backers).collect::<Vec<_>>())
};
assert_eq!(
<PendingAvailability<Test>>::get(&chain_a),
Some(CandidatePendingAvailability {
@@ -1799,7 +1811,7 @@ fn can_include_candidate_with_ok_code_upgrade() {
availability_votes: default_availability_votes(),
relay_parent_number: System::block_number() - 1,
backed_in_number: System::block_number(),
backers: backing_bitfield(&[0, 1, 2]),
backers,
backing_group: GroupIndex::from(0),
})
);