Skip to content

Commit 3510e12

Browse files
alindimas0me0ne-unkn0wn
authored andcommitted
runtime: assume elastic scaling MVP is always enabled (#7986)
The runtime part of #6352. The node-side part is handled by #7286 (which should be merged first)
1 parent 538bb36 commit 3510e12

File tree

11 files changed

+355
-519
lines changed

11 files changed

+355
-519
lines changed

polkadot/node/core/backing/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ fn table_attested_to_backed(
650650
.map(|(pos_in_votes, _pos_in_group)| validity_votes[pos_in_votes].clone())
651651
.collect(),
652652
validator_indices,
653-
Some(core_index),
653+
core_index,
654654
))
655655
}
656656

polkadot/node/core/backing/src/tests/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ fn backing_works() {
905905
assert_eq!(candidates[0].validity_votes().len(), 3);
906906

907907
let (validator_indices, maybe_core_index) =
908-
candidates[0].validator_indices_and_core_index(true);
908+
candidates[0].validator_indices_and_core_index();
909909

910910
assert_eq!(maybe_core_index.unwrap(), CoreIndex(0));
911911

@@ -1553,7 +1553,7 @@ fn backing_works_while_validation_ongoing() {
15531553
.validity_votes()
15541554
.contains(&ValidityAttestation::Explicit(signed_c.signature().clone())));
15551555
assert_eq!(
1556-
candidates[0].validator_indices_and_core_index(true),
1556+
candidates[0].validator_indices_and_core_index(),
15571557
(
15581558
bitvec::bitvec![u8, bitvec::order::Lsb0; 1, 0, 1, 1].as_bitslice(),
15591559
Some(CoreIndex(0))
@@ -2224,7 +2224,7 @@ fn candidate_backing_reorders_votes() {
22242224
vec![fake_attestation(1).into(), fake_attestation(3).into(), fake_attestation(5).into()];
22252225

22262226
assert_eq!(
2227-
backed.validator_indices_and_core_index(true),
2227+
backed.validator_indices_and_core_index(),
22282228
(expected_bitvec.as_bitslice(), Some(CoreIndex(10)))
22292229
);
22302230
assert_eq!(backed.validity_votes(), expected_attestations);

polkadot/node/core/provisioner/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ mod select_candidates {
304304
},
305305
Vec::new(),
306306
default_bitvec(MOCK_GROUP_SIZE),
307-
None,
307+
CoreIndex(0),
308308
)
309309
})
310310
.collect();
@@ -716,7 +716,7 @@ mod select_candidates {
716716
committed_receipt.clone(),
717717
Vec::new(),
718718
default_bitvec(MOCK_GROUP_SIZE),
719-
None,
719+
CoreIndex(0),
720720
)
721721
})
722722
.collect();
@@ -818,7 +818,7 @@ mod select_candidates {
818818
committed_receipt.clone(),
819819
Vec::new(),
820820
default_bitvec(MOCK_GROUP_SIZE),
821-
None,
821+
CoreIndex(0),
822822
)
823823
})
824824
.collect();
@@ -1006,7 +1006,7 @@ mod select_candidates {
10061006
},
10071007
Vec::new(),
10081008
default_bitvec(MOCK_GROUP_SIZE),
1009-
None,
1009+
CoreIndex(0),
10101010
)
10111011
})
10121012
.collect();

polkadot/primitives/src/v8/mod.rs

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,8 @@ pub struct BackedCandidate<H = Hash> {
754754
candidate: CommittedCandidateReceipt<H>,
755755
/// The validity votes themselves, expressed as signatures.
756756
validity_votes: Vec<ValidityAttestation>,
757-
/// The indices of the validators within the group, expressed as a bitfield. May be extended
758-
/// beyond the backing group size to contain the assigned core index, if ElasticScalingMVP is
759-
/// enabled.
757+
/// The indices of the validators within the group, expressed as a bitfield. Is extended
758+
/// beyond the backing group size to contain the assigned core index.
760759
validator_indices: BitVec<u8, bitvec::order::Lsb0>,
761760
}
762761

@@ -766,12 +765,10 @@ impl<H> BackedCandidate<H> {
766765
candidate: CommittedCandidateReceipt<H>,
767766
validity_votes: Vec<ValidityAttestation>,
768767
validator_indices: BitVec<u8, bitvec::order::Lsb0>,
769-
core_index: Option<CoreIndex>,
768+
core_index: CoreIndex,
770769
) -> Self {
771770
let mut instance = Self { candidate, validity_votes, validator_indices };
772-
if let Some(core_index) = core_index {
773-
instance.inject_core_index(core_index);
774-
}
771+
instance.inject_core_index(core_index);
775772
instance
776773
}
777774

@@ -814,20 +811,13 @@ impl<H> BackedCandidate<H> {
814811
/// Get a copy of the validator indices and the assumed core index, if any.
815812
pub fn validator_indices_and_core_index(
816813
&self,
817-
core_index_enabled: bool,
818814
) -> (&BitSlice<u8, bitvec::order::Lsb0>, Option<CoreIndex>) {
819-
// This flag tells us if the block producers must enable Elastic Scaling MVP hack.
820-
// It extends `BackedCandidate::validity_indices` to store a 8 bit core index.
821-
if core_index_enabled {
822-
let core_idx_offset = self.validator_indices.len().saturating_sub(8);
823-
if core_idx_offset > 0 {
824-
let (validator_indices_slice, core_idx_slice) =
825-
self.validator_indices.split_at(core_idx_offset);
826-
return (
827-
validator_indices_slice,
828-
Some(CoreIndex(core_idx_slice.load::<u8>() as u32)),
829-
);
830-
}
815+
// `BackedCandidate::validity_indices` are extended to store a 8 bit core index.
816+
let core_idx_offset = self.validator_indices.len().saturating_sub(8);
817+
if core_idx_offset > 0 {
818+
let (validator_indices_slice, core_idx_slice) =
819+
self.validator_indices.split_at(core_idx_offset);
820+
return (validator_indices_slice, Some(CoreIndex(core_idx_slice.load::<u8>() as u32)));
831821
}
832822

833823
(&self.validator_indices, None)
@@ -2311,60 +2301,35 @@ pub mod tests {
23112301
dummy_committed_candidate_receipt(),
23122302
vec![],
23132303
initial_validator_indices.clone(),
2314-
None,
2304+
CoreIndex(10),
23152305
);
23162306

2317-
// No core index supplied, ElasticScalingMVP is off.
2318-
let (validator_indices, core_index) = candidate.validator_indices_and_core_index(false);
2319-
assert_eq!(validator_indices, initial_validator_indices.as_bitslice());
2320-
assert!(core_index.is_none());
2321-
2322-
// No core index supplied, ElasticScalingMVP is on. Still, decoding will be ok if backing
2323-
// group size is <= 8, to give a chance to parachains that don't have multiple cores
2324-
// assigned.
2325-
let (validator_indices, core_index) = candidate.validator_indices_and_core_index(true);
2307+
// No core index supplied.
2308+
candidate
2309+
.set_validator_indices_and_core_index(initial_validator_indices.clone().into(), None);
2310+
let (validator_indices, core_index) = candidate.validator_indices_and_core_index();
23262311
assert_eq!(validator_indices, initial_validator_indices.as_bitslice());
23272312
assert!(core_index.is_none());
23282313

2329-
let encoded_validator_indices = candidate.validator_indices.clone();
2330-
candidate.set_validator_indices_and_core_index(validator_indices.into(), core_index);
2331-
assert_eq!(candidate.validator_indices, encoded_validator_indices);
2332-
2333-
// No core index supplied, ElasticScalingMVP is on. Decoding is corrupted if backing group
2314+
// No core index supplied. Decoding is corrupted if backing group
23342315
// size larger than 8.
2335-
let candidate = BackedCandidate::new(
2336-
dummy_committed_candidate_receipt(),
2337-
vec![],
2338-
bitvec![u8, bitvec::order::Lsb0; 0, 1, 0, 1, 0, 1, 0, 1, 0],
2316+
candidate.set_validator_indices_and_core_index(
2317+
bitvec![u8, bitvec::order::Lsb0; 0, 1, 0, 1, 0, 1, 0, 1, 0].into(),
23392318
None,
23402319
);
2341-
let (validator_indices, core_index) = candidate.validator_indices_and_core_index(true);
2320+
2321+
let (validator_indices, core_index) = candidate.validator_indices_and_core_index();
23422322
assert_eq!(validator_indices, bitvec![u8, bitvec::order::Lsb0; 0].as_bitslice());
23432323
assert!(core_index.is_some());
23442324

2345-
// Core index supplied, ElasticScalingMVP is off. Core index will be treated as normal
2346-
// validator indices. Runtime will check against this.
2347-
let candidate = BackedCandidate::new(
2348-
dummy_committed_candidate_receipt(),
2349-
vec![],
2350-
bitvec![u8, bitvec::order::Lsb0; 0, 1, 0, 1],
2351-
Some(CoreIndex(10)),
2352-
);
2353-
let (validator_indices, core_index) = candidate.validator_indices_and_core_index(false);
2354-
assert_eq!(
2355-
validator_indices,
2356-
bitvec![u8, bitvec::order::Lsb0; 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0]
2357-
);
2358-
assert!(core_index.is_none());
2359-
2360-
// Core index supplied, ElasticScalingMVP is on.
2325+
// Core index supplied.
23612326
let mut candidate = BackedCandidate::new(
23622327
dummy_committed_candidate_receipt(),
23632328
vec![],
23642329
bitvec![u8, bitvec::order::Lsb0; 0, 1, 0, 1],
2365-
Some(CoreIndex(10)),
2330+
CoreIndex(10),
23662331
);
2367-
let (validator_indices, core_index) = candidate.validator_indices_and_core_index(true);
2332+
let (validator_indices, core_index) = candidate.validator_indices_and_core_index();
23682333
assert_eq!(validator_indices, bitvec![u8, bitvec::order::Lsb0; 0, 1, 0, 1]);
23692334
assert_eq!(core_index, Some(CoreIndex(10)));
23702335

polkadot/primitives/src/vstaging/mod.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,10 @@ impl<H> BackedCandidate<H> {
709709
candidate: CommittedCandidateReceiptV2<H>,
710710
validity_votes: Vec<ValidityAttestation>,
711711
validator_indices: BitVec<u8, bitvec::order::Lsb0>,
712-
core_index: Option<CoreIndex>,
712+
core_index: CoreIndex,
713713
) -> Self {
714714
let mut instance = Self { candidate, validity_votes, validator_indices };
715-
if let Some(core_index) = core_index {
716-
instance.inject_core_index(core_index);
717-
}
715+
instance.inject_core_index(core_index);
718716
instance
719717
}
720718

@@ -769,20 +767,13 @@ impl<H> BackedCandidate<H> {
769767
/// Get a copy of the validator indices and the assumed core index, if any.
770768
pub fn validator_indices_and_core_index(
771769
&self,
772-
core_index_enabled: bool,
773770
) -> (&BitSlice<u8, bitvec::order::Lsb0>, Option<CoreIndex>) {
774-
// This flag tells us if the block producers must enable Elastic Scaling MVP hack.
775-
// It extends `BackedCandidate::validity_indices` to store a 8 bit core index.
776-
if core_index_enabled {
777-
let core_idx_offset = self.validator_indices.len().saturating_sub(8);
778-
if core_idx_offset > 0 {
779-
let (validator_indices_slice, core_idx_slice) =
780-
self.validator_indices.split_at(core_idx_offset);
781-
return (
782-
validator_indices_slice,
783-
Some(CoreIndex(core_idx_slice.load::<u8>() as u32)),
784-
);
785-
}
771+
// `BackedCandidate::validity_indices` are extended to store a 8 bit core index.
772+
let core_idx_offset = self.validator_indices.len().saturating_sub(8);
773+
if core_idx_offset > 0 {
774+
let (validator_indices_slice, core_idx_slice) =
775+
self.validator_indices.split_at(core_idx_offset);
776+
return (validator_indices_slice, Some(CoreIndex(core_idx_slice.load::<u8>() as u32)));
786777
}
787778

788779
(&self.validator_indices, None)

polkadot/runtime/parachains/src/builder.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
3333
use frame_support::pallet_prelude::*;
3434
use frame_system::pallet_prelude::*;
3535
use polkadot_primitives::{
36-
node_features::FeatureIndex,
3736
vstaging::{
3837
BackedCandidate, CandidateDescriptorV2, ClaimQueueOffset,
3938
CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreSelector,
@@ -763,16 +762,6 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
763762
})
764763
.collect();
765764

766-
// Don't inject core when it is available in descriptor.
767-
let core_idx = if candidate.descriptor.core_index().is_some() {
768-
None
769-
} else {
770-
configuration::ActiveConfig::<T>::get()
771-
.node_features
772-
.get(FeatureIndex::ElasticScalingMVP as usize)
773-
.and_then(|the_bit| if *the_bit { Some(core_idx) } else { None })
774-
};
775-
776765
BackedCandidate::<T::Hash>::new(
777766
candidate,
778767
validity_votes,

polkadot/runtime/parachains/src/inclusion/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ impl<T: Config> Pallet<T> {
628628
allowed_relay_parents: &AllowedRelayParentsTracker<T::Hash, BlockNumberFor<T>>,
629629
candidates: &BTreeMap<ParaId, Vec<(BackedCandidate<T::Hash>, CoreIndex)>>,
630630
group_validators: GV,
631-
core_index_enabled: bool,
632631
) -> Result<
633632
Vec<(CandidateReceipt<T::Hash>, Vec<(ValidatorIndex, ValidityAttestation)>)>,
634633
DispatchError,
@@ -688,12 +687,8 @@ impl<T: Config> Pallet<T> {
688687
group_validators(group_idx).ok_or_else(|| Error::<T>::InvalidGroupIndex)?;
689688

690689
// Check backing vote count and validity.
691-
let (backers, backer_idx_and_attestation) = Self::check_backing_votes(
692-
candidate,
693-
&validators,
694-
group_vals,
695-
core_index_enabled,
696-
)?;
690+
let (backers, backer_idx_and_attestation) =
691+
Self::check_backing_votes(candidate, &validators, group_vals)?;
697692

698693
// Found a valid candidate.
699694
latest_head_data = candidate.candidate().commitments.head_data.clone();
@@ -760,7 +755,6 @@ impl<T: Config> Pallet<T> {
760755
backed_candidate: &BackedCandidate<T::Hash>,
761756
validators: &[ValidatorId],
762757
group_vals: Vec<ValidatorIndex>,
763-
core_index_enabled: bool,
764758
) -> Result<(BitVec<u8, BitOrderLsb0>, Vec<(ValidatorIndex, ValidityAttestation)>), Error<T>> {
765759
let minimum_backing_votes = configuration::ActiveConfig::<T>::get().minimum_backing_votes;
766760

@@ -770,8 +764,7 @@ impl<T: Config> Pallet<T> {
770764
session_index: shared::CurrentSessionIndex::<T>::get(),
771765
};
772766

773-
let (validator_indices, _) =
774-
backed_candidate.validator_indices_and_core_index(core_index_enabled);
767+
let (validator_indices, _) = backed_candidate.validator_indices_and_core_index();
775768

776769
// check the signatures in the backing and that it is a majority.
777770
let maybe_amount_validated = polkadot_primitives::check_candidate_backing(

0 commit comments

Comments
 (0)