This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
pallet-aura: add feature-flagged explicit slot duration type #14649
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
41d0486
aura: add feature-flagged explicit slot duration type
rphmeier 70e77f4
fmt
rphmeier 10e2039
add some comments
rphmeier 64210af
have node-template use new explicit feature
rphmeier c5a541f
fix mock
rphmeier 9558faa
fmt
rphmeier 3f0272c
Merge branch 'master' into rh-aura-generalize-duration
rphmeier 2bf4d45
Merge branch 'master' into rh-aura-generalize-duration
rphmeier aeef644
use the experimental feature flag instead
rphmeier 4f4359a
checkout master Cargo.lock
rphmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ try-runtime = [ | |
"pallet-timestamp/try-runtime", | ||
"sp-runtime/try-runtime" | ||
] | ||
experimental = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,23 @@ pub use pallet::*; | |
|
||
const LOG_TARGET: &str = "runtime::aura"; | ||
|
||
/// A slot duration provider which infers the slot duration from the | ||
/// [`pallet_timestamp::Config::MinimumPeriod`] by multiplying it by two, to ensure | ||
/// that authors have the majority of their slot to author within. | ||
/// | ||
/// This was the default behavior of the Aura pallet and may be used for | ||
/// backwards compatibility. | ||
/// | ||
/// Note that this type is likely not useful without the `experimental` | ||
/// feature. | ||
pub struct MinimumPeriodTimesTwo<T>(sp_std::marker::PhantomData<T>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's strictly necessary with the explicit-slot-duration feature. I don't see a reason this should be feature flagged as it's strictly additive. |
||
|
||
impl<T: pallet_timestamp::Config> Get<T::Moment> for MinimumPeriodTimesTwo<T> { | ||
fn get() -> T::Moment { | ||
<T as pallet_timestamp::Config>::MinimumPeriod::get().saturating_mul(2u32.into()) | ||
} | ||
} | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
|
@@ -95,6 +112,16 @@ pub mod pallet { | |
/// another pallet which enforces some limitation on the number of blocks authors can create | ||
/// using the same slot. | ||
type AllowMultipleBlocksPerSlot: Get<bool>; | ||
|
||
/// The slot duration Aura should run with, expressed in milliseconds. | ||
/// The effective value of this type should not change while the chain is running. | ||
/// | ||
/// For backwards compatibility either use [`MinimumPeriodTimesTwo`] or a const. | ||
/// | ||
/// This associated type is only present when compiled with the `experimental` | ||
/// feature. | ||
#[cfg(feature = "experimental")] | ||
type SlotDuration: Get<<Self as pallet_timestamp::Config>::Moment>; | ||
} | ||
|
||
#[pallet::pallet] | ||
|
@@ -218,9 +245,17 @@ impl<T: Config> Pallet<T> { | |
|
||
/// Determine the Aura slot-duration based on the Timestamp module configuration. | ||
pub fn slot_duration() -> T::Moment { | ||
// we double the minimum block-period so each author can always propose within | ||
// the majority of its slot. | ||
<T as pallet_timestamp::Config>::MinimumPeriod::get().saturating_mul(2u32.into()) | ||
#[cfg(feature = "experimental")] | ||
{ | ||
T::SlotDuration::get() | ||
} | ||
|
||
#[cfg(not(feature = "experimental"))] | ||
{ | ||
// we double the minimum block-period so each author can always propose within | ||
// the majority of its slot. | ||
<T as pallet_timestamp::Config>::MinimumPeriod::get().saturating_mul(2u32.into()) | ||
} | ||
} | ||
|
||
/// Ensure the correctness of the state of this pallet. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this just to make the doc-CI happy (as it builds with all workspace features)