From b7f53c689dbb44c99d5c228c4d2fae32fd5bb6e4 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Mon, 2 Dec 2024 15:06:50 -0800 Subject: [PATCH 1/6] 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`. From d671c0c4ef8bed814fae8532633a18c711b6af8a Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Thu, 12 Dec 2024 20:12:49 -0800 Subject: [PATCH 2/6] add offchain mod --- Cargo.lock | 2 +- substrate/frame/Cargo.toml | 3 ++ substrate/frame/im-online/Cargo.toml | 2 - substrate/frame/im-online/src/benchmarking.rs | 2 +- substrate/frame/im-online/src/lib.rs | 32 +++-------- substrate/frame/im-online/src/migration.rs | 5 +- substrate/frame/im-online/src/mock.rs | 19 ++----- substrate/frame/im-online/src/tests.rs | 15 ++---- substrate/frame/src/lib.rs | 54 ++++++++++++++++--- 9 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b9ad960b978..e819b0f21469 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13587,7 +13587,6 @@ dependencies = [ "parity-scale-codec", "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-application-crypto 30.0.0", "sp-staking 26.0.0", ] @@ -19187,6 +19186,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 7b02f39190a0..3b6c573a2b11 100644 --- a/substrate/frame/im-online/Cargo.toml +++ b/substrate/frame/im-online/Cargo.toml @@ -21,7 +21,6 @@ log = { workspace = true } scale-info = { features = ["derive", "serde"], workspace = true } frame = { workspace = true, features = ["experimental", "runtime"] } pallet-authorship = { workspace = true } -sp-application-crypto = { features = ["serde"], workspace = true } sp-staking = { features = ["serde"], workspace = true } [dev-dependencies] @@ -36,7 +35,6 @@ std = [ "pallet-authorship/std", "pallet-session/std", "scale-info/std", - "sp-application-crypto/std", "sp-staking/std", ] runtime-benchmarks = [ diff --git a/substrate/frame/im-online/src/benchmarking.rs b/substrate/frame/im-online/src/benchmarking.rs index 43a5355f62be..7afe5b9606b6 100644 --- a/substrate/frame/im-online/src/benchmarking.rs +++ b/substrate/frame/im-online/src/benchmarking.rs @@ -20,7 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use crate::*; -use frame::{benchmarking::prelude::*, traits::UnfilteredDispatchable}; +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 e0174f8764de..5b15829dd7c0 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -86,27 +86,11 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; 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::{ - AtLeast32BitUnsigned, Convert, EstimateNextSessionRotation, OneSessionHandler, - SaturatedConversion, Saturating, TrailingZeroInput, ValidatorSet, - ValidatorSetWithIdentification, - }, + traits::{ValidatorSet, ValidatorSetWithIdentification}, }; pub use pallet::*; use scale_info::TypeInfo; -use sp_application_crypto::RuntimeAppPublic; use sp_staking::{ offence::{Kind, Offence, ReportOffence}, SessionIndex, @@ -115,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; } @@ -133,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; } @@ -422,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!( @@ -565,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); @@ -806,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) { - 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 b6b670f61ee6..9df5616938d3 100644 --- a/substrate/frame/im-online/src/migration.rs +++ b/substrate/frame/im-online/src/migration.rs @@ -19,10 +19,7 @@ use super::*; use alloc::vec::Vec; -use frame::{ - testing_prelude::storage_alias, - traits::{OnRuntimeUpgrade, WrapperOpaque}, -}; +use frame::{testing_prelude::*, traits::WrapperOpaque}; #[cfg(feature = "try-runtime")] use frame::deps::frame_support::ensure; diff --git a/substrate/frame/im-online/src/mock.rs b/substrate/frame/im-online/src/mock.rs index a7eb1df8c3f5..15a287f2a01a 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -19,18 +19,7 @@ #![cfg(test)] -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 frame::testing_prelude::*; use pallet_session::historical as pallet_session_historical; use sp_staking::{ offence::{OffenceError, ReportOffence}, @@ -79,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; @@ -100,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 { diff --git a/substrate/frame/im-online/src/tests.rs b/substrate/frame/im-online/src/tests.rs index 76e6184f03c1..6c3fac4a5eb5 100644 --- a/substrate/frame/im-online/src/tests.rs +++ b/substrate/frame/im-online/src/tests.rs @@ -21,17 +21,8 @@ use super::*; use crate::mock::*; -use frame::{ - deps::{ - frame_support::dispatch, - sp_core::offchain::{ - testing::{TestOffchainExt, TestTransactionPoolExt}, - OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, - }, - sp_runtime::testing::UintAuthorityId, - }, - testing_prelude::*, -}; +use frame::testing_prelude::*; + #[test] fn test_unresponsiveness_slash_fraction() { let dummy_offence = @@ -115,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/src/lib.rs b/substrate/frame/src/lib.rs index 03d815e349df..e04ccec7ae80 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; From 5fb7b8393499e179e05fd391caa9824f586e0241 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Thu, 12 Dec 2024 20:29:45 -0800 Subject: [PATCH 3/6] nit imports --- substrate/frame/im-online/src/lib.rs | 2 +- substrate/frame/im-online/src/migration.rs | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/substrate/frame/im-online/src/lib.rs b/substrate/frame/im-online/src/lib.rs index 5b15829dd7c0..9d14b6f99c0a 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -351,7 +351,7 @@ pub mod pallet { >; #[pallet::genesis_config] - #[derive(frame::derive::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig { pub keys: Vec, } diff --git a/substrate/frame/im-online/src/migration.rs b/substrate/frame/im-online/src/migration.rs index 9df5616938d3..37afab33f082 100644 --- a/substrate/frame/im-online/src/migration.rs +++ b/substrate/frame/im-online/src/migration.rs @@ -21,11 +21,6 @@ use super::*; use alloc::vec::Vec; use frame::{testing_prelude::*, traits::WrapperOpaque}; -#[cfg(feature = "try-runtime")] -use frame::deps::frame_support::ensure; -#[cfg(feature = "try-runtime")] -use frame::deps::sp_runtime::TryRuntimeError; - /// The log target. const TARGET: &str = "runtime::im-online::migration::v1"; @@ -60,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); From ab640cda54cc406354186fd2ccd0d9cf2340cfe6 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Fri, 3 Jan 2025 04:26:29 +0100 Subject: [PATCH 4/6] nit --- Cargo.lock | 2 +- substrate/frame/Cargo.toml | 4 ++++ substrate/frame/im-online/Cargo.toml | 3 --- substrate/frame/im-online/src/benchmarking.rs | 7 ++----- substrate/frame/im-online/src/lib.rs | 10 ++-------- substrate/frame/im-online/src/migration.rs | 5 +++-- substrate/frame/im-online/src/mock.rs | 4 ---- substrate/frame/src/lib.rs | 18 +++++++++++++----- 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46e0e5a5535b..1f12b71b7b44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13767,7 +13767,6 @@ dependencies = [ "parity-scale-codec", "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-staking 26.0.0", ] [[package]] @@ -19385,6 +19384,7 @@ dependencies = [ "sp-offchain 26.0.0", "sp-runtime 31.0.1", "sp-session 27.0.0", + "sp-staking 26.0.0", "sp-storage 19.0.0", "sp-transaction-pool 26.0.0", "sp-version 29.0.0", diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 10585e1977ef..7f228c33c089 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -42,6 +42,7 @@ sp-block-builder = { optional = true, workspace = true } sp-transaction-pool = { optional = true, workspace = true } sp-offchain = { optional = true, workspace = true } sp-session = { optional = true, workspace = true } +sp-staking = { optional = true, workspace = true } sp-consensus-aura = { optional = true, workspace = true } sp-consensus-grandpa = { optional = true, workspace = true } sp-genesis-builder = { optional = true, workspace = true } @@ -82,6 +83,7 @@ runtime = [ "sp-keyring", "sp-offchain", "sp-session", + "sp-staking", "sp-storage", "sp-transaction-pool", "sp-version", @@ -110,6 +112,7 @@ std = [ "sp-keyring?/std", "sp-offchain?/std", "sp-runtime/std", + "sp-staking?/std", "sp-session?/std", "sp-storage/std", "sp-transaction-pool?/std", @@ -121,6 +124,7 @@ runtime-benchmarks = [ "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "sp-staking/runtime-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/substrate/frame/im-online/Cargo.toml b/substrate/frame/im-online/Cargo.toml index 3b6c573a2b11..5a7f0b114326 100644 --- a/substrate/frame/im-online/Cargo.toml +++ b/substrate/frame/im-online/Cargo.toml @@ -21,7 +21,6 @@ log = { workspace = true } scale-info = { features = ["derive", "serde"], workspace = true } frame = { workspace = true, features = ["experimental", "runtime"] } pallet-authorship = { workspace = true } -sp-staking = { features = ["serde"], workspace = true } [dev-dependencies] pallet-session = { workspace = true, default-features = true } @@ -35,11 +34,9 @@ std = [ "pallet-authorship/std", "pallet-session/std", "scale-info/std", - "sp-staking/std", ] runtime-benchmarks = [ "frame/runtime-benchmarks", - "sp-staking/runtime-benchmarks", ] try-runtime = [ "frame/try-runtime", diff --git a/substrate/frame/im-online/src/benchmarking.rs b/substrate/frame/im-online/src/benchmarking.rs index 7afe5b9606b6..7d9ca69c45fd 100644 --- a/substrate/frame/im-online/src/benchmarking.rs +++ b/substrate/frame/im-online/src/benchmarking.rs @@ -27,10 +27,7 @@ const MAX_KEYS: u32 = 1000; pub fn create_heartbeat( k: u32, ) -> Result< - ( - crate::Heartbeat>, - ::Signature, - ), + (crate::Heartbeat>, ::Signature), &'static str, > { let mut keys = Vec::new(); @@ -42,7 +39,7 @@ pub fn create_heartbeat( Keys::::put(bounded_keys); let input_heartbeat = Heartbeat { - block_number: frame_system::pallet_prelude::BlockNumberFor::::zero(), + block_number: BlockNumberFor::::zero(), session_index: 0, authority_index: k - 1, validators_len: keys.len() as u32, diff --git a/substrate/frame/im-online/src/lib.rs b/substrate/frame/im-online/src/lib.rs index 9d14b6f99c0a..ead91653ba18 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -85,16 +85,10 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; -use frame::{ - prelude::*, - traits::{ValidatorSet, ValidatorSetWithIdentification}, -}; +use frame::prelude::*; pub use pallet::*; use scale_info::TypeInfo; -use sp_staking::{ - offence::{Kind, Offence, ReportOffence}, - SessionIndex, -}; + pub use weights::WeightInfo; pub mod sr25519 { diff --git a/substrate/frame/im-online/src/migration.rs b/substrate/frame/im-online/src/migration.rs index 37afab33f082..167ecf969064 100644 --- a/substrate/frame/im-online/src/migration.rs +++ b/substrate/frame/im-online/src/migration.rs @@ -19,7 +19,7 @@ use super::*; use alloc::vec::Vec; -use frame::{testing_prelude::*, traits::WrapperOpaque}; +use frame::traits::WrapperOpaque; /// The log target. const TARGET: &str = "runtime::im-online::migration::v1"; @@ -36,7 +36,7 @@ mod v0 { pub external_addresses: Vec>, } - #[storage_alias] + #[frame::storage_alias] pub(super) type ReceivedHeartbeats = StorageDoubleMap< Pallet, Twox64Concat, @@ -130,6 +130,7 @@ pub fn clear_offchain_storage(validator_set_size: u32) { mod test { use super::*; use crate::mock::{new_test_ext, Runtime as T}; + use frame::testing_prelude::*; #[test] fn migration_works() { diff --git a/substrate/frame/im-online/src/mock.rs b/substrate/frame/im-online/src/mock.rs index 15a287f2a01a..6b4e64740496 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -21,10 +21,6 @@ use frame::testing_prelude::*; use pallet_session::historical as pallet_session_historical; -use sp_staking::{ - offence::{OffenceError, ReportOffence}, - SessionIndex, -}; use crate as imonline; use crate::Config; diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 1c7292fb6bf2..37e348869ef5 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -325,6 +325,11 @@ pub mod testing_prelude { pub use frame_system::{self, mocking::*}; + pub use sp_core::offchain::{ + testing::{TestOffchainExt, TestTransactionPoolExt}, + OffchainDbExt, OffchainWorkerExt, TransactionPoolExt, + }; + #[deprecated(note = "Use `frame::testing_prelude::TestExternalities` instead.")] pub use sp_io::TestExternalities; @@ -554,10 +559,6 @@ pub mod cryptography { 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, @@ -565,7 +566,14 @@ pub mod offchain { } pub mod session { - pub use frame_support::traits::{EstimateNextSessionRotation, OneSessionHandler}; + pub use frame_support::traits::{ + EstimateNextSessionRotation, OneSessionHandler, ValidatorSet, + ValidatorSetWithIdentification, + }; + pub use sp_staking::{ + offence::{Kind, Offence, OffenceError, ReportOffence}, + SessionIndex, + }; } /// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, From 103023ada589245f5aebe5b3955edbf72dde270b Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Sat, 4 Jan 2025 20:17:24 +0100 Subject: [PATCH 5/6] abc Cargo.toml frame --- substrate/frame/Cargo.toml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index d338e5b8adf8..fb41603249df 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -37,21 +37,20 @@ frame-system = { workspace = true } # primitive types used for developing FRAME runtimes. sp-api = { optional = true, workspace = true } +sp-application-crypto = { optional = true, workspace = true } sp-block-builder = { optional = true, workspace = true } -sp-transaction-pool = { optional = true, workspace = true } -sp-offchain = { optional = true, workspace = true } -sp-session = { optional = true, workspace = true } -sp-staking = { optional = true, workspace = true } -sp-storage = { optional = true, workspace = true } sp-consensus-aura = { optional = true, workspace = true } sp-consensus-grandpa = { optional = true, workspace = true } sp-genesis-builder = { optional = true, workspace = true } sp-inherents = { optional = true, workspace = true } sp-keyring = { optional = true, workspace = true } -sp-application-crypto = { optional = true, workspace = true } +sp-offchain = { optional = true, workspace = true } +sp-session = { optional = true, workspace = true } +sp-staking = { optional = true, workspace = true } +sp-storage = { optional = true, workspace = true } +sp-transaction-pool = { optional = true, workspace = true } sp-version = { optional = true, workspace = true } - frame-executive = { optional = true, workspace = true } frame-system-rpc-runtime-api = { optional = true, workspace = true } From 26b03fa0183040acc0446ab96feab454ea632717 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Sat, 4 Jan 2025 20:23:49 +0100 Subject: [PATCH 6/6] cargo +nightly fmt --- substrate/frame/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 74adf59933e3..34d3d0ef3e05 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -204,7 +204,8 @@ pub mod prelude { #[doc(no_inline)] pub use frame_support::dispatch::{DispatchResult, GetDispatchInfo, PostDispatchInfo}; pub use frame_support::traits::{ - Contains, EstimateNextSessionRotation, IsSubType, OnRuntimeUpgrade, OneSessionHandler, UnfilteredDispatchable, + Contains, EstimateNextSessionRotation, IsSubType, OnRuntimeUpgrade, OneSessionHandler, + UnfilteredDispatchable, }; /// Pallet prelude of `frame-system`.