diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 30169489fe..828ecaf812 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -468,8 +468,13 @@ pub mod pallet { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 0)); // Compute round duration in slots - let round_duration = (current_slot.saturating_sub(round.first_slot)) - .saturating_mul(T::SlotDuration::get()); + let round_duration = if round.first_slot == 0 { + // If the first slot is zero, we fallback to the ideal duration + (round.length as u64).saturating_mul(T::BlockTime::get()) + } else { + (current_slot.saturating_sub(round.first_slot)) + .saturating_mul(T::SlotDuration::get()) + }; // mutate round round.update(n, current_slot); diff --git a/pallets/parachain-staking/src/migrations.rs b/pallets/parachain-staking/src/migrations.rs index 9f32be7a4e..5a087679a6 100644 --- a/pallets/parachain-staking/src/migrations.rs +++ b/pallets/parachain-staking/src/migrations.rs @@ -64,13 +64,12 @@ where // Read round let mut round = crate::Round::::get(); - // Compute theoretical `first_slot`` - round.first_slot = compute_theoretical_first_slot( - >::block_number(), - round.first, - u64::from(T::SlotProvider::get()), - T::BlockTime::get(), - ); + // Force the `first_slot` to zero + // We can't compute the theoretical first slot because we don't have access to the + // relay slot + // To handle that, we added a hack in pallet staking that fallback to the ideal round + // duration if `first_slot` is zero. + round.first_slot = 0; // Apply the migration (write new Round value) crate::Round::::put(round);