-
Notifications
You must be signed in to change notification settings - Fork 804
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
Migrate pallet-aura
to umbrella crate
#6622
base: master
Are you sure you want to change the base?
Changes from 9 commits
a4b0c01
7c38b15
1d19f12
da689ef
0356076
d94f026
abf0a09
6e07bf6
f7e241b
61fc9b1
d4e31b8
cbba423
76f1e12
e57100d
5d5400a
85afcc5
7c953fd
00ce153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: migrate pallet-aura to umbrella crate | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
This PR | ||
- Imports frame umbrella crate systems into pallet-aura. | ||
- Includes BoundedSlice as a runtime::prelude export from the polkadot-sdk-frame crate. | ||
- Includes `sp-application-crypto` in polkadot-sdk-frame crate, re-exports | ||
`RuntimeAppPublic` and `BoundToRuntimeAppPublic` as part of the cryptography module. | ||
- Adds a consensus module for commonly used consensus types. | ||
|
||
crates: | ||
- name: pallet-aura | ||
bump: minor | ||
- name: polkadot-sdk-frame | ||
bump: minor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,17 +42,14 @@ extern crate alloc; | |
|
||
use alloc::vec::Vec; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use frame_support::{ | ||
traits::{DisabledValidators, FindAuthor, Get, OnTimestampSet, OneSessionHandler}, | ||
BoundedSlice, BoundedVec, ConsensusEngineId, Parameter, | ||
use frame::{ | ||
runtime::prelude::*, | ||
traits::{DisabledValidators, FindAuthor, IsMember, OnTimestampSet, OneSessionHandler}, | ||
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. I would add 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. Also moved
|
||
}; | ||
use log; | ||
use sp_consensus_aura::{AuthorityIndex, ConsensusLog, Slot, AURA_ENGINE_ID}; | ||
use sp_runtime::{ | ||
generic::DigestItem, | ||
traits::{IsMember, Member, SaturatedConversion, Saturating, Zero}, | ||
RuntimeAppPublic, | ||
}; | ||
|
||
#[cfg(feature = "try-runtime")] | ||
use frame::try_runtime::TryRuntimeError; | ||
|
||
pub mod migrations; | ||
mod mock; | ||
|
@@ -76,11 +73,9 @@ impl<T: pallet_timestamp::Config> Get<T::Moment> for MinimumPeriodTimesTwo<T> { | |
} | ||
} | ||
|
||
#[frame_support::pallet] | ||
#[frame::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: pallet_timestamp::Config + frame_system::Config { | ||
|
@@ -157,7 +152,7 @@ pub mod pallet { | |
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> { | ||
fn try_state(_: BlockNumberFor<T>) -> Result<(), TryRuntimeError> { | ||
Self::do_try_state() | ||
} | ||
} | ||
|
@@ -174,7 +169,7 @@ pub mod pallet { | |
pub type CurrentSlot<T: Config> = StorageValue<_, Slot, ValueQuery>; | ||
|
||
#[pallet::genesis_config] | ||
#[derive(frame_support::DefaultNoBound)] | ||
#[derive(DefaultNoBound)] | ||
pub struct GenesisConfig<T: Config> { | ||
pub authorities: Vec<T::AuthorityId>, | ||
} | ||
|
@@ -265,7 +260,7 @@ impl<T: Config> Pallet<T> { | |
/// * The number of authorities must be less than or equal to `T::MaxAuthorities`. This however, | ||
/// is guarded by the type system. | ||
#[cfg(any(test, feature = "try-runtime"))] | ||
pub fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> { | ||
pub fn do_try_state() -> Result<(), TryRuntimeError> { | ||
// We don't have any guarantee that we are already after `on_initialize` and thus we have to | ||
// check the current slot from the digest or take the last known slot. | ||
let current_slot = | ||
|
@@ -274,7 +269,7 @@ impl<T: Config> Pallet<T> { | |
// Check that the current slot is less than the maximal slot number, unless we allow for | ||
// multiple blocks per slot. | ||
if !T::AllowMultipleBlocksPerSlot::get() { | ||
frame_support::ensure!( | ||
ensure!( | ||
current_slot < u64::MAX, | ||
"Current slot has reached maximum value and cannot be incremented further.", | ||
); | ||
|
@@ -284,11 +279,11 @@ impl<T: Config> Pallet<T> { | |
<Authorities<T>>::decode_len().ok_or("Failed to decode authorities length")?; | ||
|
||
// Check that the authorities are non-empty. | ||
frame_support::ensure!(!authorities_len.is_zero(), "Authorities must be non-empty."); | ||
ensure!(!authorities_len.is_zero(), "Authorities must be non-empty."); | ||
|
||
// Check that the current authority is not disabled. | ||
let authority_index = *current_slot % authorities_len as u64; | ||
frame_support::ensure!( | ||
ensure!( | ||
!T::DisabledValidators::is_disabled(authority_index as u32), | ||
"Current validator is disabled and should not be attempting to author blocks.", | ||
); | ||
|
@@ -297,7 +292,7 @@ impl<T: Config> Pallet<T> { | |
} | ||
} | ||
|
||
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Pallet<T> { | ||
impl<T: Config> BoundToRuntimeAppPublic for Pallet<T> { | ||
type Public = T::AuthorityId; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,7 +214,10 @@ pub mod prelude { | |
pub use super::derive::*; | ||
|
||
/// All hashing related things | ||
pub use super::hashing::*; | ||
pub use super::cryptography::*; | ||
|
||
/// Consensus types needed in runtime construction. | ||
pub use super::consensus::*; | ||
|
||
/// Runtime traits | ||
#[doc(no_inline)] | ||
|
@@ -308,7 +311,7 @@ pub mod testing_prelude { | |
/// Other helper macros from `frame_support` that help with asserting in tests. | ||
pub use frame_support::{ | ||
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok, | ||
assert_storage_noop, storage_alias, | ||
assert_storage_noop, storage_alias, ensure, | ||
}; | ||
|
||
pub use frame_system::{self, mocking::*}; | ||
|
@@ -342,6 +345,9 @@ pub mod runtime { | |
/// Consider using the new version of this [`frame_construct_runtime`]. | ||
pub use frame_support::construct_runtime; | ||
|
||
/// Related to runtime construction. | ||
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. This comment is not relevant for me |
||
pub use frame_support::{BoundedSlice, BoundedVec}; | ||
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. If you added them just to use the runtime prelude in the |
||
|
||
/// Macro to amalgamate the runtime into `struct Runtime`. | ||
/// | ||
/// This is the newer version of [`construct_runtime`]. | ||
|
@@ -494,6 +500,7 @@ pub mod runtime { | |
pub mod testing_prelude { | ||
pub use sp_core::storage::Storage; | ||
pub use sp_runtime::BuildStorage; | ||
pub use sp_runtime::testing::{TestSignature, UintAuthorityId}; | ||
} | ||
} | ||
|
||
|
@@ -513,6 +520,13 @@ pub mod arithmetic { | |
pub use sp_arithmetic::{traits::*, *}; | ||
} | ||
|
||
/// Consensus types | ||
pub mod consensus { | ||
pub use sp_consensus_aura::{ed25519::AuthorityId, AuthorityIndex, ConsensusLog, Slot, AURA_ENGINE_ID}; | ||
pub use sp_runtime::{DigestItem, Digest}; | ||
pub use sp_runtime::ConsensusEngineId; | ||
} | ||
|
||
/// All derive macros used in frame. | ||
/// | ||
/// This is already part of the [`prelude`]. | ||
|
@@ -527,9 +541,14 @@ pub mod derive { | |
pub use sp_runtime::RuntimeDebug; | ||
} | ||
|
||
pub mod hashing { | ||
pub use sp_core::{hashing::*, H160, H256, H512, U256, U512}; | ||
pub mod cryptography { | ||
pub use sp_core::{ | ||
crypto::{VrfPublic, VrfSecret, Wraps}, | ||
hashing::*, | ||
Pair, H160, H256, H512, U256, U512, | ||
}; | ||
pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; | ||
pub use sp_application_crypto::{RuntimeAppPublic, BoundToRuntimeAppPublic}; | ||
} | ||
|
||
/// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, | ||
|
@@ -575,6 +594,8 @@ pub mod deps { | |
pub use sp_storage; | ||
#[cfg(feature = "runtime")] | ||
pub use sp_version; | ||
#[cfg(feature = "runtime")] | ||
pub use sp_application_crypto; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
pub use frame_benchmarking; | ||
|
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.
Use the main prelude
frame::prelude::*
instead of the runtime one