cumulus: fix test runtimes panic (#2039)

the min slot duration should be 0 only if the `experimental` feature is
enabled. otherwise, the runtime will panic on a division by 0.
This commit is contained in:
Alin Dima
2023-10-26 22:00:51 +03:00
committed by GitHub
parent 21d36b7b42
commit 1b08bdd2dd
5 changed files with 16 additions and 5 deletions
@@ -224,7 +224,10 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
impl pallet_timestamp::Config for Runtime { impl pallet_timestamp::Config for Runtime {
type Moment = u64; type Moment = u64;
type OnTimestampSet = Aura; type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>; type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>; type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
} }
@@ -355,7 +358,7 @@ impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime { impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration { 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> { fn authorities() -> Vec<AuraId> {
@@ -216,7 +216,10 @@ impl pallet_aura::Config for Runtime {
impl pallet_timestamp::Config for Runtime { impl pallet_timestamp::Config for Runtime {
type Moment = u64; type Moment = u64;
type OnTimestampSet = Aura; type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>; type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ parachains_common::SLOT_DURATION / 2 }>;
type WeightInfo = (); type WeightInfo = ();
} }
@@ -219,7 +219,10 @@ impl pallet_aura::Config for Runtime {
impl pallet_timestamp::Config for Runtime { impl pallet_timestamp::Config for Runtime {
type Moment = u64; type Moment = u64;
type OnTimestampSet = Aura; type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>; type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ parachains_common::SLOT_DURATION / 2 }>;
type WeightInfo = (); type WeightInfo = ();
} }
+3 -2
View File
@@ -408,8 +408,9 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
let timestamp_slot = moment / slot_duration; let timestamp_slot = moment / slot_duration;
let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>()); let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>());
assert!( assert_eq!(
CurrentSlot::<T>::get() == timestamp_slot, CurrentSlot::<T>::get(),
timestamp_slot,
"Timestamp slot must match `CurrentSlot`" "Timestamp slot must match `CurrentSlot`"
); );
} }
+3 -2
View File
@@ -900,8 +900,9 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
let timestamp_slot = moment / slot_duration; let timestamp_slot = moment / slot_duration;
let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>()); let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>());
assert!( assert_eq!(
CurrentSlot::<T>::get() == timestamp_slot, CurrentSlot::<T>::get(),
timestamp_slot,
"Timestamp slot must match `CurrentSlot`" "Timestamp slot must match `CurrentSlot`"
); );
} }