From ac8bf3611dbeb8be500047fd60d9f807df1df45f Mon Sep 17 00:00:00 2001 From: UtkarshBhardwaj007 Date: Fri, 3 Jan 2025 15:39:17 +0000 Subject: [PATCH 1/3] migrate pallet-node-authorization to use umbrella crate --- Cargo.lock | 6 +----- substrate/frame/node-authorization/Cargo.toml | 16 +++------------- substrate/frame/node-authorization/src/lib.rs | 14 +++++++------- substrate/frame/node-authorization/src/mock.rs | 8 +++----- substrate/frame/node-authorization/src/tests.rs | 3 +-- .../frame/node-authorization/src/weights.rs | 3 +-- substrate/frame/src/lib.rs | 3 +++ 7 files changed, 19 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c55a14256c5..ee43a1e25a5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14250,14 +14250,10 @@ dependencies = [ name = "pallet-node-authorization" version = "28.0.0" dependencies = [ - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/node-authorization/Cargo.toml b/substrate/frame/node-authorization/Cargo.toml index 174736493934..fcbaa0ed2d4e 100644 --- a/substrate/frame/node-authorization/Cargo.toml +++ b/substrate/frame/node-authorization/Cargo.toml @@ -16,28 +16,18 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } -sp-core = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } [features] default = ["std"] std = [ "codec/std", - "frame-support/std", - "frame-system/std", "log/std", "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", + "frame/std", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", + "frame/try-runtime", ] diff --git a/substrate/frame/node-authorization/src/lib.rs b/substrate/frame/node-authorization/src/lib.rs index 7682b54ea0f2..3cec0d3bcb63 100644 --- a/substrate/frame/node-authorization/src/lib.rs +++ b/substrate/frame/node-authorization/src/lib.rs @@ -47,18 +47,18 @@ pub mod weights; extern crate alloc; use alloc::{collections::btree_set::BTreeSet, vec::Vec}; +use frame::{ + deps::{sp_core::OpaquePeerId as PeerId, sp_io}, + prelude::*, +}; pub use pallet::*; -use sp_core::OpaquePeerId as PeerId; -use sp_runtime::traits::StaticLookup; pub use weights::WeightInfo; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; #[pallet::pallet] #[pallet::without_storage_info] @@ -111,7 +111,7 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, PeerId, BTreeSet, ValueQuery>; #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig { pub nodes: Vec<(PeerId, T::AccountId)>, } @@ -171,7 +171,7 @@ pub mod pallet { impl Hooks> for Pallet { /// Set reserved node every block. It may not be enabled depends on the offchain /// worker settings when starting the node. - fn offchain_worker(now: frame_system::pallet_prelude::BlockNumberFor) { + fn offchain_worker(now: BlockNumberFor) { let network_state = sp_io::offchain::network_state(); match network_state { Err(_) => log::error!( diff --git a/substrate/frame/node-authorization/src/mock.rs b/substrate/frame/node-authorization/src/mock.rs index 656d2bfa39ad..c6665a479e11 100644 --- a/substrate/frame/node-authorization/src/mock.rs +++ b/substrate/frame/node-authorization/src/mock.rs @@ -20,13 +20,11 @@ use super::*; use crate as pallet_node_authorization; -use frame_support::{derive_impl, ord_parameter_types, traits::ConstU32}; -use frame_system::EnsureSignedBy; -use sp_runtime::BuildStorage; +use frame::testing_prelude::*; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -61,7 +59,7 @@ pub fn test_node(id: u8) -> PeerId { PeerId(vec![id]) } -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestState { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_node_authorization::GenesisConfig:: { nodes: vec![(test_node(10), 10), (test_node(20), 20), (test_node(30), 30)], diff --git a/substrate/frame/node-authorization/src/tests.rs b/substrate/frame/node-authorization/src/tests.rs index 4704b5adf269..cf60ab6efbd8 100644 --- a/substrate/frame/node-authorization/src/tests.rs +++ b/substrate/frame/node-authorization/src/tests.rs @@ -19,8 +19,7 @@ use super::*; use crate::mock::*; -use frame_support::{assert_noop, assert_ok}; -use sp_runtime::traits::BadOrigin; +use frame::testing_prelude::*; #[test] fn add_well_known_node_works() { diff --git a/substrate/frame/node-authorization/src/weights.rs b/substrate/frame/node-authorization/src/weights.rs index 881eeaf7a4c0..cd2935458b9d 100644 --- a/substrate/frame/node-authorization/src/weights.rs +++ b/substrate/frame/node-authorization/src/weights.rs @@ -21,8 +21,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; +use frame::weights_prelude::*; pub trait WeightInfo { fn add_well_known_node() -> Weight; diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index b3e340cbcbff..e060ecf06f41 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -328,6 +328,9 @@ pub mod testing_prelude { pub use sp_io::TestExternalities; pub use sp_io::TestExternalities as TestState; + + /// Commonly used runtime traits for testing. + pub use sp_runtime::traits::BadOrigin; } /// All of the types and tools needed to build FRAME-based runtimes. From 4dbbead35159f5264a13216c1180660243d816a0 Mon Sep 17 00:00:00 2001 From: UtkarshBhardwaj007 Date: Fri, 3 Jan 2025 16:01:58 +0000 Subject: [PATCH 2/3] run taplo format --- substrate/frame/node-authorization/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/node-authorization/Cargo.toml b/substrate/frame/node-authorization/Cargo.toml index fcbaa0ed2d4e..7e55ad178091 100644 --- a/substrate/frame/node-authorization/Cargo.toml +++ b/substrate/frame/node-authorization/Cargo.toml @@ -16,17 +16,17 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } -frame = { workspace = true, features = ["experimental", "runtime"] } [features] default = ["std"] std = [ "codec/std", + "frame/std", "log/std", "scale-info/std", - "frame/std", ] try-runtime = [ "frame/try-runtime", From 93f232e1ade54e6fd1e2c00a27e8b2b3f251f527 Mon Sep 17 00:00:00 2001 From: UtkarshBhardwaj007 Date: Fri, 3 Jan 2025 16:04:03 +0000 Subject: [PATCH 3/3] add prdoc --- prdoc/pr_7040.prdoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 prdoc/pr_7040.prdoc diff --git a/prdoc/pr_7040.prdoc b/prdoc/pr_7040.prdoc new file mode 100644 index 000000000000..f88e96a70371 --- /dev/null +++ b/prdoc/pr_7040.prdoc @@ -0,0 +1,16 @@ +# 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: '[pallet-node-authorization] Migrate to using frame umbrella crate' + +doc: + - audience: Runtime Dev + description: This PR migrates the pallet-node-authorization to use the frame umbrella crate. This + is part of the ongoing effort to migrate all pallets to use the frame umbrella crate. + The effort is tracked [here](https://github.com/paritytech/polkadot-sdk/issues/6504). + +crates: + - name: pallet-node-authorization + bump: minor + - name: polkadot-sdk-frame + bump: minor