Fixup backing group computation time (#3170)

Fixes: https://github.com/paritytech/polkadot-sdk/issues/3165

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
This commit is contained in:
Alexandru Gheorghe
2024-02-02 11:02:49 +02:00
committed by GitHub
parent 452f813668
commit 5ba8921787
4 changed files with 87 additions and 1 deletions
@@ -45,6 +45,8 @@ pub fn validators<T: initializer::Config>() -> Vec<ValidatorId> {
/// Implementation for the `validator_groups` function of the runtime API.
pub fn validator_groups<T: initializer::Config>(
) -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumberFor<T>>) {
// This formula needs to be the same as the one we use
// when populating group_responsible in `availability_cores`
let now = <frame_system::Pallet<T>>::block_number() + One::one();
let groups = <scheduler::Pallet<T>>::validator_groups();
@@ -95,6 +97,11 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, Bl
.expect("Occupied core always has pending availability; qed");
let backed_in_number = *pending_availability.backed_in_number();
// Use the same block number for determining the responsible group as what the
// backing subsystem would use when it calls validator_groups api.
let backing_group_allocation_time =
pending_availability.relay_parent_number() + One::one();
CoreState::Occupied(OccupiedCore {
next_up_on_available: <scheduler::Pallet<T>>::next_up_on_available(CoreIndex(
i as u32,
@@ -106,7 +113,7 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, Bl
)),
availability: pending_availability.availability_votes().clone(),
group_responsible: group_responsible_for(
backed_in_number,
backing_group_allocation_time,
pending_availability.core_occupied(),
),
candidate_hash: pending_availability.candidate_hash(),