diff --git a/Cargo.lock b/Cargo.lock index f2379d4ee6de..46e0e5a5535b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13761,18 +13761,12 @@ dependencies = [ name = "pallet-im-online" version = "27.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-authorship 28.0.0", "pallet-session 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-application-crypto 30.0.0", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", "sp-staking 26.0.0", ] @@ -19378,6 +19372,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api 26.0.0", + "sp-application-crypto 30.0.0", "sp-arithmetic 23.0.0", "sp-block-builder 26.0.0", "sp-consensus-aura 0.32.0", diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 2d0daf82997d..10585e1977ef 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -48,6 +48,7 @@ sp-genesis-builder = { optional = true, workspace = true } sp-inherents = { optional = true, workspace = true } sp-storage = { optional = true, workspace = true } sp-keyring = { optional = true, workspace = true } +sp-application-crypto = { optional = true, workspace = true } frame-executive = { optional = true, workspace = true } frame-system-rpc-runtime-api = { optional = true, workspace = true } @@ -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", @@ -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", diff --git a/substrate/frame/im-online/Cargo.toml b/substrate/frame/im-online/Cargo.toml index 6c32c8ae898e..3b6c573a2b11 100644 --- a/substrate/frame/im-online/Cargo.toml +++ b/substrate/frame/im-online/Cargo.toml @@ -19,14 +19,8 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive"], workspace = true } log = { workspace = true } scale-info = { features = ["derive", "serde"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } pallet-authorship = { workspace = true } -sp-application-crypto = { features = ["serde"], workspace = true } -sp-core = { features = ["serde"], workspace = true } -sp-io = { workspace = true } -sp-runtime = { features = ["serde"], workspace = true } sp-staking = { features = ["serde"], workspace = true } [dev-dependencies] @@ -36,30 +30,19 @@ pallet-session = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-authorship/std", "pallet-session/std", "scale-info/std", - "sp-application-crypto/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", "sp-staking/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame/runtime-benchmarks", "sp-staking/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-authorship/try-runtime", "pallet-session/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/im-online/src/benchmarking.rs b/substrate/frame/im-online/src/benchmarking.rs index 439720bcab38..7afe5b9606b6 100644 --- a/substrate/frame/im-online/src/benchmarking.rs +++ b/substrate/frame/im-online/src/benchmarking.rs @@ -19,15 +19,8 @@ #![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::v2::*; -use frame_support::{traits::UnfilteredDispatchable, WeakBoundedVec}; -use frame_system::RawOrigin; -use sp_runtime::{ - traits::{ValidateUnsigned, Zero}, - transaction_validity::TransactionSource, -}; - use crate::*; +use frame::benchmarking::prelude::*; const MAX_KEYS: u32 = 1000; diff --git a/substrate/frame/im-online/src/lib.rs b/substrate/frame/im-online/src/lib.rs index 74d3bc6484dd..9d14b6f99c0a 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -43,12 +43,11 @@ //! //! ``` //! use pallet_im_online::{self as im_online}; +//! use frame::prelude::*; //! -//! #[frame_support::pallet] +//! #[frame::pallet] //! pub mod pallet { //! use super::*; -//! use frame_support::pallet_prelude::*; -//! use frame_system::pallet_prelude::*; //! //! #[pallet::pallet] //! pub struct Pallet(_); @@ -86,26 +85,12 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{ - pallet_prelude::*, - traits::{ - EstimateNextSessionRotation, Get, OneSessionHandler, ValidatorSet, - ValidatorSetWithIdentification, - }, - BoundedSlice, WeakBoundedVec, -}; -use frame_system::{ - offchain::{CreateInherent, SubmitTransaction}, - pallet_prelude::*, +use frame::{ + prelude::*, + traits::{ValidatorSet, ValidatorSetWithIdentification}, }; pub use pallet::*; use scale_info::TypeInfo; -use sp_application_crypto::RuntimeAppPublic; -use sp_runtime::{ - offchain::storage::{MutateStorageError, StorageRetrievalError, StorageValueRef}, - traits::{AtLeast32BitUnsigned, Convert, Saturating, TrailingZeroInput}, - PerThing, Perbill, Permill, RuntimeDebug, SaturatedConversion, -}; use sp_staking::{ offence::{Kind, Offence, ReportOffence}, SessionIndex, @@ -114,11 +99,11 @@ pub use weights::WeightInfo; pub mod sr25519 { mod app_sr25519 { - use sp_application_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; + use frame::deps::sp_application_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; app_crypto!(sr25519, IM_ONLINE); } - sp_application_crypto::with_pair! { + frame::deps::sp_application_crypto::with_pair! { /// An i'm online keypair using sr25519 as its crypto. pub type AuthorityPair = app_sr25519::Pair; } @@ -132,11 +117,11 @@ pub mod sr25519 { pub mod ed25519 { mod app_ed25519 { - use sp_application_crypto::{app_crypto, ed25519, key_types::IM_ONLINE}; + use frame::deps::sp_application_crypto::{app_crypto, ed25519, key_types::IM_ONLINE}; app_crypto!(ed25519, IM_ONLINE); } - sp_application_crypto::with_pair! { + frame::deps::sp_application_crypto::with_pair! { /// An i'm online keypair using ed25519 as its crypto. pub type AuthorityPair = app_ed25519::Pair; } @@ -249,7 +234,7 @@ pub type IdentificationTuple = ( type OffchainResult = Result>>; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; @@ -366,7 +351,7 @@ pub mod pallet { >; #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig { pub keys: Vec, } @@ -421,7 +406,7 @@ pub mod pallet { impl Hooks> for Pallet { fn offchain_worker(now: BlockNumberFor) { // Only send messages if we are a potential validator. - if sp_io::offchain::is_validator() { + if offchain::is_validator() { for res in Self::send_heartbeats(now).into_iter().flatten() { if let Err(e) = res { log::debug!( @@ -564,7 +549,7 @@ impl Pallet { let residual = Permill::from_rational(1u32, session_length.saturated_into()); let threshold: Permill = progress.saturating_pow(6).saturating_add(residual); - let seed = sp_io::offchain::random_seed(); + let seed = offchain::random_seed(); let random = ::decode(&mut TrailingZeroInput::new(seed.as_ref())) .expect("input is padded with zeroes; qed"); let random = Permill::from_parts(random % Permill::ACCURACY); @@ -735,7 +720,7 @@ impl Pallet { } } -impl sp_runtime::BoundToRuntimeAppPublic for Pallet { +impl BoundToRuntimeAppPublic for Pallet { type Public = T::AuthorityId; } @@ -805,7 +790,7 @@ impl OneSessionHandler for Pallet { let validator_set_count = keys.len() as u32; let offence = UnresponsivenessOffence { session_index, validator_set_count, offenders }; if let Err(e) = T::ReportUnresponsiveness::report_offence(vec![], offence) { - sp_runtime::print(e); + frame::deps::sp_runtime::print(e); } } } diff --git a/substrate/frame/im-online/src/migration.rs b/substrate/frame/im-online/src/migration.rs index 6d3a5cda6973..37afab33f082 100644 --- a/substrate/frame/im-online/src/migration.rs +++ b/substrate/frame/im-online/src/migration.rs @@ -19,12 +19,7 @@ use super::*; use alloc::vec::Vec; -use frame_support::{storage_alias, traits::OnRuntimeUpgrade}; - -#[cfg(feature = "try-runtime")] -use frame_support::ensure; -#[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; +use frame::{testing_prelude::*, traits::WrapperOpaque}; /// The log target. const TARGET: &str = "runtime::im-online::migration::v1"; @@ -32,7 +27,6 @@ const TARGET: &str = "runtime::im-online::migration::v1"; /// The original data layout of the im-online pallet (`ReceivedHeartbeats` storage item). mod v0 { use super::*; - use frame_support::traits::WrapperOpaque; #[derive(Encode, Decode, Default)] pub(super) struct BoundedOpaqueNetworkState { @@ -61,7 +55,7 @@ pub mod v1 { impl OnRuntimeUpgrade for Migration { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { + fn pre_upgrade() -> Result, frame::try_runtime::TryRuntimeError> { let count = v0::ReceivedHeartbeats::::iter().count(); log::info!(target: TARGET, "Migrating {} received heartbeats", count); @@ -128,7 +122,7 @@ pub fn clear_offchain_storage(validator_set_size: u32) { key.extend(idx.encode()); key }; - sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); + StorageValueRef::persistent(&key).clear(); }); } @@ -136,7 +130,6 @@ pub fn clear_offchain_storage(validator_set_size: u32) { mod test { use super::*; use crate::mock::{new_test_ext, Runtime as T}; - use frame_support::traits::WrapperOpaque; #[test] fn migration_works() { diff --git a/substrate/frame/im-online/src/mock.rs b/substrate/frame/im-online/src/mock.rs index a5d9a6e20e61..15a287f2a01a 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -19,13 +19,8 @@ #![cfg(test)] -use frame_support::{ - derive_impl, parameter_types, - traits::{ConstU32, ConstU64}, - weights::Weight, -}; +use frame::testing_prelude::*; use pallet_session::historical as pallet_session_historical; -use sp_runtime::{testing::UintAuthorityId, traits::ConvertInto, BuildStorage, Permill}; use sp_staking::{ offence::{OffenceError, ReportOffence}, SessionIndex, @@ -36,7 +31,7 @@ use crate::Config; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Runtime { System: frame_system, Session: pallet_session, @@ -73,7 +68,7 @@ impl pallet_session::historical::SessionManager for TestSessionManager } /// An extrinsic type used for tests. -pub type Extrinsic = sp_runtime::testing::TestXt; +pub type Extrinsic = TestXt; type IdentificationTuple = (u64, u64); type Offence = crate::UnresponsivenessOffence; @@ -94,9 +89,9 @@ impl ReportOffence for OffenceHandler { } } -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestExternalities { let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let mut result: sp_io::TestExternalities = t.into(); + let mut result: TestExternalities = t.into(); // Set the default keys, otherwise session will discard the validator. result.execute_with(|| { for i in 1..=6 { @@ -150,7 +145,7 @@ parameter_types! { pub struct TestNextSessionRotation; -impl frame_support::traits::EstimateNextSessionRotation for TestNextSessionRotation { +impl EstimateNextSessionRotation for TestNextSessionRotation { fn average_session_length() -> u64 { // take the mock result if any and return it let mock = MockAverageSessionLength::mutate(|p| p.take()); diff --git a/substrate/frame/im-online/src/tests.rs b/substrate/frame/im-online/src/tests.rs index b9a2772da689..6c3fac4a5eb5 100644 --- a/substrate/frame/im-online/src/tests.rs +++ b/substrate/frame/im-online/src/tests.rs @@ -21,12 +21,7 @@ use super::*; use crate::mock::*; -use frame_support::{assert_noop, dispatch}; -use sp_core::offchain::{ - testing::{TestOffchainExt, TestTransactionPoolExt}, - OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, -}; -use sp_runtime::testing::UintAuthorityId; +use frame::testing_prelude::*; #[test] fn test_unresponsiveness_slash_fraction() { @@ -111,7 +106,7 @@ fn heartbeat( authority_index: u32, id: UintAuthorityId, validators: Vec, -) -> dispatch::DispatchResult { +) -> DispatchResult { let heartbeat = Heartbeat { block_number, session_index, diff --git a/substrate/frame/im-online/src/weights.rs b/substrate/frame/im-online/src/weights.rs index 6fde451caf9e..4e60e65c49fd 100644 --- a/substrate/frame/im-online/src/weights.rs +++ b/substrate/frame/im-online/src/weights.rs @@ -46,7 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_im_online`. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 8031ddf96e6a..1c7292fb6bf2 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -202,8 +202,10 @@ 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::dispatch::{DispatchResult, GetDispatchInfo, PostDispatchInfo}; + pub use frame_support::traits::{ + Contains, IsSubType, OnRuntimeUpgrade, UnfilteredDispatchable, + }; /// Pallet prelude of `frame-system`. #[doc(no_inline)] @@ -214,15 +216,25 @@ pub mod prelude { pub use super::derive::*; /// All hashing related things - pub use super::hashing::*; + pub use super::cryptography::*; + + /// All arithmetic types used for safe math. + pub use super::arithmetic::*; + + pub use super::offchain::*; + + pub use super::session::*; /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, - Saturating, StaticLookup, TrailingZeroInput, + BlockNumberProvider, Bounded, Convert, ConvertInto, DispatchInfoOf, Dispatchable, + 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::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; @@ -493,7 +505,10 @@ pub mod runtime { #[cfg(feature = "std")] pub mod testing_prelude { pub use sp_core::storage::Storage; - pub use sp_runtime::BuildStorage; + pub use sp_runtime::{ + testing::{TestSignature, TestXt, UintAuthorityId}, + BuildStorage, + }; } } @@ -527,11 +542,32 @@ 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_application_crypto::{BoundToRuntimeAppPublic, RuntimeAppPublic}; + pub use sp_core::{ + crypto::{VrfPublic, VrfSecret, Wraps}, + hashing::*, + Pair, H160, H256, H512, U256, U512, + }; pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } +pub mod offchain { + pub use frame_system::offchain::{CreateInherent, SubmitTransaction}; + pub use sp_core::offchain::{ + testing::{TestOffchainExt, TestTransactionPoolExt}, + OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, + }; + pub use sp_io::offchain; + pub use sp_runtime::offchain::storage::{ + MutateStorageError, StorageRetrievalError, StorageValueRef, + }; +} + +pub mod session { + pub use frame_support::traits::{EstimateNextSessionRotation, OneSessionHandler}; +} + /// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, /// this module can be used. /// @@ -558,6 +594,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;