From 70b0b4b3cddbdb1fd74cf2e3f8dbe025ba57879e Mon Sep 17 00:00:00 2001 From: runcomet Date: Tue, 19 Nov 2024 07:06:00 -0800 Subject: [PATCH 01/13] frame::prelude --- Cargo.lock | 4 +--- substrate/frame/alliance/Cargo.toml | 20 ++++---------------- substrate/frame/alliance/src/lib.rs | 8 ++++++-- substrate/frame/alliance/src/migration.rs | 3 ++- substrate/frame/alliance/src/types.rs | 5 +++-- substrate/frame/alliance/src/weights.rs | 3 ++- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 119a8b3afed2..d1b8c5e22a3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10601,14 +10601,12 @@ name = "pallet-alliance" version = "27.0.0" dependencies = [ "array-bytes", - "frame-benchmarking", - "frame-support", - "frame-system", "log", "pallet-balances", "pallet-collective", "pallet-identity", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", "sp-core 28.0.0", "sp-crypto-hashing 0.1.0", diff --git a/substrate/frame/alliance/Cargo.toml b/substrate/frame/alliance/Cargo.toml index 451b86b35dde..732a97bb8d54 100644 --- a/substrate/frame/alliance/Cargo.toml +++ b/substrate/frame/alliance/Cargo.toml @@ -27,9 +27,7 @@ sp-crypto-hashing = { optional = true, workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } pallet-identity = { workspace = true } pallet-collective = { optional = true, workspace = true } @@ -44,35 +42,25 @@ pallet-collective = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-balances/std", "pallet-collective?/std", "pallet-identity/std", "scale-info/std", - "sp-core/std", "sp-crypto-hashing?/std", - "sp-io/std", - "sp-runtime/std", ] runtime-benchmarks = [ "array-bytes", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-identity/runtime-benchmarks", "sp-crypto-hashing", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", "pallet-collective?/try-runtime", "pallet-identity/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index be65f49e6e4e..9c956adb3a60 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -98,6 +98,8 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; +use frame::{prelude::*, traits::{Dispatchable, Saturating, StaticLookup, Zero}, deps::sp_runtime::DispatchError, derive::DefaultNoBound}; +/* use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_runtime::{ @@ -114,6 +116,7 @@ use frame_support::{ }, weights::Weight, }; +*/ use scale_info::TypeInfo; pub use pallet::*; @@ -215,7 +218,8 @@ type UnscrupulousItemOf = type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -#[frame_support::pallet] +// #[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; @@ -399,7 +403,7 @@ pub mod pallet { } #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(frame::derive::DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub fellows: Vec, pub allies: Vec, diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index b4ecc1819447..7f66310f5871 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,7 +16,8 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -use frame_support::{pallet_prelude::*, storage::migration, traits::OnRuntimeUpgrade}; +//use frame_support::{pallet_prelude::*, storage::migration, traits::OnRuntimeUpgrade}; +use frame::{prelude::*, traits::OnRuntimeUpgrade, deps::frame_support::storage::migration}; use log; /// The in-code storage version. diff --git a/substrate/frame/alliance/src/types.rs b/substrate/frame/alliance/src/types.rs index 75b949c19b32..103234c4cf20 100644 --- a/substrate/frame/alliance/src/types.rs +++ b/substrate/frame/alliance/src/types.rs @@ -17,9 +17,10 @@ use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{traits::ConstU32, BoundedVec}; +// use frame_support::{traits::ConstU32, BoundedVec}; use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; +// use sp_runtime::RuntimeDebug; +use frame::{runtime::prelude::ConstU32, derive::RuntimeDebug, deps::frame_support::BoundedVec}; /// A Multihash instance that only supports the basic functionality and no hashing. #[derive( diff --git a/substrate/frame/alliance/src/weights.rs b/substrate/frame/alliance/src/weights.rs index 0184ac91107c..87034066ad34 100644 --- a/substrate/frame/alliance/src/weights.rs +++ b/substrate/frame/alliance/src/weights.rs @@ -46,7 +46,8 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_alliance`. From 8c9c6cf4d098ca9ec703c533fa716ecc50adb2cd Mon Sep 17 00:00:00 2001 From: runcomet Date: Tue, 19 Nov 2024 14:15:02 -0800 Subject: [PATCH 02/13] comp imports --- Cargo.lock | 3 ++- substrate/frame/alliance/Cargo.toml | 1 + substrate/frame/alliance/src/benchmarking.rs | 8 +++++--- substrate/frame/alliance/src/lib.rs | 9 ++++++++- substrate/frame/alliance/src/migration.rs | 4 +++- substrate/frame/alliance/src/mock.rs | 19 +++++++++++++++++-- substrate/frame/alliance/src/tests.rs | 4 +++- substrate/frame/alliance/src/types.rs | 2 +- 8 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad9d0f898f5b..b504ab366491 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11612,7 +11612,8 @@ dependencies = [ "pallet-collective 28.0.0", "pallet-identity 29.0.0", "parity-scale-codec", - "polkadot-sdk-frame", + "polkadot-sdk-frame 0.1.0", + "pretty_assertions", "scale-info", "sp-core 28.0.0", "sp-crypto-hashing 0.1.0", diff --git a/substrate/frame/alliance/Cargo.toml b/substrate/frame/alliance/Cargo.toml index 732a97bb8d54..9c58ca9fccbb 100644 --- a/substrate/frame/alliance/Cargo.toml +++ b/substrate/frame/alliance/Cargo.toml @@ -37,6 +37,7 @@ array-bytes = { workspace = true, default-features = true } sp-crypto-hashing = { workspace = true } pallet-balances = { workspace = true, default-features = true } pallet-collective = { workspace = true, default-features = true } +pretty_assertions = { workspace = true } [features] default = ["std"] diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index 09e2045555b6..c7a8312f648e 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -20,13 +20,15 @@ #![cfg(feature = "runtime-benchmarks")] use core::{cmp, mem::size_of}; +/* use sp_runtime::traits::{Bounded, Hash, StaticLookup}; use frame_benchmarking::{account, v2::*, BenchmarkError}; use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}; use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin}; - +*/ use super::{Call as AllianceCall, Pallet as Alliance, *}; +use frame::{benchmarking::prelude::*, deps::{frame_system::{Pallet as System, RawOrigin as SystemOrigin}, frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}}}; const SEED: u32 = 0; @@ -193,7 +195,7 @@ mod benchmarks { // Whitelist voter account from further DB operations. let voter_key = frame_system::Account::::hashed_key_for(&voter); - frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into()); + add_to_whitelist(voter_key.into()); #[extrinsic_call] _(SystemOrigin::Signed(voter), last_hash, index, approve); @@ -264,7 +266,7 @@ mod benchmarks { // Whitelist voter account from further DB operations. let voter_key = frame_system::Account::::hashed_key_for(&voter); - frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into()); + add_to_whitelist(voter_key.into()); #[extrinsic_call] close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage); diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 9c956adb3a60..4b57cd29cbeb 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -98,7 +98,14 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame::{prelude::*, traits::{Dispatchable, Saturating, StaticLookup, Zero}, deps::sp_runtime::DispatchError, derive::DefaultNoBound}; +use frame::{ + deps::sp_runtime::DispatchError, + prelude::*, + traits::{ + ChangeMembers, Currency, Dispatchable, InitializeMembers, OnUnbalanced, ReservableCurrency, + Saturating, StaticLookup, Zero, + }, +}; /* use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index 7f66310f5871..c0113ba88fa7 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -17,7 +17,7 @@ use crate::{Config, Pallet, Weight, LOG_TARGET}; //use frame_support::{pallet_prelude::*, storage::migration, traits::OnRuntimeUpgrade}; -use frame::{prelude::*, traits::OnRuntimeUpgrade, deps::frame_support::storage::migration}; +use frame::{deps::frame_support::storage::migration, prelude::*, traits::OnRuntimeUpgrade}; use log; /// The in-code storage version. @@ -163,6 +163,8 @@ pub(crate) mod v1_to_v2 { #[cfg(test)] mod test { use super::*; + use frame::testing_prelude::assert_ok; + use pretty_assertions::assert_eq; use crate::{mock::*, MemberRole, Members}; #[test] diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 625cabf3457f..5013e105dfbd 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -16,7 +16,7 @@ // limitations under the License. //! Test utilities - +/* pub use sp_core::H256; use sp_runtime::traits::Hash; pub use sp_runtime::{ @@ -29,6 +29,21 @@ pub use frame_support::{ traits::EitherOfDiverse, BoundedVec, }; use frame_system::{EnsureRoot, EnsureSignedBy}; +*/ +use frame::{ + deps::{ + frame_support::{traits::EitherOfDiverse, BoundedVec}, + sp_runtime::traits::{IdentifyAccount, Lazy, Verify}, + }, + runtime::{ + prelude::{ + construct_runtime, derive_impl, ord_parameter_types, parameter_types, EnsureRoot, + EnsureSignedBy, + }, + testing_prelude::BuildStorage, + }, + testing_prelude::{assert_noop, assert_ok}, +}; use pallet_identity::{ legacy::{IdentityField, IdentityInfo}, Data, IdentityOf, Judgement, SuperOf, @@ -237,7 +252,7 @@ impl Config for Test { type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index 2397ebfe7db4..3d412f51fd8a 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -17,12 +17,14 @@ //! Tests for the alliance pallet. +/* use frame_support::{assert_noop, assert_ok}; use frame_system::{EventRecord, Phase}; use sp_runtime::traits::BadOrigin; - +*/ use super::*; use crate::{self as alliance, mock::*}; +use frame::{testing_prelude::{assert_noop, assert_ok}, deps::{sp_runtime::DispatchError::BadOrigin, frame_system::{EventRecord, Phase}}}; type AllianceMotionEvent = pallet_collective::Event; diff --git a/substrate/frame/alliance/src/types.rs b/substrate/frame/alliance/src/types.rs index 103234c4cf20..04e4e78b6130 100644 --- a/substrate/frame/alliance/src/types.rs +++ b/substrate/frame/alliance/src/types.rs @@ -20,7 +20,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; // use frame_support::{traits::ConstU32, BoundedVec}; use scale_info::TypeInfo; // use sp_runtime::RuntimeDebug; -use frame::{runtime::prelude::ConstU32, derive::RuntimeDebug, deps::frame_support::BoundedVec}; +use frame::{deps::frame_support::BoundedVec, derive::RuntimeDebug, runtime::prelude::ConstU32}; /// A Multihash instance that only supports the basic functionality and no hashing. #[derive( From f100e33450a8b836ffe6ec97dff26c0946184bb4 Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 22 Nov 2024 19:24:40 -0800 Subject: [PATCH 03/13] cargo fmt --- substrate/frame/alliance/src/benchmarking.rs | 17 ++++++++--------- substrate/frame/alliance/src/lib.rs | 18 ------------------ substrate/frame/alliance/src/migration.rs | 3 +-- substrate/frame/alliance/src/mock.rs | 14 -------------- substrate/frame/alliance/src/tests.rs | 13 +++++++------ substrate/frame/alliance/src/types.rs | 4 +--- substrate/frame/alliance/src/weights.rs | 1 - 7 files changed, 17 insertions(+), 53 deletions(-) diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index c7a8312f648e..94cee5a7c811 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -19,16 +19,15 @@ #![cfg(feature = "runtime-benchmarks")] -use core::{cmp, mem::size_of}; -/* -use sp_runtime::traits::{Bounded, Hash, StaticLookup}; - -use frame_benchmarking::{account, v2::*, BenchmarkError}; -use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}; -use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin}; -*/ use super::{Call as AllianceCall, Pallet as Alliance, *}; -use frame::{benchmarking::prelude::*, deps::{frame_system::{Pallet as System, RawOrigin as SystemOrigin}, frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}}}; +use core::{cmp, mem::size_of}; +use frame::{ + benchmarking::prelude::*, + deps::{ + frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}, + frame_system::{Pallet as System, RawOrigin as SystemOrigin}, + }, +}; const SEED: u32 = 0; diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 4b57cd29cbeb..9c280bcd97b9 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -106,24 +106,6 @@ use frame::{ Saturating, StaticLookup, Zero, }, }; -/* -use frame_support::pallet_prelude::*; -use frame_system::pallet_prelude::*; -use sp_runtime::{ - traits::{Dispatchable, Saturating, StaticLookup, Zero}, - DispatchError, RuntimeDebug, -}; - -use frame_support::{ - dispatch::{DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo, PostDispatchInfo}, - ensure, - traits::{ - ChangeMembers, Currency, Get, InitializeMembers, IsSubType, OnUnbalanced, - ReservableCurrency, - }, - weights::Weight, -}; -*/ use scale_info::TypeInfo; pub use pallet::*; diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index c0113ba88fa7..c75574be7143 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,7 +16,6 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -//use frame_support::{pallet_prelude::*, storage::migration, traits::OnRuntimeUpgrade}; use frame::{deps::frame_support::storage::migration, prelude::*, traits::OnRuntimeUpgrade}; use log; @@ -163,9 +162,9 @@ pub(crate) mod v1_to_v2 { #[cfg(test)] mod test { use super::*; + use crate::{mock::*, MemberRole, Members}; use frame::testing_prelude::assert_ok; use pretty_assertions::assert_eq; - use crate::{mock::*, MemberRole, Members}; #[test] fn migration_v1_to_v2_works() { diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 5013e105dfbd..685a87247e79 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -16,20 +16,6 @@ // limitations under the License. //! Test utilities -/* -pub use sp_core::H256; -use sp_runtime::traits::Hash; -pub use sp_runtime::{ - traits::{BlakeTwo256, IdentifyAccount, Lazy, Verify}, - BuildStorage, -}; - -pub use frame_support::{ - assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types, - traits::EitherOfDiverse, BoundedVec, -}; -use frame_system::{EnsureRoot, EnsureSignedBy}; -*/ use frame::{ deps::{ frame_support::{traits::EitherOfDiverse, BoundedVec}, diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index 3d412f51fd8a..6827476a5838 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -17,14 +17,15 @@ //! Tests for the alliance pallet. -/* -use frame_support::{assert_noop, assert_ok}; -use frame_system::{EventRecord, Phase}; -use sp_runtime::traits::BadOrigin; -*/ use super::*; use crate::{self as alliance, mock::*}; -use frame::{testing_prelude::{assert_noop, assert_ok}, deps::{sp_runtime::DispatchError::BadOrigin, frame_system::{EventRecord, Phase}}}; +use frame::{ + deps::{ + frame_system::{EventRecord, Phase}, + sp_runtime::DispatchError::BadOrigin, + }, + testing_prelude::{assert_noop, assert_ok}, +}; type AllianceMotionEvent = pallet_collective::Event; diff --git a/substrate/frame/alliance/src/types.rs b/substrate/frame/alliance/src/types.rs index 04e4e78b6130..15c1917cae18 100644 --- a/substrate/frame/alliance/src/types.rs +++ b/substrate/frame/alliance/src/types.rs @@ -17,10 +17,8 @@ use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; -// use frame_support::{traits::ConstU32, BoundedVec}; -use scale_info::TypeInfo; -// use sp_runtime::RuntimeDebug; use frame::{deps::frame_support::BoundedVec, derive::RuntimeDebug, runtime::prelude::ConstU32}; +use scale_info::TypeInfo; /// A Multihash instance that only supports the basic functionality and no hashing. #[derive( diff --git a/substrate/frame/alliance/src/weights.rs b/substrate/frame/alliance/src/weights.rs index cd4b4cd9fee3..b06a0913a5b9 100644 --- a/substrate/frame/alliance/src/weights.rs +++ b/substrate/frame/alliance/src/weights.rs @@ -46,7 +46,6 @@ #![allow(unused_imports)] #![allow(missing_docs)] -// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use frame::weights_prelude::*; use core::marker::PhantomData; From a152e9ec11ac4ac43ae2027a4022133a610217a9 Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 29 Nov 2024 07:15:15 -0800 Subject: [PATCH 04/13] add BoundedVec to frame::runtime::prelude --- prdoc/pr_6541.prdoc | 15 +++++++++++++++ substrate/frame/alliance/src/lib.rs | 1 - substrate/frame/alliance/src/migration.rs | 5 ++++- substrate/frame/alliance/src/mock.rs | 9 +++------ substrate/frame/alliance/src/types.rs | 5 ++++- substrate/frame/src/lib.rs | 3 +++ 6 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 prdoc/pr_6541.prdoc diff --git a/prdoc/pr_6541.prdoc b/prdoc/pr_6541.prdoc new file mode 100644 index 000000000000..cae7a88f93c0 --- /dev/null +++ b/prdoc/pr_6541.prdoc @@ -0,0 +1,15 @@ +# 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-alliance to umbrella crate. + +doc: + - audience: Runtime Dev + description: | + Imports frame umbrella crate systems into pallet-alliance. + +crates: + - name: pallet-alliance + bump: minor + - name: polkadot-sdk-frame + bump: minor diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 9c280bcd97b9..8458b5096e95 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -207,7 +207,6 @@ type UnscrupulousItemOf = type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -// #[frame_support::pallet] #[frame::pallet] pub mod pallet { use super::*; diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index c75574be7143..012792dcbd28 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,7 +16,10 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -use frame::{deps::frame_support::storage::migration, prelude::*, traits::OnRuntimeUpgrade}; +use frame::{ + deps::frame_support::{pallet_prelude::*, storage::migration}, + traits::OnRuntimeUpgrade, +}; use log; /// The in-code storage version. diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 685a87247e79..f44dfec2c0de 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -17,18 +17,15 @@ //! Test utilities use frame::{ - deps::{ - frame_support::{traits::EitherOfDiverse, BoundedVec}, - sp_runtime::traits::{IdentifyAccount, Lazy, Verify}, - }, runtime::{ prelude::{ - construct_runtime, derive_impl, ord_parameter_types, parameter_types, EnsureRoot, - EnsureSignedBy, + construct_runtime, derive_impl, ord_parameter_types, parameter_types, BoundedVec, + EnsureRoot, EnsureSignedBy, }, testing_prelude::BuildStorage, }, testing_prelude::{assert_noop, assert_ok}, + traits::{EitherOfDiverse, IdentifyAccount, Lazy, Verify}, }; use pallet_identity::{ legacy::{IdentityField, IdentityInfo}, diff --git a/substrate/frame/alliance/src/types.rs b/substrate/frame/alliance/src/types.rs index 15c1917cae18..b1d048088385 100644 --- a/substrate/frame/alliance/src/types.rs +++ b/substrate/frame/alliance/src/types.rs @@ -17,7 +17,10 @@ use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; -use frame::{deps::frame_support::BoundedVec, derive::RuntimeDebug, runtime::prelude::ConstU32}; +use frame::{ + derive::RuntimeDebug, + runtime::prelude::{BoundedVec, ConstU32}, +}; use scale_info::TypeInfo; /// A Multihash instance that only supports the basic functionality and no hashing. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 03d815e349df..1a46818d556e 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -342,6 +342,9 @@ pub mod runtime { /// Consider using the new version of this [`frame_construct_runtime`]. pub use frame_support::construct_runtime; + /// Related to runtime contruction. + pub use frame_support::BoundedVec; + /// Macro to amalgamate the runtime into `struct Runtime`. /// /// This is the newer version of [`construct_runtime`]. From b90040baa752b7dc9d72b7ff65f7e12697833f24 Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 29 Nov 2024 10:51:48 -0800 Subject: [PATCH 05/13] remove primitives --- Cargo.lock | 3 --- prdoc/pr_6541.prdoc | 4 +++- substrate/frame/alliance/Cargo.toml | 7 ------- substrate/frame/alliance/src/mock.rs | 11 ++++++----- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 544a8e3544a3..ee73e19ca435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11646,10 +11646,7 @@ dependencies = [ "polkadot-sdk-frame 0.1.0", "pretty_assertions", "scale-info", - "sp-core 28.0.0", "sp-crypto-hashing 0.1.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/prdoc/pr_6541.prdoc b/prdoc/pr_6541.prdoc index cae7a88f93c0..d443f0d6e75b 100644 --- a/prdoc/pr_6541.prdoc +++ b/prdoc/pr_6541.prdoc @@ -6,7 +6,9 @@ title: migrate pallet-alliance to umbrella crate. doc: - audience: Runtime Dev description: | - Imports frame umbrella crate systems into pallet-alliance. + Imports frame umbrella crate systems into pallet-alliance and + exports BoundedVec as part of runtime::prelude of the + polkadot-sdk-frame crate. crates: - name: pallet-alliance diff --git a/substrate/frame/alliance/Cargo.toml b/substrate/frame/alliance/Cargo.toml index 9c58ca9fccbb..0963927f54da 100644 --- a/substrate/frame/alliance/Cargo.toml +++ b/substrate/frame/alliance/Cargo.toml @@ -18,17 +18,10 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] array-bytes = { optional = true, workspace = true, default-features = true } log = { workspace = true } - codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } - -sp-core = { workspace = true } sp-crypto-hashing = { optional = true, workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } - frame = { workspace = true, features = ["experimental", "runtime"] } - pallet-identity = { workspace = true } pallet-collective = { optional = true, workspace = true } diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index f44dfec2c0de..534b92a18c0c 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -17,6 +17,7 @@ //! Test utilities use frame::{ + arithmetic::Perbill, runtime::{ prelude::{ construct_runtime, derive_impl, ord_parameter_types, parameter_types, BoundedVec, @@ -24,7 +25,7 @@ use frame::{ }, testing_prelude::BuildStorage, }, - testing_prelude::{assert_noop, assert_ok}, + testing_prelude::{assert_noop, assert_ok, TestExternalities}, traits::{EitherOfDiverse, IdentifyAccount, Lazy, Verify}, }; use pallet_identity::{ @@ -61,7 +62,7 @@ parameter_types! { pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS; pub const MaxProposals: u32 = 100; pub const MaxMembers: u32 = 100; - pub MaxProposalWeight: Weight = sp_runtime::Perbill::from_percent(50) * BlockWeights::get().max_block; + pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block; } type AllianceCollective = pallet_collective::Instance1; impl pallet_collective::Config for Test { @@ -266,7 +267,7 @@ pub(super) fn test_identity_info_deposit() -> : byte_deposit * test_identity_info().encoded_size() as u64 + basic_deposit } -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { @@ -293,7 +294,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .assimilate_storage(&mut t) .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); + let mut ext = TestExternalities::new(t); ext.execute_with(|| { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1)); @@ -370,7 +371,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } #[cfg(feature = "runtime-benchmarks")] -pub fn new_bench_ext() -> sp_io::TestExternalities { +pub fn new_bench_ext() -> TestExternalities { RuntimeGenesisConfig::default().build_storage().unwrap().into() } From 0e9e72c6f20c906ba7f00f0fb4def401ed7e336d Mon Sep 17 00:00:00 2001 From: runcomet Date: Sun, 1 Dec 2024 02:52:58 -0800 Subject: [PATCH 06/13] frame traits instead of frame_support deps bench --- substrate/frame/alliance/src/benchmarking.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index 94cee5a7c811..f43f331ea3de 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -23,10 +23,8 @@ use super::{Call as AllianceCall, Pallet as Alliance, *}; use core::{cmp, mem::size_of}; use frame::{ benchmarking::prelude::*, - deps::{ - frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}, - frame_system::{Pallet as System, RawOrigin as SystemOrigin}, - }, + deps::frame_system::{Pallet as System, RawOrigin as SystemOrigin}, + traits::{EnsureOrigin, Get, UnfilteredDispatchable}, }; const SEED: u32 = 0; From 835ee3ce00650619c19b541b64628a90994524ef Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 6 Dec 2024 14:57:50 -0800 Subject: [PATCH 07/13] improve imports as stated in the guidelines --- prdoc/pr_6541.prdoc | 10 ++++++---- substrate/frame/alliance/src/benchmarking.rs | 10 ++++------ substrate/frame/alliance/src/lib.rs | 6 +----- substrate/frame/alliance/src/migration.rs | 6 ++---- substrate/frame/alliance/src/mock.rs | 9 +-------- substrate/frame/alliance/src/tests.rs | 8 +------- substrate/frame/alliance/src/types.rs | 5 +---- substrate/frame/src/lib.rs | 8 ++++++++ 8 files changed, 24 insertions(+), 38 deletions(-) diff --git a/prdoc/pr_6541.prdoc b/prdoc/pr_6541.prdoc index d443f0d6e75b..ad26a78dff11 100644 --- a/prdoc/pr_6541.prdoc +++ b/prdoc/pr_6541.prdoc @@ -6,12 +6,14 @@ title: migrate pallet-alliance to umbrella crate. doc: - audience: Runtime Dev description: | - Imports frame umbrella crate systems into pallet-alliance and - exports BoundedVec as part of runtime::prelude of the - polkadot-sdk-frame crate. + This PR: + - Imports frame umbrella crate systems into pallet-alliance. + - Includes BoundedVec as part of `runtime::prelude`. + - Includes the event module in `testing_prelude`, this are systems used in asseccing events + in mock runtimes across different crates in the PolkadotSDK. crates: - name: pallet-alliance bump: minor - name: polkadot-sdk-frame - bump: minor + bump: minor \ No newline at end of file diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index f43f331ea3de..9e2eb0a72731 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -21,18 +21,16 @@ use super::{Call as AllianceCall, Pallet as Alliance, *}; use core::{cmp, mem::size_of}; -use frame::{ - benchmarking::prelude::*, - deps::frame_system::{Pallet as System, RawOrigin as SystemOrigin}, - traits::{EnsureOrigin, Get, UnfilteredDispatchable}, -}; +use frame::{benchmarking::prelude::*, traits::UnfilteredDispatchable}; +use frame_system::Pallet as System; +use RawOrigin as SystemOrigin; const SEED: u32 = 0; const MAX_BYTES: u32 = 1_024; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { - frame_system::Pallet::::assert_last_event(generic_event.into()); + System::::assert_last_event(generic_event.into()); } fn cid(input: impl AsRef<[u8]>) -> Cid { diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 8458b5096e95..96c7d019b01c 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -99,12 +99,8 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use frame::{ - deps::sp_runtime::DispatchError, prelude::*, - traits::{ - ChangeMembers, Currency, Dispatchable, InitializeMembers, OnUnbalanced, ReservableCurrency, - Saturating, StaticLookup, Zero, - }, + traits::{ChangeMembers, Currency, InitializeMembers, OnUnbalanced, ReservableCurrency}, }; use scale_info::TypeInfo; diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index 012792dcbd28..d5532446be7f 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,11 +16,9 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -use frame::{ - deps::frame_support::{pallet_prelude::*, storage::migration}, - traits::OnRuntimeUpgrade, -}; +use frame::{runtime::prelude::*, traits::OnRuntimeUpgrade}; use log; +use storage::migration; /// The in-code storage version. pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 534b92a18c0c..c83b2027d910 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -18,14 +18,7 @@ //! Test utilities use frame::{ arithmetic::Perbill, - runtime::{ - prelude::{ - construct_runtime, derive_impl, ord_parameter_types, parameter_types, BoundedVec, - EnsureRoot, EnsureSignedBy, - }, - testing_prelude::BuildStorage, - }, - testing_prelude::{assert_noop, assert_ok, TestExternalities}, + testing_prelude::*, traits::{EitherOfDiverse, IdentifyAccount, Lazy, Verify}, }; use pallet_identity::{ diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index 6827476a5838..deee651e0d79 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -19,13 +19,7 @@ use super::*; use crate::{self as alliance, mock::*}; -use frame::{ - deps::{ - frame_system::{EventRecord, Phase}, - sp_runtime::DispatchError::BadOrigin, - }, - testing_prelude::{assert_noop, assert_ok}, -}; +use frame::{deps::sp_runtime::DispatchError::BadOrigin, testing_prelude::*}; type AllianceMotionEvent = pallet_collective::Event; diff --git a/substrate/frame/alliance/src/types.rs b/substrate/frame/alliance/src/types.rs index b1d048088385..917537082b8d 100644 --- a/substrate/frame/alliance/src/types.rs +++ b/substrate/frame/alliance/src/types.rs @@ -17,10 +17,7 @@ use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; -use frame::{ - derive::RuntimeDebug, - runtime::prelude::{BoundedVec, ConstU32}, -}; +use frame::runtime::prelude::*; use scale_info::TypeInfo; /// A Multihash instance that only supports the basic functionality and no hashing. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 1a46818d556e..d592df50e4b8 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -301,6 +301,9 @@ pub mod weights_prelude { pub mod testing_prelude { pub use crate::{prelude::*, runtime::prelude::*}; + /// Testing includes event cheking. + pub use crate::event::*; + /// Testing includes building a runtime, so we bring in all preludes related to runtimes as /// well. pub use super::runtime::testing_prelude::*; @@ -516,6 +519,11 @@ pub mod arithmetic { pub use sp_arithmetic::{traits::*, *}; } +/// Event checking system for mock runtimes. +pub mod event { + pub use frame_system::{EventRecord, Phase}; +} + /// All derive macros used in frame. /// /// This is already part of the [`prelude`]. From 968ea7788adf51258dbdbb88cbd807a99db1d97d Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 6 Dec 2024 15:42:09 -0800 Subject: [PATCH 08/13] DefaultBound --- substrate/frame/alliance/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 96c7d019b01c..a3b09b5480ea 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -387,7 +387,7 @@ pub mod pallet { } #[pallet::genesis_config] - #[derive(frame::derive::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig, I: 'static = ()> { pub fellows: Vec, pub allies: Vec, From 19a5d0226553adb0988a3156dcd6887eb096fc5d Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 6 Dec 2024 16:05:34 -0800 Subject: [PATCH 09/13] remove pretty_assertions --- Cargo.lock | 1 - substrate/frame/alliance/Cargo.toml | 1 - substrate/frame/alliance/src/migration.rs | 4 +--- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 633c9c0e72cd..664cc84af359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11644,7 +11644,6 @@ dependencies = [ "pallet-identity 29.0.0", "parity-scale-codec", "polkadot-sdk-frame 0.1.0", - "pretty_assertions", "scale-info", "sp-crypto-hashing 0.1.0", ] diff --git a/substrate/frame/alliance/Cargo.toml b/substrate/frame/alliance/Cargo.toml index 0963927f54da..9ceaed464a0f 100644 --- a/substrate/frame/alliance/Cargo.toml +++ b/substrate/frame/alliance/Cargo.toml @@ -30,7 +30,6 @@ array-bytes = { workspace = true, default-features = true } sp-crypto-hashing = { workspace = true } pallet-balances = { workspace = true, default-features = true } pallet-collective = { workspace = true, default-features = true } -pretty_assertions = { workspace = true } [features] default = ["std"] diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index d5532446be7f..31860560f3d0 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,7 +16,7 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -use frame::{runtime::prelude::*, traits::OnRuntimeUpgrade}; +use frame::{testing_prelude::*, traits::OnRuntimeUpgrade}; use log; use storage::migration; @@ -164,8 +164,6 @@ pub(crate) mod v1_to_v2 { mod test { use super::*; use crate::{mock::*, MemberRole, Members}; - use frame::testing_prelude::assert_ok; - use pretty_assertions::assert_eq; #[test] fn migration_v1_to_v2_works() { From 6f676a0e3fe4e21d0e624784fb4d7baf27bbddb0 Mon Sep 17 00:00:00 2001 From: runcomet Date: Wed, 11 Dec 2024 13:41:17 -0800 Subject: [PATCH 10/13] remove prdoc --- prdoc/pr_6541.prdoc | 19 ------------------- substrate/frame/alliance/src/benchmarking.rs | 4 +--- substrate/frame/src/lib.rs | 13 +++++++------ 3 files changed, 8 insertions(+), 28 deletions(-) delete mode 100644 prdoc/pr_6541.prdoc diff --git a/prdoc/pr_6541.prdoc b/prdoc/pr_6541.prdoc deleted file mode 100644 index ad26a78dff11..000000000000 --- a/prdoc/pr_6541.prdoc +++ /dev/null @@ -1,19 +0,0 @@ -# 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-alliance to umbrella crate. - -doc: - - audience: Runtime Dev - description: | - This PR: - - Imports frame umbrella crate systems into pallet-alliance. - - Includes BoundedVec as part of `runtime::prelude`. - - Includes the event module in `testing_prelude`, this are systems used in asseccing events - in mock runtimes across different crates in the PolkadotSDK. - -crates: - - name: pallet-alliance - bump: minor - - name: polkadot-sdk-frame - bump: minor \ No newline at end of file diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index 9e2eb0a72731..33365237d6f1 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -21,9 +21,7 @@ use super::{Call as AllianceCall, Pallet as Alliance, *}; use core::{cmp, mem::size_of}; -use frame::{benchmarking::prelude::*, traits::UnfilteredDispatchable}; -use frame_system::Pallet as System; -use RawOrigin as SystemOrigin; +use frame::benchmarking::prelude::{*, RawOrigin as SystemOrigin, frame_system::Pallet as System}; const SEED: u32 = 0; diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index d592df50e4b8..703e05dbc3eb 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -194,6 +194,9 @@ pub mod prelude { #[doc(inline)] pub use frame_system; + /// Bounded types. + pub use frame_support::{BoundedVec, BoundedSlice}; + /// Pallet prelude of `frame-support`. /// /// Note: this needs to revised once `frame-support` evolves. @@ -266,6 +269,7 @@ pub mod benchmarking { pub use super::shared::*; pub use crate::prelude::*; pub use frame_benchmarking::v2::*; + pub use frame_support::traits::UnfilteredDispatchable; } } @@ -301,9 +305,6 @@ pub mod weights_prelude { pub mod testing_prelude { pub use crate::{prelude::*, runtime::prelude::*}; - /// Testing includes event cheking. - pub use crate::event::*; - /// Testing includes building a runtime, so we bring in all preludes related to runtimes as /// well. pub use super::runtime::testing_prelude::*; @@ -337,6 +338,9 @@ pub mod runtime { pub mod prelude { pub use crate::prelude::*; + /// Testing includes event cheking. + pub use crate::event::*; + /// All of the types related to the FRAME runtime executive. pub use frame_executive::*; @@ -345,9 +349,6 @@ pub mod runtime { /// Consider using the new version of this [`frame_construct_runtime`]. pub use frame_support::construct_runtime; - /// Related to runtime contruction. - pub use frame_support::BoundedVec; - /// Macro to amalgamate the runtime into `struct Runtime`. /// /// This is the newer version of [`construct_runtime`]. From 9b2b7fe2fbe5497f20b2da25f0170a5a4b605762 Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 27 Dec 2024 06:47:21 -0800 Subject: [PATCH 11/13] sp-crypto-hashing to frame crate --- Cargo.lock | 2 +- substrate/frame/Cargo.toml | 3 +++ substrate/frame/alliance/Cargo.toml | 4 ---- substrate/frame/alliance/src/benchmarking.rs | 4 ++-- substrate/frame/alliance/src/mock.rs | 2 +- substrate/frame/src/lib.rs | 13 ++++++++----- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c349495bb7d..b6d922e3008e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11645,7 +11645,6 @@ dependencies = [ "parity-scale-codec", "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-crypto-hashing 0.1.0", ] [[package]] @@ -19187,6 +19186,7 @@ dependencies = [ "sp-consensus-aura 0.32.0", "sp-consensus-grandpa 13.0.0", "sp-core 28.0.0", + "sp-crypto-hashing 0.1.0", "sp-genesis-builder 0.8.0", "sp-inherents 26.0.0", "sp-io 30.0.0", diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 2d0daf82997d..795aafa5c622 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -44,6 +44,7 @@ sp-offchain = { optional = true, workspace = true } sp-session = { optional = true, workspace = true } sp-consensus-aura = { optional = true, workspace = true } sp-consensus-grandpa = { optional = true, workspace = true } +sp-crypto-hashing = { optional = true, workspace = true } sp-genesis-builder = { optional = true, workspace = true } sp-inherents = { optional = true, workspace = true } sp-storage = { optional = true, workspace = true } @@ -101,6 +102,7 @@ std = [ "sp-consensus-aura?/std", "sp-consensus-grandpa?/std", "sp-core/std", + "sp-crypto-hashing?/std", "sp-genesis-builder?/std", "sp-inherents?/std", "sp-io/std", @@ -118,6 +120,7 @@ runtime-benchmarks = [ "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "sp-crypto-hashing", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/substrate/frame/alliance/Cargo.toml b/substrate/frame/alliance/Cargo.toml index 9ceaed464a0f..0620fd1fcb9c 100644 --- a/substrate/frame/alliance/Cargo.toml +++ b/substrate/frame/alliance/Cargo.toml @@ -20,14 +20,12 @@ array-bytes = { optional = true, workspace = true, default-features = true } log = { workspace = true } codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -sp-crypto-hashing = { optional = true, workspace = true } frame = { workspace = true, features = ["experimental", "runtime"] } pallet-identity = { workspace = true } pallet-collective = { optional = true, workspace = true } [dev-dependencies] array-bytes = { workspace = true, default-features = true } -sp-crypto-hashing = { workspace = true } pallet-balances = { workspace = true, default-features = true } pallet-collective = { workspace = true, default-features = true } @@ -41,7 +39,6 @@ std = [ "pallet-collective?/std", "pallet-identity/std", "scale-info/std", - "sp-crypto-hashing?/std", ] runtime-benchmarks = [ "array-bytes", @@ -49,7 +46,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-identity/runtime-benchmarks", - "sp-crypto-hashing", ] try-runtime = [ "frame/try-runtime", diff --git a/substrate/frame/alliance/src/benchmarking.rs b/substrate/frame/alliance/src/benchmarking.rs index 33365237d6f1..faa072e09079 100644 --- a/substrate/frame/alliance/src/benchmarking.rs +++ b/substrate/frame/alliance/src/benchmarking.rs @@ -21,7 +21,7 @@ use super::{Call as AllianceCall, Pallet as Alliance, *}; use core::{cmp, mem::size_of}; -use frame::benchmarking::prelude::{*, RawOrigin as SystemOrigin, frame_system::Pallet as System}; +use frame::benchmarking::prelude::{frame_system::Pallet as System, RawOrigin as SystemOrigin, *}; const SEED: u32 = 0; @@ -32,7 +32,7 @@ fn assert_last_event, I: 'static>(generic_event: >:: } fn cid(input: impl AsRef<[u8]>) -> Cid { - let result = sp_crypto_hashing::sha2_256(input.as_ref()); + let result = frame::deps::sp_crypto_hashing::sha2_256(input.as_ref()); Cid::new_v0(result) } diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index c83b2027d910..cd283cfc151c 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -369,7 +369,7 @@ pub fn new_bench_ext() -> TestExternalities { } pub fn test_cid() -> Cid { - let result = sp_crypto_hashing::sha2_256(b"hello world"); + let result = frame::deps::sp_crypto_hashing::sha2_256(b"hello world"); Cid::new_v0(result) } diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 703e05dbc3eb..ae2f7f68e71f 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -194,9 +194,6 @@ pub mod prelude { #[doc(inline)] pub use frame_system; - /// Bounded types. - pub use frame_support::{BoundedVec, BoundedSlice}; - /// Pallet prelude of `frame-support`. /// /// Note: this needs to revised once `frame-support` evolves. @@ -206,7 +203,9 @@ pub mod prelude { /// Dispatch types from `frame-support`, other fundamental traits #[doc(no_inline)] pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; - pub use frame_support::traits::{Contains, IsSubType, OnRuntimeUpgrade}; + pub use frame_support::traits::{ + Contains, IsSubType, OnRuntimeUpgrade, UnfilteredDispatchable, + }; /// Pallet prelude of `frame-system`. #[doc(no_inline)] @@ -226,6 +225,9 @@ pub mod prelude { Saturating, StaticLookup, TrailingZeroInput, }; + /// Bounded storage related types. + pub use sp_runtime::{BoundedSlice, BoundedVec}; + /// Other error/result types for runtime #[doc(no_inline)] pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; @@ -269,7 +271,6 @@ pub mod benchmarking { pub use super::shared::*; pub use crate::prelude::*; pub use frame_benchmarking::v2::*; - pub use frame_support::traits::UnfilteredDispatchable; } } @@ -576,6 +577,8 @@ pub mod deps { #[cfg(feature = "runtime")] pub use sp_consensus_grandpa; #[cfg(feature = "runtime")] + pub use sp_crypto_hashing; + #[cfg(feature = "runtime")] pub use sp_genesis_builder; #[cfg(feature = "runtime")] pub use sp_inherents; From ff6f12d2e69509b958cccf64e0df05aeabe1526b Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 27 Dec 2024 07:40:03 -0800 Subject: [PATCH 12/13] just Lazy --- substrate/frame/alliance/src/lib.rs | 5 +-- substrate/frame/alliance/src/migration.rs | 2 +- substrate/frame/alliance/src/mock.rs | 6 +--- substrate/frame/alliance/src/tests.rs | 2 +- substrate/frame/src/lib.rs | 41 +++++++++++++++++++---- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index a3b09b5480ea..daf5e19a15d1 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -98,10 +98,7 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame::{ - prelude::*, - traits::{ChangeMembers, Currency, InitializeMembers, OnUnbalanced, ReservableCurrency}, -}; +use frame::prelude::*; use scale_info::TypeInfo; pub use pallet::*; diff --git a/substrate/frame/alliance/src/migration.rs b/substrate/frame/alliance/src/migration.rs index 31860560f3d0..db4182f06a89 100644 --- a/substrate/frame/alliance/src/migration.rs +++ b/substrate/frame/alliance/src/migration.rs @@ -16,7 +16,7 @@ // limitations under the License. use crate::{Config, Pallet, Weight, LOG_TARGET}; -use frame::{testing_prelude::*, traits::OnRuntimeUpgrade}; +use frame::testing_prelude::*; use log; use storage::migration; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index cd283cfc151c..000c4f65d0ac 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -16,11 +16,7 @@ // limitations under the License. //! Test utilities -use frame::{ - arithmetic::Perbill, - testing_prelude::*, - traits::{EitherOfDiverse, IdentifyAccount, Lazy, Verify}, -}; +use frame::{testing_prelude::*, traits::Lazy}; use pallet_identity::{ legacy::{IdentityField, IdentityInfo}, Data, IdentityOf, Judgement, SuperOf, diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index deee651e0d79..1b7e62714669 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -19,7 +19,7 @@ use super::*; use crate::{self as alliance, mock::*}; -use frame::{deps::sp_runtime::DispatchError::BadOrigin, testing_prelude::*}; +use frame::testing_prelude::*; type AllianceMotionEvent = pallet_collective::Event; diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index ae2f7f68e71f..985df4576250 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -215,8 +215,17 @@ pub mod prelude { #[doc(no_inline)] pub use super::derive::*; - /// All hashing related things - pub use super::hashing::*; + /// All crypto related things. + pub use super::cryptography::*; + + /// All arithmetic types used for safe math. + pub use super::arithmetic::*; + + /// All currency related things. + pub use super::currency::*; + + /// All account related things. + pub use super::account::*; /// Runtime traits #[doc(no_inline)] @@ -230,7 +239,10 @@ pub mod prelude { /// Other error/result types for runtime #[doc(no_inline)] - pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; + pub use sp_runtime::{ + DispatchError::{self, BadOrigin}, + DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + }; } #[cfg(any(feature = "try-runtime", test))] @@ -540,9 +552,26 @@ pub mod derive { pub use sp_runtime::RuntimeDebug; } -pub mod hashing { - pub use sp_core::{hashing::*, H160, H256, H512, U256, U512}; - pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; +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, Verify}; +} + +pub mod currency { + /// Currency related traits. + pub use frame_support::traits::{ + Currency, ExistenceRequirement::KeepAlive, OnUnbalanced, ReservableCurrency, + }; +} + +pub mod account { + /// Traits related to Accounts on substrate based chains. + pub use frame_support::traits::{ChangeMembers, EitherOfDiverse, InitializeMembers}; + pub use sp_runtime::traits::IdentifyAccount; } /// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, From d291d0b5f249d30e0ded998a8c832a1bb332fbac Mon Sep 17 00:00:00 2001 From: runcomet Date: Fri, 27 Dec 2024 11:13:55 -0800 Subject: [PATCH 13/13] sp_crypto_hashing in runtime feature --- substrate/frame/Cargo.toml | 1 + substrate/frame/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 795aafa5c622..e487627db704 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -76,6 +76,7 @@ runtime = [ "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", + "sp-crypto-hashing", "sp-genesis-builder", "sp-inherents", "sp-keyring", diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 985df4576250..7218abd061e8 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -561,15 +561,15 @@ pub mod cryptography { pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256, Verify}; } +/// Currency related traits. pub mod currency { - /// Currency related traits. pub use frame_support::traits::{ Currency, ExistenceRequirement::KeepAlive, OnUnbalanced, ReservableCurrency, }; } +/// Traits related to Accounts on substrate based chains. pub mod account { - /// Traits related to Accounts on substrate based chains. pub use frame_support::traits::{ChangeMembers, EitherOfDiverse, InitializeMembers}; pub use sp_runtime::traits::IdentifyAccount; }