From f2bcae79f4ce3caae88d4fb77870ef80ca5fc57d Mon Sep 17 00:00:00 2001 From: snowmead Date: Thu, 7 Nov 2024 23:45:26 -0500 Subject: [PATCH 01/16] pallet-babe prelude imports, additional umbrella re-exports --- Cargo.lock | 7 +- substrate/frame/babe/Cargo.toml | 77 ++++++++------------- substrate/frame/babe/src/benchmarking.rs | 29 ++++---- substrate/frame/babe/src/default_weights.rs | 17 ++--- substrate/frame/babe/src/equivocation.rs | 10 +-- substrate/frame/babe/src/lib.rs | 40 ++++------- substrate/frame/babe/src/mock.rs | 44 ++++-------- substrate/frame/babe/src/randomness.rs | 4 +- substrate/frame/babe/src/tests.rs | 45 ++++-------- substrate/frame/src/lib.rs | 36 +++++++--- 10 files changed, 124 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f171ad756c0..1b1e1a788fef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10965,10 +10965,7 @@ dependencies = [ name = "pallet-babe" version = "28.0.0" dependencies = [ - "frame-benchmarking", "frame-election-provider-support", - "frame-support", - "frame-system", "log", "pallet-authorship", "pallet-balances", @@ -10978,12 +10975,10 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-timestamp", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", "sp-application-crypto 30.0.0", "sp-consensus-babe", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", "sp-session", "sp-staking", ] diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index f0a7f4648c0a..f5011ed32afd 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,41 @@ 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", - "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", + "codec/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-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", - "pallet-balances/runtime-benchmarks", - "pallet-offences/runtime-benchmarks", - "pallet-staking/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "sp-staking/runtime-benchmarks", + "frame-election-provider-support/runtime-benchmarks", + "frame/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-offences/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "sp-staking/runtime-benchmarks", ] try-runtime = [ - "frame-election-provider-support/try-runtime", - "frame-support/try-runtime", - "frame-system/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", + "frame-election-provider-support/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", ] diff --git a/substrate/frame/babe/src/benchmarking.rs b/substrate/frame/babe/src/benchmarking.rs index 6b0e31e84718..30fd654d5d93 100644 --- a/substrate/frame/babe/src/benchmarking.rs +++ b/substrate/frame/babe/src/benchmarking.rs @@ -20,14 +20,16 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::v1::benchmarks; +use frame::benchmarking::prelude::*; type Header = sp_runtime::generic::Header; -benchmarks! { - check_equivocation_proof { - let x in 0 .. 1; +#[benchmarks] +mod benchmarks { + use super::*; + #[benchmark] + fn check_equivocation_proof(x: Linear<0, 1>) -> Result<(), BenchmarkError> { // NOTE: generated with the test below `test_generate_equivocation_report_blob`. // the output is not deterministic since keys are generated randomly (and therefore // signature content changes). it should not affect the benchmark. @@ -53,22 +55,21 @@ benchmarks! { 124, 11, 167, 227, 103, 88, 78, 23, 228, 33, 96, 41, 207, 183, 227, 189, 114, 70, 254, 30, 128, 243, 233, 83, 214, 45, 74, 182, 120, 119, 64, 243, 219, 119, 63, 240, 205, 123, 231, 82, 205, 174, 143, 70, 2, 86, 182, 20, 16, 141, 145, 91, 116, 195, 58, 223, - 175, 145, 255, 7, 121, 133 + 175, 145, 255, 7, 121, 133, ]; let equivocation_proof1: sp_consensus_babe::EquivocationProof
= Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap(); let equivocation_proof2 = equivocation_proof1.clone(); - }: { - sp_consensus_babe::check_equivocation_proof::
(equivocation_proof1); - } verify { + + #[extrinsic_call] + _(equivocation_proof1); + 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,); + + Ok(()) + } } 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..453930f00575 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, + prelude::*, + traits::{ + DisabledValidators, EstimateNextSessionRotation, FindAuthor, IsMember, + Lateness as LatenessT, OnTimestampSet, 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 c2e24c73a7bd..7818dd87bc6f 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -19,37 +19,23 @@ use crate::{self as pallet_babe, Config, CurrentSlot}; use codec::Encode; +use frame::{ + deps::sp_runtime::curve::PiecewiseLinear, prelude::*, runtime::prelude::*, testing_prelude::*, +}; 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 +183,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 +278,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 +292,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(); @@ -356,7 +340,7 @@ pub fn generate_equivocation_proof( offender_authority_index: u32, offender_authority_pair: &AuthorityPair, slot: Slot, -) -> sp_consensus_babe::EquivocationProof
{ +) -> sp_consensus_babe::EquivocationProof { use sp_consensus_babe::digests::CompatibleDigestItem; let current_block = System::block_number(); @@ -374,7 +358,7 @@ pub fn generate_equivocation_proof( // sign the header prehash and sign it, adding it to the block as the seal // digest item - let seal_header = |header: &mut Header| { + let seal_header = |header: &mut TestHeader| { let prehash = header.hash(); let seal = ::babe_seal( offender_authority_pair.sign(prehash.as_ref()), 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 eca958160239..fb13efd49376 100644 --- a/substrate/frame/babe/src/tests.rs +++ b/substrate/frame/babe/src/tests.rs @@ -17,18 +17,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 super::{Call, DigestItem, *}; +use frame::{ + 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 +134,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 +318,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 +618,7 @@ fn report_equivocation_invalid_key_owner_proof() { #[test] fn report_equivocation_invalid_equivocation_proof() { - use sp_runtime::traits::Header; + use frame::prelude::Header as _; let (pairs, mut ext) = new_test_ext_with_pairs(3); @@ -724,11 +720,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 +750,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 +768,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 +781,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 +920,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 a8d2c0b3fc56..10e9d8845220 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -213,19 +213,25 @@ pub mod prelude { #[doc(no_inline)] pub use super::derive::*; - /// All hashing related things + /// All hashing related things. pub use super::hashing::*; + /// All arithmetic types used for safe math. + pub use super::arithmetic::*; + /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, Saturating, StaticLookup, - TrailingZeroInput, + Bounded, DispatchInfoOf, Dispatchable, Header, OpaqueKeys, SaturatedConversion, Saturating, + StaticLookup, TrailingZeroInput, ValidateUnsigned, }; - /// Other error/result types for runtime + /// Other error/result types for runtime. #[doc(no_inline)] - pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; + pub use sp_runtime::{ + BoundToRuntimeAppPublic, ConsensusEngineId, DispatchErrorWithPostInfo, + DispatchResultWithInfo, TokenError, + }; } #[cfg(any(feature = "try-runtime", test))] @@ -279,7 +285,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, }, }; @@ -389,7 +398,7 @@ pub mod runtime { }; pub use sp_inherents::{CheckInherentsResult, InherentData}; pub use sp_keyring::AccountKeyring; - pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode}; + pub use sp_runtime::{impl_opaque_keys, ApplyExtrinsicResult, ExtrinsicInclusionMode}; } /// Types and traits for runtimes that implement runtime APIs. @@ -490,7 +499,12 @@ 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, DigestItem, TestXt}, + BuildStorage, + }; + /// Re-export testing `Header` to unambiguate re-export `prelude::Header`. + pub type TestHeader = sp_runtime::testing::Header; } } @@ -525,7 +539,11 @@ pub mod derive { } pub mod hashing { - pub use sp_core::{hashing::*, H160, H256, H512, U256, U512}; + pub use sp_core::{ + crypto::{VrfPublic, VrfSecret, Wraps}, + hashing::*, + Pair, H160, H256, H512, U256, U512, + }; pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } From aaf16a79eae7af6fe70e50487be1c6af8fa9d64e Mon Sep 17 00:00:00 2001 From: snowmead Date: Fri, 8 Nov 2024 09:11:40 -0500 Subject: [PATCH 02/16] fix: revert Header exports in umbrella --- substrate/frame/babe/src/mock.rs | 9 ++++++--- substrate/frame/babe/src/tests.rs | 2 +- substrate/frame/src/lib.rs | 4 +--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index 7818dd87bc6f..6edb96f06443 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -20,7 +20,10 @@ use crate::{self as pallet_babe, Config, CurrentSlot}; use codec::Encode; use frame::{ - deps::sp_runtime::curve::PiecewiseLinear, prelude::*, runtime::prelude::*, testing_prelude::*, + deps::sp_runtime::{curve::PiecewiseLinear, testing::Header}, + prelude::*, + runtime::prelude::*, + testing_prelude::*, }; use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, @@ -340,7 +343,7 @@ pub fn generate_equivocation_proof( offender_authority_index: u32, offender_authority_pair: &AuthorityPair, slot: Slot, -) -> sp_consensus_babe::EquivocationProof { +) -> sp_consensus_babe::EquivocationProof
{ use sp_consensus_babe::digests::CompatibleDigestItem; let current_block = System::block_number(); @@ -358,7 +361,7 @@ pub fn generate_equivocation_proof( // sign the header prehash and sign it, adding it to the block as the seal // digest item - let seal_header = |header: &mut TestHeader| { + let seal_header = |header: &mut Header| { let prehash = header.hash(); let seal = ::babe_seal( offender_authority_pair.sign(prehash.as_ref()), diff --git a/substrate/frame/babe/src/tests.rs b/substrate/frame/babe/src/tests.rs index fb13efd49376..9f211f9892bf 100644 --- a/substrate/frame/babe/src/tests.rs +++ b/substrate/frame/babe/src/tests.rs @@ -618,7 +618,7 @@ fn report_equivocation_invalid_key_owner_proof() { #[test] fn report_equivocation_invalid_equivocation_proof() { - use frame::prelude::Header as _; + use frame::traits::Header; let (pairs, mut ext) = new_test_ext_with_pairs(3); diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 9b9b9a718997..c02e43133b71 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -222,7 +222,7 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - Bounded, DispatchInfoOf, Dispatchable, Header, OpaqueKeys, SaturatedConversion, Saturating, + Bounded, DispatchInfoOf, Dispatchable, OpaqueKeys, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, }; @@ -506,8 +506,6 @@ pub mod runtime { testing::{Digest, DigestItem, TestXt}, BuildStorage, }; - /// Re-export testing `Header` to unambiguate re-export `prelude::Header`. - pub type TestHeader = sp_runtime::testing::Header; } } From b6bfd0ac7804fd2ab8781791069d920eed5477fa Mon Sep 17 00:00:00 2001 From: snowmead Date: Fri, 8 Nov 2024 13:57:03 -0500 Subject: [PATCH 03/16] use umbrella crate in staking reward curve --- Cargo.lock | 2 +- substrate/frame/staking/reward-curve/Cargo.toml | 2 +- substrate/frame/staking/reward-curve/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86180637dddf..5619520185f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12874,10 +12874,10 @@ dependencies = [ name = "pallet-staking-reward-curve" version = "11.0.0" dependencies = [ + "polkadot-sdk-frame", "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "sp-runtime 31.0.1", "syn 2.0.87", ] diff --git a/substrate/frame/staking/reward-curve/Cargo.toml b/substrate/frame/staking/reward-curve/Cargo.toml index 8e60b3962a99..7beae4977441 100644 --- a/substrate/frame/staking/reward-curve/Cargo.toml +++ b/substrate/frame/staking/reward-curve/Cargo.toml @@ -24,4 +24,4 @@ quote = { workspace = true } syn = { features = ["full", "visit"], workspace = true } [dev-dependencies] -sp-runtime = { workspace = true, default-features = true } +frame = { workspace = true, features = ["runtime"] } diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index cfb8b896f939..77356857f882 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -82,7 +82,7 @@ pub fn build(input: TokenStream) -> TokenStream { let imports = match crate_name("sp-runtime") { Ok(FoundCrate::Itself) => quote!( #[doc(hidden)] - pub use sp_runtime as _sp_runtime; + pub use frame::deps::sp_runtime as _sp_runtime; ), Ok(FoundCrate::Name(sp_runtime)) => { let ident = syn::Ident::new(&sp_runtime, Span::call_site()); From 84ee9b11f8893450a3a40186abd68693b554f69c Mon Sep 17 00:00:00 2001 From: snowmead Date: Fri, 8 Nov 2024 16:21:29 -0500 Subject: [PATCH 04/16] fix: import Header trait, pallet_staking_reward_curve build! proc macro imports --- substrate/frame/babe/src/mock.rs | 5 ++--- substrate/frame/staking/reward-curve/Cargo.toml | 2 +- substrate/frame/staking/reward-curve/src/lib.rs | 6 +++--- substrate/frame/staking/reward-curve/tests/test.rs | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index 6edb96f06443..b38b62154322 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -21,9 +21,8 @@ use crate::{self as pallet_babe, Config, CurrentSlot}; use codec::Encode; use frame::{ deps::sp_runtime::{curve::PiecewiseLinear, testing::Header}, - prelude::*, - runtime::prelude::*, testing_prelude::*, + traits::Header as _, }; use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, @@ -117,7 +116,7 @@ impl pallet_balances::Config for Test { } pallet_staking_reward_curve::build! { - const REWARD_CURVE: PiecewiseLinear<'static> = curve!( + const REWARD_CURVE: frame::deps::sp_runtime::curve::PiecewiseLinear<'static> = curve!( min_inflation: 0_025_000u64, max_inflation: 0_100_000, ideal_stake: 0_500_000, diff --git a/substrate/frame/staking/reward-curve/Cargo.toml b/substrate/frame/staking/reward-curve/Cargo.toml index 7beae4977441..fa9616af2170 100644 --- a/substrate/frame/staking/reward-curve/Cargo.toml +++ b/substrate/frame/staking/reward-curve/Cargo.toml @@ -24,4 +24,4 @@ quote = { workspace = true } syn = { features = ["full", "visit"], workspace = true } [dev-dependencies] -frame = { workspace = true, features = ["runtime"] } +frame = { workspace = true, features = ["experimental", "runtime"] } diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index 77356857f882..60c9d7cd23d0 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -79,14 +79,14 @@ pub fn build(input: TokenStream) -> TokenStream { let declaration = generate_piecewise_linear(points); let test_module = generate_test_module(&input); - let imports = match crate_name("sp-runtime") { + let imports = match crate_name("polkadot-sdk-frame") { Ok(FoundCrate::Itself) => quote!( #[doc(hidden)] - pub use frame::deps::sp_runtime as _sp_runtime; + pub use deps::sp_runtime as _sp_runtime; ), Ok(FoundCrate::Name(sp_runtime)) => { let ident = syn::Ident::new(&sp_runtime, Span::call_site()); - quote!( #[doc(hidden)] pub use #ident as _sp_runtime; ) + quote!( #[doc(hidden)] pub use #ident::deps::sp_runtime as _sp_runtime; ) }, Err(e) => match crate_name("polkadot-sdk") { Ok(FoundCrate::Name(polkadot_sdk)) => { diff --git a/substrate/frame/staking/reward-curve/tests/test.rs b/substrate/frame/staking/reward-curve/tests/test.rs index 339e00322249..5fb3f4c05572 100644 --- a/substrate/frame/staking/reward-curve/tests/test.rs +++ b/substrate/frame/staking/reward-curve/tests/test.rs @@ -20,7 +20,7 @@ mod test_small_falloff { pallet_staking_reward_curve::build! { - const REWARD_CURVE: sp_runtime::curve::PiecewiseLinear<'static> = curve!( + const REWARD_CURVE: frame::deps::sp_runtime::curve::PiecewiseLinear<'static> = curve!( min_inflation: 0_020_000, max_inflation: 0_200_000, ideal_stake: 0_600_000, @@ -33,7 +33,7 @@ mod test_small_falloff { mod test_big_falloff { pallet_staking_reward_curve::build! { - const REWARD_CURVE: sp_runtime::curve::PiecewiseLinear<'static> = curve!( + const REWARD_CURVE: frame::deps::sp_runtime::curve::PiecewiseLinear<'static> = curve!( min_inflation: 0_100_000, max_inflation: 0_400_000, ideal_stake: 0_400_000, From 5cc09041db8b1df3da49018420b0707da0efd138 Mon Sep 17 00:00:00 2001 From: snowmead Date: Fri, 8 Nov 2024 16:36:21 -0500 Subject: [PATCH 05/16] prdoc --- prdoc/pr_6412.prdoc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 prdoc/pr_6412.prdoc diff --git a/prdoc/pr_6412.prdoc b/prdoc/pr_6412.prdoc new file mode 100644 index 000000000000..1ebf8442481d --- /dev/null +++ b/prdoc/pr_6412.prdoc @@ -0,0 +1,18 @@ +# 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. + Migrates benchmarking from v1 to v2 for pallet-babe. + +crates: + - name: polkadot-sdk-frame + bump: minor + - name: pallet-babe + bump: patch + - name: pallet-staking-reward-curve + bump: patch From b01a486302357729d10e79dc4d0ca167de53e808 Mon Sep 17 00:00:00 2001 From: snowmead Date: Fri, 15 Nov 2024 23:10:34 -0500 Subject: [PATCH 06/16] revert frame dependency reward-curve pallet, add re-exports to umbrella, fix benchmarking --- Cargo.lock | 2 +- substrate/frame/babe/Cargo.toml | 58 +++++++++---------- substrate/frame/babe/src/benchmarking.rs | 8 ++- substrate/frame/babe/src/lib.rs | 4 +- substrate/frame/src/lib.rs | 14 +++-- .../frame/staking/reward-curve/Cargo.toml | 2 +- .../frame/staking/reward-curve/src/lib.rs | 15 +++-- .../frame/staking/reward-curve/tests/test.rs | 4 +- 8 files changed, 59 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5619520185f9..86180637dddf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12874,10 +12874,10 @@ dependencies = [ name = "pallet-staking-reward-curve" version = "11.0.0" dependencies = [ - "polkadot-sdk-frame", "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", + "sp-runtime 31.0.1", "syn 2.0.87", ] diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index f5011ed32afd..49ea5d2b6754 100644 --- a/substrate/frame/babe/Cargo.toml +++ b/substrate/frame/babe/Cargo.toml @@ -38,37 +38,37 @@ pallet-staking-reward-curve = { workspace = true, default-features = true } [features] default = ["std"] std = [ - "codec/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-session/std", - "sp-staking/std", + "codec/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-session/std", + "sp-staking/std", ] runtime-benchmarks = [ - "frame-election-provider-support/runtime-benchmarks", - "frame/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-offences/runtime-benchmarks", - "pallet-staking/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "sp-staking/runtime-benchmarks", + "frame-election-provider-support/runtime-benchmarks", + "frame/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-offences/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "sp-staking/runtime-benchmarks", ] try-runtime = [ - "frame-election-provider-support/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", + "frame-election-provider-support/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", ] diff --git a/substrate/frame/babe/src/benchmarking.rs b/substrate/frame/babe/src/benchmarking.rs index 30fd654d5d93..38c1299371fb 100644 --- a/substrate/frame/babe/src/benchmarking.rs +++ b/substrate/frame/babe/src/benchmarking.rs @@ -22,7 +22,7 @@ use super::*; use frame::benchmarking::prelude::*; -type Header = sp_runtime::generic::Header; +type Header = frame::deps::sp_runtime::generic::Header; #[benchmarks] mod benchmarks { @@ -63,8 +63,10 @@ mod benchmarks { let equivocation_proof2 = equivocation_proof1.clone(); - #[extrinsic_call] - _(equivocation_proof1); + #[block] + { + sp_consensus_babe::check_equivocation_proof::
(equivocation_proof1); + } assert!(sp_consensus_babe::check_equivocation_proof::
(equivocation_proof2)); diff --git a/substrate/frame/babe/src/lib.rs b/substrate/frame/babe/src/lib.rs index 453930f00575..dad58f2db4d2 100644 --- a/substrate/frame/babe/src/lib.rs +++ b/substrate/frame/babe/src/lib.rs @@ -29,8 +29,8 @@ use frame::{ deps::sp_runtime::generic::DigestItem, prelude::*, traits::{ - DisabledValidators, EstimateNextSessionRotation, FindAuthor, IsMember, - Lateness as LatenessT, OnTimestampSet, OneSessionHandler, StorageInstance, + DisabledValidators, EstimateNextSessionRotation, Lateness as LatenessT, OneSessionHandler, + StorageInstance, }, }; use sp_consensus_babe::{ diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index c02e43133b71..3fe65c48daa1 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)] @@ -214,7 +216,7 @@ 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::*; @@ -222,11 +224,11 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - Bounded, DispatchInfoOf, Dispatchable, OpaqueKeys, SaturatedConversion, Saturating, - StaticLookup, TrailingZeroInput, ValidateUnsigned, + Bounded, DispatchInfoOf, Dispatchable, IsMember, OpaqueKeys, SaturatedConversion, + Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, }; - /// Other error/result types for runtime. + /// Other types for runtime. #[doc(no_inline)] pub use sp_runtime::{ BoundToRuntimeAppPublic, ConsensusEngineId, DispatchErrorWithPostInfo, @@ -539,7 +541,7 @@ pub mod derive { pub use sp_runtime::RuntimeDebug; } -pub mod hashing { +pub mod cryptography { pub use sp_core::{ crypto::{VrfPublic, VrfSecret, Wraps}, hashing::*, diff --git a/substrate/frame/staking/reward-curve/Cargo.toml b/substrate/frame/staking/reward-curve/Cargo.toml index fa9616af2170..8e60b3962a99 100644 --- a/substrate/frame/staking/reward-curve/Cargo.toml +++ b/substrate/frame/staking/reward-curve/Cargo.toml @@ -24,4 +24,4 @@ quote = { workspace = true } syn = { features = ["full", "visit"], workspace = true } [dev-dependencies] -frame = { workspace = true, features = ["experimental", "runtime"] } +sp-runtime = { workspace = true, default-features = true } diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index 60c9d7cd23d0..03885c33bc05 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -79,21 +79,28 @@ pub fn build(input: TokenStream) -> TokenStream { let declaration = generate_piecewise_linear(points); let test_module = generate_test_module(&input); - let imports = match crate_name("polkadot-sdk-frame") { + let imports = match crate_name("sp-runtime") { Ok(FoundCrate::Itself) => quote!( #[doc(hidden)] - pub use deps::sp_runtime as _sp_runtime; + pub use sp_runtime as _sp_runtime; ), Ok(FoundCrate::Name(sp_runtime)) => { let ident = syn::Ident::new(&sp_runtime, Span::call_site()); - quote!( #[doc(hidden)] pub use #ident::deps::sp_runtime as _sp_runtime; ) + quote!( #[doc(hidden)] pub use #ident as _sp_runtime; ) }, Err(e) => match crate_name("polkadot-sdk") { Ok(FoundCrate::Name(polkadot_sdk)) => { 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(), + }, }, }; diff --git a/substrate/frame/staking/reward-curve/tests/test.rs b/substrate/frame/staking/reward-curve/tests/test.rs index 5fb3f4c05572..339e00322249 100644 --- a/substrate/frame/staking/reward-curve/tests/test.rs +++ b/substrate/frame/staking/reward-curve/tests/test.rs @@ -20,7 +20,7 @@ mod test_small_falloff { pallet_staking_reward_curve::build! { - const REWARD_CURVE: frame::deps::sp_runtime::curve::PiecewiseLinear<'static> = curve!( + const REWARD_CURVE: sp_runtime::curve::PiecewiseLinear<'static> = curve!( min_inflation: 0_020_000, max_inflation: 0_200_000, ideal_stake: 0_600_000, @@ -33,7 +33,7 @@ mod test_small_falloff { mod test_big_falloff { pallet_staking_reward_curve::build! { - const REWARD_CURVE: frame::deps::sp_runtime::curve::PiecewiseLinear<'static> = curve!( + const REWARD_CURVE: sp_runtime::curve::PiecewiseLinear<'static> = curve!( min_inflation: 0_100_000, max_inflation: 0_400_000, ideal_stake: 0_400_000, From ac30fd67eb648672927f1d8bdc3e7d65b4ce9d3d Mon Sep 17 00:00:00 2001 From: snowmead Date: Fri, 15 Nov 2024 23:44:26 -0500 Subject: [PATCH 07/16] update doc --- substrate/frame/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 3fe65c48daa1..d780c1f02837 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -228,7 +228,7 @@ pub mod prelude { Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, }; - /// Other types for runtime. + /// Runtime types #[doc(no_inline)] pub use sp_runtime::{ BoundToRuntimeAppPublic, ConsensusEngineId, DispatchErrorWithPostInfo, From 8f480534190d87be9d0c7410c01ad5216f73e425 Mon Sep 17 00:00:00 2001 From: snowmead Date: Sun, 17 Nov 2024 09:40:58 -0500 Subject: [PATCH 08/16] add curve::PiecewiseLinear to frame umbrella prelude, update reward-curve proc macro docs --- prdoc/pr_6412.prdoc | 3 ++- substrate/frame/babe/src/mock.rs | 2 +- substrate/frame/src/lib.rs | 4 ++-- substrate/frame/staking/reward-curve/src/lib.rs | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/prdoc/pr_6412.prdoc b/prdoc/pr_6412.prdoc index 1ebf8442481d..fc6b8820ac43 100644 --- a/prdoc/pr_6412.prdoc +++ b/prdoc/pr_6412.prdoc @@ -7,6 +7,7 @@ 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: @@ -15,4 +16,4 @@ crates: - name: pallet-babe bump: patch - name: pallet-staking-reward-curve - bump: patch + bump: minor diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index c78090b1b811..ca3d2f835429 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -116,7 +116,7 @@ impl pallet_balances::Config for Test { } pallet_staking_reward_curve::build! { - const REWARD_CURVE: frame::deps::sp_runtime::curve::PiecewiseLinear<'static> = curve!( + const REWARD_CURVE: PiecewiseLinear<'static> = curve!( min_inflation: 0_025_000u64, max_inflation: 0_100_000, ideal_stake: 0_500_000, diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index d780c1f02837..5232d337b8b7 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -231,8 +231,8 @@ pub mod prelude { /// Runtime types #[doc(no_inline)] pub use sp_runtime::{ - BoundToRuntimeAppPublic, ConsensusEngineId, DispatchErrorWithPostInfo, - DispatchResultWithInfo, TokenError, + curve::PiecewiseLinear, BoundToRuntimeAppPublic, ConsensusEngineId, + DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, }; } diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index 03885c33bc05..05eaaaa5844c 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -57,7 +57,9 @@ use syn::parse::{Parse, ParseStream}; /// /// ``` /// # 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!( From 8293b24c293022ba25fa544e8e9c83121a34f0e1 Mon Sep 17 00:00:00 2001 From: snowmead Date: Sun, 17 Nov 2024 15:09:54 -0500 Subject: [PATCH 09/16] remove test pallets from std feature --- substrate/frame/babe/Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index 49ea5d2b6754..d718fe27e359 100644 --- a/substrate/frame/babe/Cargo.toml +++ b/substrate/frame/babe/Cargo.toml @@ -42,16 +42,12 @@ 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-session/std", - "sp-staking/std", ] runtime-benchmarks = [ "frame-election-provider-support/runtime-benchmarks", From a4764652f3566e367dc73ad0ddbfa70ea3eed244 Mon Sep 17 00:00:00 2001 From: snowmead Date: Sun, 17 Nov 2024 15:21:40 -0500 Subject: [PATCH 10/16] add back sp-staking --- substrate/frame/babe/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index d718fe27e359..e94f2e615d12 100644 --- a/substrate/frame/babe/Cargo.toml +++ b/substrate/frame/babe/Cargo.toml @@ -48,6 +48,7 @@ std = [ "sp-application-crypto/std", "sp-consensus-babe/std", "sp-session/std", + "sp-staking/std", ] runtime-benchmarks = [ "frame-election-provider-support/runtime-benchmarks", From 453ef581d2dd80cb5d89f73b23f2d2c9bd8c1128 Mon Sep 17 00:00:00 2001 From: snowmead Date: Wed, 27 Nov 2024 07:55:49 -0500 Subject: [PATCH 11/16] fmt --- substrate/frame/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 54a976be3431..82ebd35b7f29 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -224,8 +224,8 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, IsMember, OpaqueKeys, SaturatedConversion, - Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned + BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, IsMember, OpaqueKeys, + SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, ValidateUnsigned, }; /// Runtime types From 07b422510e5e7e812b5933148e6608155fbeb407 Mon Sep 17 00:00:00 2001 From: Michael Assaf Date: Mon, 16 Dec 2024 14:05:44 -0500 Subject: [PATCH 12/16] Remove ConsensusEngineId and DigestItem from frame prelude --- substrate/frame/babe/src/lib.rs | 2 +- substrate/frame/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/substrate/frame/babe/src/lib.rs b/substrate/frame/babe/src/lib.rs index dad58f2db4d2..1d8f962e86cf 100644 --- a/substrate/frame/babe/src/lib.rs +++ b/substrate/frame/babe/src/lib.rs @@ -26,7 +26,7 @@ extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; use codec::{Decode, Encode}; use frame::{ - deps::sp_runtime::generic::DigestItem, + deps::sp_runtime::{generic::DigestItem, ConsensusEngineId}, prelude::*, traits::{ DisabledValidators, EstimateNextSessionRotation, Lateness as LatenessT, OneSessionHandler, diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 82ebd35b7f29..9b2aed08395f 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -231,8 +231,8 @@ pub mod prelude { /// Runtime types #[doc(no_inline)] pub use sp_runtime::{ - curve::PiecewiseLinear, BoundToRuntimeAppPublic, ConsensusEngineId, - DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + curve::PiecewiseLinear, BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, + DispatchResultWithInfo, TokenError, }; } @@ -505,7 +505,7 @@ pub mod runtime { pub mod testing_prelude { pub use sp_core::storage::Storage; pub use sp_runtime::{ - testing::{Digest, DigestItem, TestXt}, + testing::{Digest, TestXt}, BuildStorage, }; } From d141f2590e35fd30ee9eedda6e670b012238878d Mon Sep 17 00:00:00 2001 From: Michael Assaf Date: Mon, 16 Dec 2024 15:06:58 -0500 Subject: [PATCH 13/16] remove AccountKeyring --- substrate/frame/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index b9dfc9619ffa..20328e562b78 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -402,7 +402,7 @@ pub mod runtime { LOCAL_TESTNET_RUNTIME_PRESET, }; pub use sp_inherents::{CheckInherentsResult, InherentData}; - pub use sp_keyring::{AccountKeyring, Sr25519Keyring}; + pub use sp_keyring::Sr25519Keyring; pub use sp_runtime::{impl_opaque_keys, ApplyExtrinsicResult, ExtrinsicInclusionMode}; } From 026d174a120ac8be4d74ddaf761d1142cd779ab2 Mon Sep 17 00:00:00 2001 From: Michael Assaf Date: Mon, 16 Dec 2024 15:27:05 -0500 Subject: [PATCH 14/16] import DigestItem --- substrate/frame/babe/src/mock.rs | 5 ++++- substrate/frame/babe/src/tests.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index ca3d2f835429..0e189dac5295 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -20,7 +20,10 @@ use crate::{self as pallet_babe, Config, CurrentSlot}; use codec::Encode; use frame::{ - deps::sp_runtime::{curve::PiecewiseLinear, testing::Header}, + deps::sp_runtime::{ + curve::PiecewiseLinear, + testing::{DigestItem, Header}, + }, testing_prelude::*, traits::Header as _, }; diff --git a/substrate/frame/babe/src/tests.rs b/substrate/frame/babe/src/tests.rs index 4d2dbaf02365..2ae57b8dea6b 100644 --- a/substrate/frame/babe/src/tests.rs +++ b/substrate/frame/babe/src/tests.rs @@ -17,8 +17,9 @@ //! Consensus extension module tests for BABE consensus. -use super::{Call, DigestItem, *}; +use super::{Call, *}; use frame::{ + deps::sp_runtime::testing::DigestItem, testing_prelude::*, traits::{Currency, EstimateNextSessionRotation, KeyOwnerProofSystem}, }; From 8cf8eab8cbb4e09b75cad3e5c50fc450158d176a Mon Sep 17 00:00:00 2001 From: Michael Assaf Date: Mon, 16 Dec 2024 17:50:16 -0500 Subject: [PATCH 15/16] update semver in pr doc --- prdoc/pr_6412.prdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prdoc/pr_6412.prdoc b/prdoc/pr_6412.prdoc index fc6b8820ac43..24f8770b89db 100644 --- a/prdoc/pr_6412.prdoc +++ b/prdoc/pr_6412.prdoc @@ -12,8 +12,8 @@ doc: crates: - name: polkadot-sdk-frame - bump: minor - - name: pallet-babe bump: patch - - name: pallet-staking-reward-curve + - name: pallet-babe bump: minor + - name: pallet-staking-reward-curve + bump: patch From 9136209ef3784ab05bf84f457de081b243221b47 Mon Sep 17 00:00:00 2001 From: Michael Assaf Date: Wed, 18 Dec 2024 09:57:32 -0500 Subject: [PATCH 16/16] fix: ignore reward curve rust docs --- substrate/frame/staking/reward-curve/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index 05eaaaa5844c..fc76020b97bf 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -55,7 +55,7 @@ use syn::parse::{Parse, ParseStream}; /// /// # Example /// -/// ``` +/// ```ignore /// # fn main() {} /// // polkadot-sdk-frame dependency prelude which includes `PiecewiseLinear` /// use frame::prelude::*;