From b7f53c689dbb44c99d5c228c4d2fae32fd5bb6e4 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Mon, 2 Dec 2024 15:06:50 -0800 Subject: [PATCH] move im-online to umbrella crate --- Cargo.lock | 7 +--- substrate/frame/im-online/Cargo.toml | 23 ++--------- substrate/frame/im-online/src/benchmarking.rs | 9 +--- substrate/frame/im-online/src/lib.rs | 41 ++++++++++--------- substrate/frame/im-online/src/migration.rs | 13 +++--- substrate/frame/im-online/src/mock.rs | 20 +++++---- substrate/frame/im-online/src/tests.rs | 16 +++++--- substrate/frame/im-online/src/weights.rs | 2 +- 8 files changed, 58 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc2ebb2a057d..7b9ad960b978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13581,18 +13581,13 @@ 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", ] diff --git a/substrate/frame/im-online/Cargo.toml b/substrate/frame/im-online/Cargo.toml index 6c32c8ae898e..7b02f39190a0 100644 --- a/substrate/frame/im-online/Cargo.toml +++ b/substrate/frame/im-online/Cargo.toml @@ -19,14 +19,9 @@ 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 +31,20 @@ 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..43a5355f62be 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::*, traits::UnfilteredDispatchable}; 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..e0174f8764de 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,28 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{ - pallet_prelude::*, +use frame::{ + arithmetic::{PerThing, Perbill, Permill}, + deps::{ + frame_support::{BoundedSlice, WeakBoundedVec}, + frame_system::offchain::{CreateInherent, SubmitTransaction}, + sp_io, + sp_runtime::{ + offchain::storage::{MutateStorageError, StorageRetrievalError, StorageValueRef}, + print, BoundToRuntimeAppPublic, + }, + }, + derive::RuntimeDebug, + prelude::*, traits::{ - EstimateNextSessionRotation, Get, OneSessionHandler, ValidatorSet, + AtLeast32BitUnsigned, Convert, EstimateNextSessionRotation, OneSessionHandler, + SaturatedConversion, Saturating, TrailingZeroInput, ValidatorSet, ValidatorSetWithIdentification, }, - BoundedSlice, WeakBoundedVec, -}; -use frame_system::{ - offchain::{CreateInherent, SubmitTransaction}, - pallet_prelude::*, }; 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, @@ -249,7 +250,7 @@ pub type IdentificationTuple = ( type OffchainResult = Result>>; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; @@ -366,7 +367,7 @@ pub mod pallet { >; #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(frame::derive::DefaultNoBound)] pub struct GenesisConfig { pub keys: Vec, } @@ -735,7 +736,7 @@ impl Pallet { } } -impl sp_runtime::BoundToRuntimeAppPublic for Pallet { +impl BoundToRuntimeAppPublic for Pallet { type Public = T::AuthorityId; } @@ -805,7 +806,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); + print(e); } } } diff --git a/substrate/frame/im-online/src/migration.rs b/substrate/frame/im-online/src/migration.rs index 6d3a5cda6973..b6b670f61ee6 100644 --- a/substrate/frame/im-online/src/migration.rs +++ b/substrate/frame/im-online/src/migration.rs @@ -19,12 +19,15 @@ use super::*; use alloc::vec::Vec; -use frame_support::{storage_alias, traits::OnRuntimeUpgrade}; +use frame::{ + testing_prelude::storage_alias, + traits::{OnRuntimeUpgrade, WrapperOpaque}, +}; #[cfg(feature = "try-runtime")] -use frame_support::ensure; +use frame::deps::frame_support::ensure; #[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; +use frame::deps::sp_runtime::TryRuntimeError; /// The log target. const TARGET: &str = "runtime::im-online::migration::v1"; @@ -32,7 +35,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 { @@ -128,7 +130,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 +138,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..a7eb1df8c3f5 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -19,13 +19,19 @@ #![cfg(test)] -use frame_support::{ - derive_impl, parameter_types, - traits::{ConstU32, ConstU64}, - weights::Weight, +use frame::{ + arithmetic::Permill, + deps::{ + frame_system, sp_io, + sp_runtime::{self, testing::UintAuthorityId}, + }, + runtime::{ + prelude::{construct_runtime, derive_impl, parameter_types, weights::Weight}, + testing_prelude::BuildStorage, + }, + traits::{ConstU32, ConstU64, ConvertInto, EstimateNextSessionRotation}, }; 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 +42,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, @@ -150,7 +156,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..76e6184f03c1 100644 --- a/substrate/frame/im-online/src/tests.rs +++ b/substrate/frame/im-online/src/tests.rs @@ -21,13 +21,17 @@ use super::*; use crate::mock::*; -use frame_support::{assert_noop, dispatch}; -use sp_core::offchain::{ - testing::{TestOffchainExt, TestTransactionPoolExt}, - OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, +use frame::{ + deps::{ + frame_support::dispatch, + sp_core::offchain::{ + testing::{TestOffchainExt, TestTransactionPoolExt}, + OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, + }, + sp_runtime::testing::UintAuthorityId, + }, + testing_prelude::*, }; -use sp_runtime::testing::UintAuthorityId; - #[test] fn test_unresponsiveness_slash_fraction() { let dummy_offence = 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`.