Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
RomarQ marked this conversation as resolved.
Show resolved Hide resolved
<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
Loading