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 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions prdoc/pr_6619.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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-authority-discovery to umbrella crate

doc:
- audience: Runtime Dev
description: |
Imports frame umbrella crate systems into pallet-authority-discovery.

crates:
- name: pallet-authority-discovery
bump: minor
18 changes: 3 additions & 15 deletions substrate/frame/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,24 @@ codec = { features = [
"derive",
], workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-session = { features = [
"historical",
], 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",
]
39 changes: 20 additions & 19 deletions substrate/frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
extern crate alloc;

use alloc::vec::Vec;
use frame_support::{
use frame::{
deps::frame_support::WeakBoundedVec,
prelude::*,
traits::{Get, OneSessionHandler},
WeakBoundedVec,
};
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 +59,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 +113,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 +171,22 @@ mod tests {
use super::*;
use crate as pallet_authority_discovery;
use alloc::vec;
use frame_support::{derive_impl, parameter_types, traits::ConstU32};
use frame::{
arithmetic::Perbill,
deps::sp_runtime::KeyTypeId,
runtime::{
prelude::{construct_runtime, derive_impl, parameter_types},
testing_prelude::BuildStorage,
},
testing_prelude::TestExternalities,
traits::{ConstU32, ConvertInto, IdentityLookup, OpaqueKeys},
};
use sp_application_crypto::Pair;
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>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand All @@ -203,7 +205,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 +236,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 +311,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