Skip to content

Commit

Permalink
set the first_slot to zero and fallback to ideal duration for one rou…
Browse files Browse the repository at this point in the history
…nd (#2852)

* set the first_slot to zero and fallback to ideal duration for one round

* fix formatting

---------

Co-authored-by: Rodrigo Quelhas <[email protected]>
  • Loading branch information
librelois and RomarQ authored Jun 27, 2024
1 parent c54b0ac commit 0178eb9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 7 additions & 2 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions pallets/parachain-staking/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ where
// Read round
let mut round = crate::Round::<T>::get();

// Compute theoretical `first_slot``
round.first_slot = compute_theoretical_first_slot(
<frame_system::Pallet<T>>::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::<T>::put(round);
Expand Down

0 comments on commit 0178eb9

Please sign in to comment.