Skip to content
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-authority-discovery to umbrella crate #6619

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
8 changes: 2 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ frame-system = { workspace = true }

# primitive types used for developing FRAME runtimes.
sp-api = { optional = true, workspace = true }
sp-application-crypto = { optional = true, workspace = true }
sp-block-builder = { optional = true, workspace = true }
sp-consensus-aura = { optional = true, workspace = true }
sp-consensus-grandpa = { optional = true, workspace = true }
Expand Down Expand Up @@ -72,6 +73,7 @@ runtime = [
"frame-executive",
"frame-system-rpc-runtime-api",
"sp-api",
"sp-application-crypto",
"sp-block-builder",
"sp-consensus-aura",
"sp-consensus-grandpa",
Expand All @@ -96,6 +98,7 @@ std = [
"log/std",
"scale-info/std",
"sp-api?/std",
"sp-application-crypto/std",
"sp-arithmetic/std",
"sp-block-builder?/std",
"sp-consensus-aura?/std",
Expand Down
22 changes: 4 additions & 18 deletions substrate/frame/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,23 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { features = [
"derive",
], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the experimental feature flag from now on as in #7177

Suggested change
frame = { workspace = true, features = ["experimental", "runtime"] }
frame = { workspace = true, features = ["runtime"] }

pallet-session = { features = [
"historical",
], workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-application-crypto = { workspace = true }
sp-authority-discovery = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"pallet-session/std",
"scale-info/std",
"sp-application-crypto/std",
"sp-authority-discovery/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-session/try-runtime",
"sp-runtime/try-runtime",
]
33 changes: 10 additions & 23 deletions substrate/frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@
extern crate alloc;

use alloc::vec::Vec;
use frame_support::{
traits::{Get, OneSessionHandler},
WeakBoundedVec,
};
use frame::prelude::*;
use sp_authority_discovery::AuthorityId;

pub use pallet::*;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand All @@ -59,7 +55,7 @@ pub mod pallet {
pub(super) type NextKeys<T: Config> =
StorageValue<_, WeakBoundedVec<AuthorityId, T::MaxAuthorities>, ValueQuery>;

#[derive(frame_support::DefaultNoBound)]
#[derive(frame::derive::DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub keys: Vec<AuthorityId>,
Expand Down Expand Up @@ -113,7 +109,7 @@ impl<T: Config> Pallet<T> {
}
}

impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Pallet<T> {
impl<T: Config> frame::deps::sp_runtime::BoundToRuntimeAppPublic for Pallet<T> {
type Public = AuthorityId;
}

Expand Down Expand Up @@ -171,20 +167,12 @@ mod tests {
use super::*;
use crate as pallet_authority_discovery;
use alloc::vec;
use frame_support::{derive_impl, parameter_types, traits::ConstU32};
use sp_application_crypto::Pair;
use frame::{testing_prelude::*, traits::OpaqueKeys};
use sp_authority_discovery::AuthorityPair;
use sp_core::crypto::key_types;
use sp_io::TestExternalities;
use sp_runtime::{
testing::UintAuthorityId,
traits::{ConvertInto, IdentityLookup, OpaqueKeys},
BuildStorage, KeyTypeId, Perbill,
};

type Block = frame_system::mocking::MockBlock<Test>;
type Block = MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand All @@ -203,7 +191,7 @@ mod tests {

impl pallet_session::Config for Test {
type SessionManager = ();
type Keys = UintAuthorityId;
type Keys = frame::deps::sp_runtime::testing::UintAuthorityId;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionHandler = TestSessionHandler;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -234,7 +222,8 @@ mod tests {

pub struct TestSessionHandler;
impl pallet_session::SessionHandler<AuthorityId> for TestSessionHandler {
const KEY_TYPE_IDS: &'static [KeyTypeId] = &[key_types::DUMMY];
const KEY_TYPE_IDS: &'static [KeyTypeId] =
&[frame::deps::sp_core::crypto::key_types::DUMMY];

fn on_new_session<Ks: OpaqueKeys>(
_changed: bool,
Expand Down Expand Up @@ -308,8 +297,6 @@ mod tests {
let mut externalities = TestExternalities::new(t);

externalities.execute_with(|| {
use frame_support::traits::OneSessionHandler;

AuthorityDiscovery::on_genesis_session(
first_authorities.iter().map(|id| (id, id.clone())),
);
Expand Down
32 changes: 28 additions & 4 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,24 @@ pub mod prelude {
pub use super::derive::*;

/// All hashing related things
pub use super::hashing::*;
pub use super::cryptography::*;

/// All arithmetic types and traits used for safe math.
pub use super::arithmetic::*;

/// All account management related things.
pub use super::account::*;

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
BlockNumberProvider, Bounded, Convert, ConvertInto, DispatchInfoOf, Dispatchable, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
};

/// Bounded storage related types.
pub use sp_runtime::{BoundedSlice, BoundedVec, WeakBoundedVec};

/// Other error/result types for runtime
#[doc(no_inline)]
pub use sp_runtime::{
Expand Down Expand Up @@ -526,6 +533,17 @@ pub mod traits {
pub use sp_runtime::traits::*;
}

/// All account management related traits.
///
/// This is already part of the [`prelude`].
pub mod account {
pub use frame_support::traits::{
AsEnsureOriginWithArg, ChangeMembers, EitherOfDiverse, FindAuthor, InitializeMembers,
};
pub use sp_application_crypto::{KeyTypeId, Pair};
pub use sp_runtime::traits::{IdentifyAccount, IdentityLookup};
}

/// The arithmetic types used for safe math.
///
/// This is already part of the [`prelude`].
Expand All @@ -547,8 +565,12 @@ 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove Pair because it appears in several pallets with different meanings

};
pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256};
}

Expand Down Expand Up @@ -578,6 +600,8 @@ pub mod deps {
#[cfg(feature = "runtime")]
pub use sp_api;
#[cfg(feature = "runtime")]
pub use sp_application_crypto;
#[cfg(feature = "runtime")]
pub use sp_block_builder;
#[cfg(feature = "runtime")]
pub use sp_consensus_aura;
Expand Down
Loading