diff --git a/Cargo.lock b/Cargo.lock index 6151ed33c5b6..7cf3c37f1868 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12240,10 +12240,7 @@ dependencies = [ name = "pallet-babe" version = "28.0.0" dependencies = [ - "frame-benchmarking 28.0.0", "frame-election-provider-support 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-authorship 28.0.0", "pallet-balances 28.0.0", @@ -12253,12 +12250,10 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-timestamp 27.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", "sp-application-crypto 30.0.0", "sp-consensus-babe 0.32.0", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", "sp-session 27.0.0", "sp-staking 26.0.0", ] diff --git a/prdoc/pr_6412.prdoc b/prdoc/pr_6412.prdoc new file mode 100644 index 000000000000..24f8770b89db --- /dev/null +++ b/prdoc/pr_6412.prdoc @@ -0,0 +1,19 @@ +# 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: Use frame umbrella crate in pallet-babe and pallet-staking-reward-curve + +doc: + - audience: Runtime Dev + description: | + Extends the FRAME umbrella crate and uses it in pallet-babe and pallet-staking-reward-curve. + Reverse compatible addition to the pallet-staking-reward-curve proc macro to allow for the use of the FRAME umbrella crate. + Migrates benchmarking from v1 to v2 for pallet-babe. + +crates: + - name: polkadot-sdk-frame + bump: patch + - name: pallet-babe + bump: minor + - name: pallet-staking-reward-curve + bump: patch diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index f0a7f4648c0a..e94f2e615d12 100644 --- a/substrate/frame/babe/Cargo.toml +++ b/substrate/frame/babe/Cargo.toml @@ -19,17 +19,12 @@ 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 } pallet-session = { workspace = true } pallet-timestamp = { workspace = true } sp-application-crypto = { features = ["serde"], workspace = true } sp-consensus-babe = { features = ["serde"], workspace = true } -sp-core = { features = ["serde"], workspace = true } -sp-io = { workspace = true } -sp-runtime = { features = ["serde"], workspace = true } sp-session = { workspace = true } sp-staking = { features = ["serde"], workspace = true } @@ -39,53 +34,38 @@ pallet-balances = { workspace = true, default-features = true } pallet-offences = { workspace = true, default-features = true } pallet-staking = { workspace = true, default-features = true } pallet-staking-reward-curve = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } [features] default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-election-provider-support/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-authorship/std", - "pallet-balances/std", - "pallet-offences/std", "pallet-session/std", - "pallet-staking/std", "pallet-timestamp/std", "scale-info/std", "sp-application-crypto/std", "sp-consensus-babe/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", "sp-session/std", "sp-staking/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", "frame-election-provider-support/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-offences/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", ] try-runtime = [ "frame-election-provider-support/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-offences/try-runtime", "pallet-session/try-runtime", "pallet-staking/try-runtime", "pallet-timestamp/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/babe/src/benchmarking.rs b/substrate/frame/babe/src/benchmarking.rs index 33e275fcb5e3..49ba4fbd514d 100644 --- a/substrate/frame/babe/src/benchmarking.rs +++ b/substrate/frame/babe/src/benchmarking.rs @@ -20,9 +20,9 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::v2::*; +use frame::benchmarking::prelude::*; -type Header = sp_runtime::generic::Header; +type Header = frame::deps::sp_runtime::generic::Header; #[benchmarks] mod benchmarks { @@ -69,7 +69,7 @@ mod benchmarks { } assert!(sp_consensus_babe::check_equivocation_proof::
(equivocation_proof2)); - } - impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(3), crate::mock::Test,); + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(3), crate::mock::Test,); + } } diff --git a/substrate/frame/babe/src/default_weights.rs b/substrate/frame/babe/src/default_weights.rs index 1f7de2b28c25..5e7228ee304b 100644 --- a/substrate/frame/babe/src/default_weights.rs +++ b/substrate/frame/babe/src/default_weights.rs @@ -18,14 +18,11 @@ //! Default weights for the Babe Pallet //! This file was not auto-generated. -use frame_support::weights::{ - constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_NANOS}, - Weight, -}; +use frame::{prelude::*, weights_prelude::*}; impl crate::WeightInfo for () { fn plan_config_change() -> Weight { - DbWeight::get().writes(1) + RocksDbWeight::get().writes(1) } fn report_equivocation(validator_count: u32, max_nominators_per_validator: u32) -> Weight { @@ -39,7 +36,7 @@ impl crate::WeightInfo for () { Weight::from_parts(175u64 * WEIGHT_REF_TIME_PER_NANOS, 0) .saturating_mul(validator_count), ) - .saturating_add(DbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().reads(5)) // check equivocation proof .saturating_add(Weight::from_parts(110u64 * WEIGHT_REF_TIME_PER_MICROS, 0)) // report offence @@ -48,7 +45,11 @@ impl crate::WeightInfo for () { 25u64 * WEIGHT_REF_TIME_PER_MICROS * max_nominators_per_validator as u64, 0, )) - .saturating_add(DbWeight::get().reads(14 + 3 * max_nominators_per_validator as u64)) - .saturating_add(DbWeight::get().writes(10 + 3 * max_nominators_per_validator as u64)) + .saturating_add( + RocksDbWeight::get().reads(14 + 3 * max_nominators_per_validator as u64), + ) + .saturating_add( + RocksDbWeight::get().writes(10 + 3 * max_nominators_per_validator as u64), + ) } } diff --git a/substrate/frame/babe/src/equivocation.rs b/substrate/frame/babe/src/equivocation.rs index 524ad23e58ee..9f2ccbb2be35 100644 --- a/substrate/frame/babe/src/equivocation.rs +++ b/substrate/frame/babe/src/equivocation.rs @@ -34,18 +34,10 @@ //! definition. use alloc::{boxed::Box, vec, vec::Vec}; -use frame_support::traits::{Get, KeyOwnerProofSystem}; -use frame_system::pallet_prelude::HeaderFor; +use frame::{prelude::*, runtime::apis::KeyTypeId, traits::KeyOwnerProofSystem}; use log::{error, info}; use sp_consensus_babe::{AuthorityId, EquivocationProof, Slot, KEY_TYPE}; -use sp_runtime::{ - transaction_validity::{ - InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, - TransactionValidityError, ValidTransaction, - }, - DispatchError, KeyTypeId, Perbill, -}; use sp_session::{GetSessionNumber, GetValidatorCount}; use sp_staking::{ offence::{Kind, Offence, OffenceReportSystem, ReportOffence}, diff --git a/substrate/frame/babe/src/lib.rs b/substrate/frame/babe/src/lib.rs index 3e33d5627c47..1d8f962e86cf 100644 --- a/substrate/frame/babe/src/lib.rs +++ b/substrate/frame/babe/src/lib.rs @@ -25,26 +25,20 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode}; -use frame_support::{ - dispatch::{DispatchResultWithPostInfo, Pays}, - ensure, - traits::{ConstU32, DisabledValidators, FindAuthor, Get, OnTimestampSet, OneSessionHandler}, - weights::Weight, - BoundedVec, WeakBoundedVec, +use frame::{ + deps::sp_runtime::{generic::DigestItem, ConsensusEngineId}, + prelude::*, + traits::{ + DisabledValidators, EstimateNextSessionRotation, Lateness as LatenessT, OneSessionHandler, + StorageInstance, + }, }; -use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor}; use sp_consensus_babe::{ digests::{NextConfigDescriptor, NextEpochDescriptor, PreDigest}, AllowedSlots, BabeAuthorityWeight, BabeEpochConfiguration, ConsensusLog, Epoch, EquivocationProof, Randomness as BabeRandomness, Slot, BABE_ENGINE_ID, RANDOMNESS_LENGTH, RANDOMNESS_VRF_CONTEXT, }; -use sp_core::crypto::Wraps; -use sp_runtime::{ - generic::DigestItem, - traits::{IsMember, One, SaturatedConversion, Saturating, Zero}, - ConsensusEngineId, Permill, -}; use sp_session::{GetSessionNumber, GetValidatorCount}; use sp_staking::{offence::OffenceReportSystem, SessionIndex}; @@ -109,11 +103,9 @@ impl EpochChangeTrigger for SameAuthoritiesForever { const UNDER_CONSTRUCTION_SEGMENT_LENGTH: u32 = 256; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; /// The BABE Pallet #[pallet::pallet] @@ -311,7 +303,7 @@ pub mod pallet { pub type SkippedEpochs = StorageValue<_, BoundedVec<(u64, SessionIndex), ConstU32<100>>, ValueQuery>; - #[derive(frame_support::DefaultNoBound)] + #[derive(frame::prelude::DefaultNoBound)] #[pallet::genesis_config] pub struct GenesisConfig { pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>, @@ -369,7 +361,6 @@ pub mod pallet { // execution. We don't run the verification again here to avoid slowing // down the runtime. debug_assert!({ - use sp_core::crypto::VrfPublic; public.vrf_verify(&transcript.clone().into_sign_data(), &signature) }); @@ -943,9 +934,7 @@ impl OnTimestampSet for Pallet { } } -impl frame_support::traits::EstimateNextSessionRotation> - for Pallet -{ +impl EstimateNextSessionRotation> for Pallet { fn average_session_length() -> BlockNumberFor { T::EpochDuration::get().saturated_into() } @@ -971,13 +960,13 @@ impl frame_support::traits::EstimateNextSessionRotation frame_support::traits::Lateness> for Pallet { +impl LatenessT> for Pallet { fn lateness(&self) -> BlockNumberFor { Lateness::::get() } } -impl sp_runtime::BoundToRuntimeAppPublic for Pallet { +impl BoundToRuntimeAppPublic for Pallet { type Public = AuthorityId; } @@ -1045,12 +1034,11 @@ fn compute_randomness( s.extend_from_slice(&vrf_output[..]); } - sp_io::hashing::blake2_256(&s) + blake2_256(&s) } pub mod migrations { use super::*; - use frame_support::pallet_prelude::{StorageValue, ValueQuery}; /// Something that can return the storage prefix of the `Babe` pallet. pub trait BabePalletPrefix: Config { @@ -1058,7 +1046,7 @@ pub mod migrations { } struct __OldNextEpochConfig(core::marker::PhantomData); - impl frame_support::traits::StorageInstance for __OldNextEpochConfig { + impl StorageInstance for __OldNextEpochConfig { fn pallet_prefix() -> &'static str { T::pallet_prefix() } diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index 23857470adc4..0e189dac5295 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -19,37 +19,28 @@ use crate::{self as pallet_babe, Config, CurrentSlot}; use codec::Encode; +use frame::{ + deps::sp_runtime::{ + curve::PiecewiseLinear, + testing::{DigestItem, Header}, + }, + testing_prelude::*, + traits::Header as _, +}; use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, onchain, SequentialPhragmen, }; -use frame_support::{ - derive_impl, parameter_types, - traits::{ConstU128, ConstU32, ConstU64, OnInitialize}, -}; use pallet_session::historical as pallet_session_historical; use sp_consensus_babe::{AuthorityId, AuthorityPair, Randomness, Slot, VrfSignature}; -use sp_core::{ - crypto::{Pair, VrfSecret}, - U256, -}; -use sp_io; -use sp_runtime::{ - curve::PiecewiseLinear, - impl_opaque_keys, - testing::{Digest, DigestItem, Header, TestXt}, - traits::{Header as _, OpaqueKeys}, - BuildStorage, Perbill, -}; use sp_staking::{EraIndex, SessionIndex}; type DummyValidatorId = u64; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( - pub enum Test - { +construct_runtime!( + pub struct Test { System: frame_system, Authorship: pallet_authorship, Balances: pallet_balances, @@ -197,11 +188,11 @@ impl Config for Test { } pub fn go_to_block(n: u64, s: u64) { - use frame_support::traits::OnFinalize; + use frame::traits::OnFinalize; - Babe::on_finalize(System::block_number()); - Session::on_finalize(System::block_number()); - Staking::on_finalize(System::block_number()); + >::on_finalize(System::block_number()); + >::on_finalize(System::block_number()); + >::on_finalize(System::block_number()); let parent_hash = if System::block_number() > 1 { let hdr = System::finalize(); @@ -292,13 +283,11 @@ pub fn make_vrf_signature_and_randomness( (signature, randomness) } -pub fn new_test_ext(authorities_len: usize) -> sp_io::TestExternalities { +pub fn new_test_ext(authorities_len: usize) -> TestState { new_test_ext_with_pairs(authorities_len).1 } -pub fn new_test_ext_with_pairs( - authorities_len: usize, -) -> (Vec, sp_io::TestExternalities) { +pub fn new_test_ext_with_pairs(authorities_len: usize) -> (Vec, TestState) { let pairs = (0..authorities_len) .map(|i| AuthorityPair::from_seed(&U256::from(i).to_little_endian())) .collect::>(); @@ -308,7 +297,7 @@ pub fn new_test_ext_with_pairs( (pairs, new_test_ext_raw_authorities(public)) } -pub fn new_test_ext_raw_authorities(authorities: Vec) -> sp_io::TestExternalities { +pub fn new_test_ext_raw_authorities(authorities: Vec) -> TestState { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); let balances: Vec<_> = (0..authorities.len()).map(|i| (i as u64, 10_000_000)).collect(); diff --git a/substrate/frame/babe/src/randomness.rs b/substrate/frame/babe/src/randomness.rs index fd52981d2a1d..92bf5ae8681a 100644 --- a/substrate/frame/babe/src/randomness.rs +++ b/substrate/frame/babe/src/randomness.rs @@ -21,9 +21,7 @@ use super::{ AuthorVrfRandomness, Config, EpochStart, NextRandomness, Randomness, RANDOMNESS_LENGTH, }; -use frame_support::traits::Randomness as RandomnessT; -use frame_system::pallet_prelude::BlockNumberFor; -use sp_runtime::traits::{Hash, One, Saturating}; +use frame::{prelude::*, traits::Randomness as RandomnessT}; /// Randomness usable by consensus protocols that **depend** upon finality and take action /// based upon on-chain commitments made during the epoch before the previous epoch. diff --git a/substrate/frame/babe/src/tests.rs b/substrate/frame/babe/src/tests.rs index 5210d9289bcd..2ae57b8dea6b 100644 --- a/substrate/frame/babe/src/tests.rs +++ b/substrate/frame/babe/src/tests.rs @@ -18,17 +18,16 @@ //! Consensus extension module tests for BABE consensus. use super::{Call, *}; -use frame_support::{ - assert_err, assert_noop, assert_ok, - dispatch::{GetDispatchInfo, Pays}, - traits::{Currency, EstimateNextSessionRotation, KeyOwnerProofSystem, OnFinalize}, +use frame::{ + deps::sp_runtime::testing::DigestItem, + testing_prelude::*, + traits::{Currency, EstimateNextSessionRotation, KeyOwnerProofSystem}, }; use mock::*; use pallet_session::ShouldEndSession; use sp_consensus_babe::{ AllowedSlots, BabeEpochConfiguration, Slot, VrfSignature, RANDOMNESS_LENGTH, }; -use sp_core::crypto::Pair; const EMPTY_RANDOMNESS: [u8; RANDOMNESS_LENGTH] = [ 74, 25, 49, 128, 53, 97, 244, 49, 222, 202, 176, 2, 231, 66, 95, 10, 133, 49, 213, 228, 86, @@ -136,7 +135,7 @@ fn current_slot_is_processed_on_initialization() { fn test_author_vrf_output(make_pre_digest: F) where - F: Fn(sp_consensus_babe::AuthorityIndex, Slot, VrfSignature) -> sp_runtime::Digest, + F: Fn(sp_consensus_babe::AuthorityIndex, Slot, VrfSignature) -> Digest, { let (pairs, mut ext) = new_test_ext_with_pairs(1); @@ -320,8 +319,6 @@ fn can_enact_next_config() { #[test] fn only_root_can_enact_config_change() { - use sp_runtime::DispatchError; - new_test_ext(1).execute_with(|| { let next_config = NextConfigDescriptor::V1 { c: (1, 4), allowed_slots: AllowedSlots::PrimarySlots }; @@ -622,7 +619,7 @@ fn report_equivocation_invalid_key_owner_proof() { #[test] fn report_equivocation_invalid_equivocation_proof() { - use sp_runtime::traits::Header; + use frame::traits::Header; let (pairs, mut ext) = new_test_ext_with_pairs(3); @@ -724,11 +721,6 @@ fn report_equivocation_invalid_equivocation_proof() { #[test] fn report_equivocation_validate_unsigned_prevents_duplicates() { - use sp_runtime::transaction_validity::{ - InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, - ValidTransaction, - }; - let (pairs, mut ext) = new_test_ext_with_pairs(3); ext.execute_with(|| { @@ -759,20 +751,14 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { // only local/inblock reports are allowed assert_eq!( - ::validate_unsigned( - TransactionSource::External, - &inner, - ), + ::validate_unsigned(TransactionSource::External, &inner,), InvalidTransaction::Call.into(), ); // the transaction is valid when passed as local let tx_tag = (offending_authority_pair.public(), CurrentSlot::::get()); assert_eq!( - ::validate_unsigned( - TransactionSource::Local, - &inner, - ), + ::validate_unsigned(TransactionSource::Local, &inner,), TransactionValidity::Ok(ValidTransaction { priority: TransactionPriority::max_value(), requires: vec![], @@ -783,7 +769,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { ); // the pre dispatch checks should also pass - assert_ok!(::pre_dispatch(&inner)); + assert_ok!(::pre_dispatch(&inner)); // we submit the report Babe::report_equivocation_unsigned( @@ -796,17 +782,11 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { // the report should now be considered stale and the transaction is invalid. // the check for staleness should be done on both `validate_unsigned` and on `pre_dispatch` assert_err!( - ::validate_unsigned( - TransactionSource::Local, - &inner, - ), + ::validate_unsigned(TransactionSource::Local, &inner,), InvalidTransaction::Stale, ); - assert_err!( - ::pre_dispatch(&inner), - InvalidTransaction::Stale, - ); + assert_err!(::pre_dispatch(&inner), InvalidTransaction::Stale,); }); } @@ -941,7 +921,7 @@ fn valid_equivocation_reports_dont_pay_fees() { #[test] fn add_epoch_configurations_migration_works() { - use frame_support::storage::migration::{get_storage_value, put_storage_value}; + use storage::migration::{get_storage_value, put_storage_value}; impl crate::migrations::BabePalletPrefix for Test { fn pallet_prefix() -> &'static str { diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 8031ddf96e6a..20328e562b78 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -203,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, FindAuthor, IsSubType, OnRuntimeUpgrade, OnTimestampSet, + }; /// Pallet prelude of `frame-system`. #[doc(no_inline)] @@ -213,19 +215,25 @@ pub mod prelude { #[doc(no_inline)] pub use super::derive::*; - /// All hashing related things - pub use super::hashing::*; + /// All hashing related things. + pub use super::cryptography::*; + + /// All arithmetic types used for safe math. + pub use super::arithmetic::*; /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, - Saturating, StaticLookup, TrailingZeroInput, + BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, IsMember, OpaqueKeys, + SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, }; - /// Other error/result types for runtime + /// Runtime types #[doc(no_inline)] - pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; + pub use sp_runtime::{ + curve::PiecewiseLinear, BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, + DispatchResultWithInfo, TokenError, + }; } #[cfg(any(feature = "try-runtime", test))] @@ -279,7 +287,10 @@ pub mod weights_prelude { pub use frame_support::{ traits::Get, weights::{ - constants::{ParityDbWeight, RocksDbWeight}, + constants::{ + ParityDbWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_MICROS, + WEIGHT_REF_TIME_PER_NANOS, + }, Weight, }, }; @@ -392,7 +403,7 @@ pub mod runtime { }; pub use sp_inherents::{CheckInherentsResult, InherentData}; pub use sp_keyring::Sr25519Keyring; - pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode}; + pub use sp_runtime::{impl_opaque_keys, ApplyExtrinsicResult, ExtrinsicInclusionMode}; } /// Types and traits for runtimes that implement runtime APIs. @@ -493,7 +504,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::{Digest, TestXt}, + BuildStorage, + }; } } @@ -527,8 +541,12 @@ 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_core::{ + crypto::{VrfPublic, VrfSecret, Wraps}, + hashing::*, + Pair, H160, H256, H512, U256, U512, + }; pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index cfb8b896f939..fc76020b97bf 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -55,9 +55,11 @@ use syn::parse::{Parse, ParseStream}; /// /// # Example /// -/// ``` +/// ```ignore /// # fn main() {} -/// use sp_runtime::curve::PiecewiseLinear; +/// // polkadot-sdk-frame dependency prelude which includes `PiecewiseLinear` +/// use frame::prelude::*; +/// // or `use sp_runtime::curve::PiecewiseLinear;` if you are using `sp-runtime` dependency. /// /// pallet_staking_reward_curve::build! { /// const I_NPOS: PiecewiseLinear<'static> = curve!( @@ -93,7 +95,14 @@ pub fn build(input: TokenStream) -> TokenStream { let ident = syn::Ident::new(&polkadot_sdk, Span::call_site()); quote!( #[doc(hidden)] pub use #ident::sp_runtime as _sp_runtime; ) }, - _ => syn::Error::new(Span::call_site(), e).to_compile_error(), + Ok(FoundCrate::Itself) => syn::Error::new(Span::call_site(), e).to_compile_error(), + Err(e) => match crate_name("polkadot-sdk-frame") { + Ok(FoundCrate::Name(polkadot_sdk_frame)) => { + let ident = syn::Ident::new(&polkadot_sdk_frame, Span::call_site()); + quote!( #[doc(hidden)] pub use #ident::deps::sp_runtime as _sp_runtime; ) + }, + _ => syn::Error::new(Span::call_site(), e).to_compile_error(), + }, }, };