Skip to content

Commit

Permalink
cumulus: fix test runtimes panic (#2039)
Browse files Browse the repository at this point in the history
the min slot duration should be 0 only if the `experimental` feature is
enabled. otherwise, the runtime will panic on a division by 0.
  • Loading branch information
alindima authored Oct 26, 2023
1 parent 21d36b7 commit 1b08bdd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
}

Expand Down Expand Up @@ -355,7 +358,7 @@ impl_runtime_apis! {

impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
}

fn authorities() -> Vec<AuraId> {
Expand Down
3 changes: 3 additions & 0 deletions cumulus/parachains/runtimes/starters/seedling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ impl pallet_aura::Config for Runtime {
impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ parachains_common::SLOT_DURATION / 2 }>;
type WeightInfo = ();
}

Expand Down
3 changes: 3 additions & 0 deletions cumulus/parachains/runtimes/starters/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ impl pallet_aura::Config for Runtime {
impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ parachains_common::SLOT_DURATION / 2 }>;
type WeightInfo = ();
}

Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
let timestamp_slot = moment / slot_duration;
let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>());

assert!(
CurrentSlot::<T>::get() == timestamp_slot,
assert_eq!(
CurrentSlot::<T>::get(),
timestamp_slot,
"Timestamp slot must match `CurrentSlot`"
);
}
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,9 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
let timestamp_slot = moment / slot_duration;
let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>());

assert!(
CurrentSlot::<T>::get() == timestamp_slot,
assert_eq!(
CurrentSlot::<T>::get(),
timestamp_slot,
"Timestamp slot must match `CurrentSlot`"
);
}
Expand Down

0 comments on commit 1b08bdd

Please sign in to comment.