pallet-aura: Allow multiple blocks per slot (#14024)

* pallet-aura: Allow multiple blocks per slot

* run fmt

* rework as associated type

* fix fallout

* fmt

* use constbool

* fmt
This commit is contained in:
asynchronous rob
2023-06-09 16:04:37 -05:00
committed by GitHub
parent 881fd1e0dc
commit 62f37e105c
4 changed files with 86 additions and 2 deletions
+20 -1
View File
@@ -81,6 +81,20 @@ pub mod pallet {
/// Blocks authored by a disabled validator will lead to a panic as part of this module's
/// initialization.
type DisabledValidators: DisabledValidators;
/// Whether to allow block authors to create multiple blocks per slot.
///
/// If this is `true`, the pallet will allow slots to stay the same across sequential
/// blocks. If this is `false`, the pallet will require that subsequent blocks always have
/// higher slots than previous ones.
///
/// Regardless of the setting of this storage value, the pallet will always enforce the
/// invariant that slots don't move backwards as the chain progresses.
///
/// The typical value for this should be 'false' unless this pallet is being augmented by
/// another pallet which enforces some limitation on the number of blocks authors can create
/// using the same slot.
type AllowMultipleBlocksPerSlot: Get<bool>;
}
#[pallet::pallet]
@@ -92,7 +106,12 @@ pub mod pallet {
if let Some(new_slot) = Self::current_slot_from_digests() {
let current_slot = CurrentSlot::<T>::get();
assert!(current_slot < new_slot, "Slot must increase");
if T::AllowMultipleBlocksPerSlot::get() {
assert!(current_slot <= new_slot, "Slot must not decrease");
} else {
assert!(current_slot < new_slot, "Slot must increase");
}
CurrentSlot::<T>::put(new_slot);
if let Some(n_authorities) = <Authorities<T>>::decode_len() {