From 6481857374ad377787e84e1df4ead5c7c960808a Mon Sep 17 00:00:00 2001 From: Dom Date: Sat, 21 Dec 2024 16:10:01 -0500 Subject: [PATCH 01/31] Update salary logic to use BlockNumberProvider --- substrate/frame/salary/src/benchmarking.rs | 29 ++++++++++------ substrate/frame/salary/src/lib.rs | 34 ++++++++++++------- .../frame/salary/src/tests/integration.rs | 1 + substrate/frame/salary/src/tests/unit.rs | 1 + 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/substrate/frame/salary/src/benchmarking.rs b/substrate/frame/salary/src/benchmarking.rs index aeae8d2d67f8..a3fda52cd341 100644 --- a/substrate/frame/salary/src/benchmarking.rs +++ b/substrate/frame/salary/src/benchmarking.rs @@ -20,11 +20,12 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use crate::Pallet as Salary; +use crate::{Pallet as Salary, BlockNumberFor as SalaryBlockNumberFor}; use frame_benchmarking::v2::*; -use frame_system::{Pallet as System, RawOrigin}; +use frame_system::RawOrigin; use sp_core::Get; +use sp_runtime::traits::BlockNumberProvider; const SEED: u32 = 0; @@ -47,6 +48,14 @@ fn ensure_member_with_salary, I: 'static>(who: &T::AccountId) { mod benchmarks { use super::*; + fn get_block_number, I: 'static>() -> SalaryBlockNumberFor { + T::BlockNumberProvider::current_block_number() + } + + fn set_block_number, I: 'static>(n: SalaryBlockNumberFor) { + T::BlockNumberProvider::set_block_number(n); + } + #[benchmark] fn init() { let caller: T::AccountId = whitelisted_caller(); @@ -61,7 +70,7 @@ mod benchmarks { fn bump() { let caller: T::AccountId = whitelisted_caller(); Salary::::init(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + Salary::::cycle_period()); + set_block_number::(get_block_number::() + Salary::::cycle_period()); #[extrinsic_call] _(RawOrigin::Signed(caller.clone())); @@ -87,7 +96,7 @@ mod benchmarks { ensure_member_with_salary::(&caller); Salary::::init(RawOrigin::Signed(caller.clone()).into()).unwrap(); Salary::::induct(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + Salary::::cycle_period()); + set_block_number::(get_block_number::() + Salary::::cycle_period()); Salary::::bump(RawOrigin::Signed(caller.clone()).into()).unwrap(); #[extrinsic_call] @@ -102,9 +111,9 @@ mod benchmarks { ensure_member_with_salary::(&caller); Salary::::init(RawOrigin::Signed(caller.clone()).into()).unwrap(); Salary::::induct(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + Salary::::cycle_period()); + set_block_number::(get_block_number::() + Salary::::cycle_period()); Salary::::bump(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + T::RegistrationPeriod::get()); + set_block_number::(get_block_number::() + T::RegistrationPeriod::get()); let salary = T::Salary::get_salary(T::Members::rank_of(&caller).unwrap(), &caller); T::Paymaster::ensure_successful(&caller, (), salary); @@ -128,9 +137,9 @@ mod benchmarks { ensure_member_with_salary::(&caller); Salary::::init(RawOrigin::Signed(caller.clone()).into()).unwrap(); Salary::::induct(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + Salary::::cycle_period()); + set_block_number::(get_block_number::() + Salary::::cycle_period()); Salary::::bump(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + T::RegistrationPeriod::get()); + set_block_number::(get_block_number::() + T::RegistrationPeriod::get()); let salary = T::Salary::get_salary(T::Members::rank_of(&caller).unwrap(), &caller); let recipient: T::AccountId = account("recipient", 0, SEED); @@ -155,9 +164,9 @@ mod benchmarks { ensure_member_with_salary::(&caller); Salary::::init(RawOrigin::Signed(caller.clone()).into()).unwrap(); Salary::::induct(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + Salary::::cycle_period()); + set_block_number::(get_block_number::() + Salary::::cycle_period()); Salary::::bump(RawOrigin::Signed(caller.clone()).into()).unwrap(); - System::::set_block_number(System::::block_number() + T::RegistrationPeriod::get()); + set_block_number::(get_block_number::() + T::RegistrationPeriod::get()); let salary = T::Salary::get_salary(T::Members::rank_of(&caller).unwrap(), &caller); let recipient: T::AccountId = account("recipient", 0, SEED); diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index efb4f5d3c542..e03f1be07b1f 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -89,7 +89,8 @@ pub struct ClaimantStatus { pub mod pallet { use super::*; use frame_support::{dispatch::Pays, pallet_prelude::*}; - use frame_system::pallet_prelude::*; + use frame_system::pallet_prelude::{OriginFor, ensure_signed}; + use sp_runtime::traits::BlockNumberProvider; #[pallet::pallet] pub struct Pallet(PhantomData<(T, I)>); @@ -125,27 +126,34 @@ pub mod pallet { /// The number of blocks between sequential payout cycles is the sum of this and /// `PayoutPeriod`. #[pallet::constant] - type RegistrationPeriod: Get>; + type RegistrationPeriod: Get>; /// The number of blocks within a cycle which accounts have to claim the payout. /// /// The number of blocks between sequential payout cycles is the sum of this and /// `RegistrationPeriod`. #[pallet::constant] - type PayoutPeriod: Get>; + type PayoutPeriod: Get>; /// The total budget per cycle. /// /// This may change over the course of a cycle without any problem. #[pallet::constant] type Budget: Get>; + + /// Provides the current block number. + /// + /// This is usually `cumulus_pallet_parachain_system::RelaychainDataProvider` if a + /// parachain, or `frame_system::Pallet` if a solochain. + type BlockNumberProvider: BlockNumberProvider; } - pub type CycleIndexOf = BlockNumberFor; + pub type BlockNumberFor = <>::BlockNumberProvider as BlockNumberProvider>::BlockNumber; + pub type CycleIndexOf = BlockNumberFor; pub type BalanceOf = <>::Paymaster as Pay>::Balance; pub type IdOf = <>::Paymaster as Pay>::Id; - pub type StatusOf = StatusType, BlockNumberFor, BalanceOf>; - pub type ClaimantStatusOf = ClaimantStatus, BalanceOf, IdOf>; + pub type StatusOf = StatusType, BlockNumberFor, BalanceOf>; + pub type ClaimantStatusOf = ClaimantStatus, BalanceOf, IdOf>; /// The overall status of the system. #[pallet::storage] @@ -172,7 +180,7 @@ pub mod pallet { id: ::Id, }, /// The next cycle begins. - CycleStarted { index: CycleIndexOf }, + CycleStarted { index: CycleIndexOf }, /// A member swapped their account. Swapped { who: T::AccountId, new_who: T::AccountId }, } @@ -218,7 +226,7 @@ pub mod pallet { #[pallet::call_index(0)] pub fn init(origin: OriginFor) -> DispatchResultWithPostInfo { let _ = ensure_signed(origin)?; - let now = frame_system::Pallet::::block_number(); + let now = T::BlockNumberProvider::current_block_number(); ensure!(!Status::::exists(), Error::::AlreadyStarted); let status = StatusType { cycle_index: Zero::zero(), @@ -240,7 +248,7 @@ pub mod pallet { #[pallet::call_index(1)] pub fn bump(origin: OriginFor) -> DispatchResultWithPostInfo { let _ = ensure_signed(origin)?; - let now = frame_system::Pallet::::block_number(); + let now = T::BlockNumberProvider::current_block_number(); let cycle_period = Self::cycle_period(); let mut status = Status::::get().ok_or(Error::::NotStarted)?; status.cycle_start.saturating_accrue(cycle_period); @@ -286,7 +294,7 @@ pub mod pallet { let rank = T::Members::rank_of(&who).ok_or(Error::::NotMember)?; let mut status = Status::::get().ok_or(Error::::NotStarted)?; let mut claimant = Claimant::::get(&who).ok_or(Error::::NotInducted)?; - let now = frame_system::Pallet::::block_number(); + let now = T::BlockNumberProvider::current_block_number(); ensure!( now < status.cycle_start + T::RegistrationPeriod::get(), Error::::TooLate @@ -386,17 +394,17 @@ pub mod pallet { pub fn status() -> Option> { Status::::get() } - pub fn last_active(who: &T::AccountId) -> Result, DispatchError> { + pub fn last_active(who: &T::AccountId) -> Result, DispatchError> { Ok(Claimant::::get(&who).ok_or(Error::::NotInducted)?.last_active) } - pub fn cycle_period() -> BlockNumberFor { + pub fn cycle_period() -> BlockNumberFor { T::RegistrationPeriod::get() + T::PayoutPeriod::get() } fn do_payout(who: T::AccountId, beneficiary: T::AccountId) -> DispatchResult { let mut status = Status::::get().ok_or(Error::::NotStarted)?; let mut claimant = Claimant::::get(&who).ok_or(Error::::NotInducted)?; - let now = frame_system::Pallet::::block_number(); + let now = T::BlockNumberProvider::current_block_number(); ensure!( now >= status.cycle_start + T::RegistrationPeriod::get(), Error::::TooEarly, diff --git a/substrate/frame/salary/src/tests/integration.rs b/substrate/frame/salary/src/tests/integration.rs index 0c1fb8bbdcba..a25fc9d889a6 100644 --- a/substrate/frame/salary/src/tests/integration.rs +++ b/substrate/frame/salary/src/tests/integration.rs @@ -100,6 +100,7 @@ impl Config for Test { type RegistrationPeriod = ConstU64<2>; type PayoutPeriod = ConstU64<2>; type Budget = Budget; + type BlockNumberProvider = System; } pub struct FixedSalary; diff --git a/substrate/frame/salary/src/tests/unit.rs b/substrate/frame/salary/src/tests/unit.rs index db1c8b947ef5..c070885c822f 100644 --- a/substrate/frame/salary/src/tests/unit.rs +++ b/substrate/frame/salary/src/tests/unit.rs @@ -154,6 +154,7 @@ impl Config for Test { type RegistrationPeriod = ConstU64<2>; type PayoutPeriod = ConstU64<2>; type Budget = Budget; + type BlockNumberProvider = System; } pub fn new_test_ext() -> sp_io::TestExternalities { From 0e650b63fe4a7b207f6b7834bd7f0a8945469e4a Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 11:08:03 -0500 Subject: [PATCH 02/31] Salary v0 to v1 migration --- substrate/frame/salary/src/lib.rs | 11 +- substrate/frame/salary/src/migration.rs | 152 ++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 substrate/frame/salary/src/migration.rs diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index e03f1be07b1f..1121c4f26869 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -41,6 +41,7 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; pub mod weights; +pub mod migration; pub use pallet::*; pub use weights::WeightInfo; @@ -52,15 +53,15 @@ pub type Cycle = u32; #[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)] pub struct StatusType { /// The index of the "current cycle" (i.e. the last cycle being processed). - cycle_index: CycleIndex, + pub cycle_index: CycleIndex, /// The first block of the "current cycle" (i.e. the last cycle being processed). - cycle_start: BlockNumber, + pub cycle_start: BlockNumber, /// The total budget available for all payments in the current cycle. - budget: Balance, + pub budget: Balance, /// The total amount of the payments registered in the current cycle. - total_registrations: Balance, + pub total_registrations: Balance, /// The total amount of unregistered payments which have been made in the current cycle. - total_unregistered_paid: Balance, + pub total_unregistered_paid: Balance, } /// The state of a specific payment claim. diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs new file mode 100644 index 000000000000..57750960fcf1 --- /dev/null +++ b/substrate/frame/salary/src/migration.rs @@ -0,0 +1,152 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Storage migrations for the salary pallet. + +use super::*; +use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; + +// #[cfg(feature = "try-runtime")] +// use alloc::vec::Vec; +#[cfg(feature = "try-runtime")] +use sp_runtime::TryRuntimeError; + +mod v0 { + use super::*; + use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; + + // V0 types. + pub type CycleIndexOf = LocalBlockNumberFor; + pub type StatusOf = StatusType, LocalBlockNumberFor, BalanceOf>; + pub type ClaimantStatusOf = ClaimantStatus, BalanceOf, IdOf>; + + /// V0 alias for [`crate::Status`]. + #[storage_alias] + pub type Status, I: 'static> = + StorageValue, StatusOf, OptionQuery>; + + /// V0 alias for [`crate::Claimant`]. + #[storage_alias] + pub type Claimant, I: 'static> = StorageMap< + Pallet, + Twox64Concat, + ::AccountId, + ClaimantStatusOf, + OptionQuery, + >; +} + +mod v1 { + use super::{BlockNumberFor as NewBlockNumberFor, *}; + use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; + + /// Converts previous (local) block number into the new one. May just be identity functions + /// if sticking with local block number as the provider. + pub trait ConvertBlockNumber { + /// Simply converts the type from L to N + fn convert(local: L) -> N; + + /// Converts to the new type and finds the equivalent moment in time as relative to the new + /// block provider + /// + /// For instance - if your new version uses the relay chain number, you'll want to + /// use relay current - ((current local - local) * equivalent_block_duration) + fn equivalent_moment_in_time(local: L) -> N; + + /// Returns the equivalent time duration as the previous type when represented as the new + /// type + /// + /// For instance - If you previously had 12s blocks and are now following the relay chain's + /// 6, one local block is equivalent to 2 relay blocks in duration + fn equivalent_block_duration(local: L) -> N; + } + + pub struct MigrateToV1(PhantomData<(T, BC, I)>); + impl, BC, I: 'static> UncheckedOnRuntimeUpgrade for MigrateToV1 + where + BC: ConvertBlockNumber, NewBlockNumberFor>, + { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, TryRuntimeError> { + if let Some(old_status) = v0::Status::::take() { + log::info!("\n Old status - {:?}\n", old_status); + } + + let _ = v0::Claimant::::iter().for_each(|(key, value)| { + log::info!("\n Old claimant - {:?} -> {:?}\n", key, value); + }); + + Ok(Default::default()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut transactions = 0; + + // Status storage option + if let Some(old_status) = v0::Status::::take() { + let new_status = crate::StatusOf:: { + cycle_index: BC::convert(old_status.cycle_index), + cycle_start: BC::equivalent_moment_in_time(old_status.cycle_start), + budget: old_status.budget, + total_registrations: old_status.total_registrations, + total_unregistered_paid: old_status.total_unregistered_paid, + }; + crate::Status::::put(new_status); + transactions.saturating_inc(); + } + + // Claimant map + crate::Claimant::::translate::, _>( + |_, old_claimant| { + transactions.saturating_inc(); + Some(crate::ClaimantStatusOf:: { + last_active: BC::convert(old_claimant.last_active), + status: old_claimant.status, + }) + }, + ); + + T::DbWeight::get().reads_writes(transactions, transactions) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), TryRuntimeError> { + if let Some(new_status) = crate::Status::::get() { + log::info!("\n New status - {:?}\n", new_status); + } + + let _ = crate::Claimant::::iter().for_each(|(key, value)| { + log::info!("\n New claimant - {:?} -> {:?}\n", key, value); + }); + + Ok(()) + } + } +} + +/// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`] wrapped in a +/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: +/// - The migration only runs once when the on-chain storage version is 0 +/// - The on-chain storage version is updated to `1` after the migration executes +/// - Reads/Writes from checking/settings the on-chain storage version are accounted for +pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< + 0, // The migration will only execute when the on-chain storage version is 0 + 1, // The on-chain storage version will be set to 1 after the migration is complete + v1::MigrateToV1, + crate::pallet::Pallet, + ::DbWeight, +>; From 4359f230ee1fe7dc6143ac0ffd884c904314aa8f Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 11:08:50 -0500 Subject: [PATCH 03/31] Set block provider to system for now --- .../collectives-westend/src/ambassador/mod.rs | 1 + .../collectives-westend/src/fellowship/mod.rs | 4 +- .../collectives-westend/src/lib.rs | 44 +++++++++++++++++++ substrate/bin/node/runtime/src/lib.rs | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs index a052a9d3800c..3a5a237aac18 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -270,4 +270,5 @@ impl pallet_salary::Config for Runtime { type PayoutPeriod = ConstU32<{ 15 * DAYS }>; // Total monthly salary budget. type Budget = ConstU128<{ 10_000 * DOLLARS }>; + type BlockNumberProvider = System; } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs index 1e8212cf6ac2..0302ee3dc7e1 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs @@ -23,7 +23,7 @@ use crate::{ xcm_config::{FellowshipAdminBodyId, LocationToAccountId, TreasurerBodyId, UsdtAssetHub}, AccountId, AssetRate, Balance, Balances, FellowshipReferenda, GovernanceLocation, ParachainInfo, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, - WestendTreasuryAccount, DAYS, + WestendTreasuryAccount, DAYS, System, }; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -257,6 +257,8 @@ impl pallet_salary::Config for Runtime { type PayoutPeriod = ConstU32<{ 15 * DAYS }>; // Total monthly salary budget. type Budget = ConstU128<{ 100_000 * USDT_UNITS }>; + + type BlockNumberProvider = System; } parameter_types! { diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 5c2ba2e24c22..a3604471b483 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -762,8 +762,52 @@ type Migrations = ( pallet_core_fellowship::migration::MigrateV0ToV1, // unreleased pallet_core_fellowship::migration::MigrateV0ToV1, + // unreleased + pallet_salary::migration::MigrateV0ToV1, + pallet_salary::migration::MigrateV0ToV1, ); +// Helpers for the salary pallet v0->v1 storage migration. +use sp_runtime::traits::BlockNumberProvider; +type SalaryLocalBlockNumber = ::BlockNumber; +type SalaryNewBlockNumber = ::BlockNumber;// as BlockNumberProvider>::BlockNumber; +pub struct SalaryBlockNumberConverter; +impl + pallet_salary::migration::v1::ConvertBlockNumber< + SalaryLocalBlockNumber, + SalaryNewBlockNumber, + > for SalaryBlockNumberConverter +{ + /// Simply convert the types. Cycle index storage item uses block number but is agnostic to the + /// time that denotes for instance + fn convert(local: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { + local + } + + /// The equivalent moment in time from the perspective of the relay chain, starting from a + /// local moment in time (system block number) + fn equivalent_moment_in_time( + local: SalaryLocalBlockNumber, + ) -> SalaryNewBlockNumber { + let block_number = System::block_number(); + let local_duration = block_number.saturating_sub(local); + let relay_duration = Self::equivalent_block_duration(local_duration); //6s to 6s + let relay_block_number = ParachainSystem::last_relay_block_number(); + relay_block_number.saturating_sub(relay_duration) + } + + /// The equivalent duration from the perspective of the relay chain, starting from + /// a local duration (number of block). Identity function for Westend, since both + /// relay and collectives chain run 6s block times + fn equivalent_block_duration( + local: SalaryLocalBlockNumber, + ) -> SalaryNewBlockNumber { + local + } +} + /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index faffcd23fbcf..147dde3d1380 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1976,6 +1976,7 @@ impl pallet_salary::Config for Runtime { type RegistrationPeriod = ConstU32<200>; type PayoutPeriod = ConstU32<200>; type Budget = Budget; + type BlockNumberProvider = System; } impl pallet_core_fellowship::Config for Runtime { From 7752f6cf4c14682380e59da0acaf6c0e024e0ec6 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 11:39:49 -0500 Subject: [PATCH 04/31] Set to block number provider to relay chain --- .../collectives/collectives-westend/src/ambassador/mod.rs | 2 +- .../collectives/collectives-westend/src/fellowship/mod.rs | 4 ++-- .../runtimes/collectives/collectives-westend/src/lib.rs | 5 ++--- substrate/frame/salary/src/migration.rs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs index 3a5a237aac18..b5d90ff23c35 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -270,5 +270,5 @@ impl pallet_salary::Config for Runtime { type PayoutPeriod = ConstU32<{ 15 * DAYS }>; // Total monthly salary budget. type Budget = ConstU128<{ 10_000 * DOLLARS }>; - type BlockNumberProvider = System; + type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs index 0302ee3dc7e1..8fc31159d6ec 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs @@ -23,7 +23,7 @@ use crate::{ xcm_config::{FellowshipAdminBodyId, LocationToAccountId, TreasurerBodyId, UsdtAssetHub}, AccountId, AssetRate, Balance, Balances, FellowshipReferenda, GovernanceLocation, ParachainInfo, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, - WestendTreasuryAccount, DAYS, System, + WestendTreasuryAccount, DAYS, }; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -258,7 +258,7 @@ impl pallet_salary::Config for Runtime { // Total monthly salary budget. type Budget = ConstU128<{ 100_000 * USDT_UNITS }>; - type BlockNumberProvider = System; + type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; } parameter_types! { diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index a3604471b483..83c5af21e14a 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -770,9 +770,8 @@ type Migrations = ( // Helpers for the salary pallet v0->v1 storage migration. use sp_runtime::traits::BlockNumberProvider; type SalaryLocalBlockNumber = ::BlockNumber; -type SalaryNewBlockNumber = ::BlockNumber;// as BlockNumberProvider>::BlockNumber; +type SalaryNewBlockNumber = + as BlockNumberProvider>::BlockNumber; pub struct SalaryBlockNumberConverter; impl pallet_salary::migration::v1::ConvertBlockNumber< diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 57750960fcf1..5bece151df5d 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -50,7 +50,7 @@ mod v0 { >; } -mod v1 { +pub mod v1 { use super::{BlockNumberFor as NewBlockNumberFor, *}; use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; From 52790c57e7fb8340d5b2b9646a2ed7b9d92a8dbd Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 16:32:44 -0500 Subject: [PATCH 05/31] Fix storage version issue --- substrate/frame/salary/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index 1121c4f26869..31d28cf2260b 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -92,8 +92,12 @@ pub mod pallet { use frame_support::{dispatch::Pays, pallet_prelude::*}; use frame_system::pallet_prelude::{OriginFor, ensure_signed}; use sp_runtime::traits::BlockNumberProvider; + + /// The in-code storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] From cb119b0356cfafe61387a047e72da08003c36eb0 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 16:33:27 -0500 Subject: [PATCH 06/31] Add migrations --- .../runtimes/collectives/collectives-westend/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 83c5af21e14a..9803cec98ee8 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -49,9 +49,9 @@ extern crate alloc; pub use ambassador::pallet_ambassador_origins; use alloc::{vec, vec::Vec}; -use ambassador::AmbassadorCoreInstance; +use ambassador::{AmbassadorCoreInstance, AmbassadorSalaryInstance}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use fellowship::{pallet_fellowship_origins, Fellows, FellowshipCoreInstance}; +use fellowship::{pallet_fellowship_origins, Fellows, FellowshipCoreInstance, FellowshipSalaryInstance}; use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -763,8 +763,8 @@ type Migrations = ( // unreleased pallet_core_fellowship::migration::MigrateV0ToV1, // unreleased - pallet_salary::migration::MigrateV0ToV1, - pallet_salary::migration::MigrateV0ToV1, + pallet_salary::migration::MigrateV0ToV1, + pallet_salary::migration::MigrateV0ToV1, ); // Helpers for the salary pallet v0->v1 storage migration. From bdd0727316c7267d7f356d20320e47befda2d71d Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 16:33:52 -0500 Subject: [PATCH 07/31] Remove unused import --- substrate/frame/salary/src/migration.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 5bece151df5d..85adf2ed30d4 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -20,8 +20,6 @@ use super::*; use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; -// #[cfg(feature = "try-runtime")] -// use alloc::vec::Vec; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; From 77741b30d690167902a345c4a60d2c72ba95b1d9 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 16:35:22 -0500 Subject: [PATCH 08/31] fmt --- .../collectives-westend/src/lib.rs | 33 ++++++++++--------- substrate/frame/salary/src/benchmarking.rs | 2 +- substrate/frame/salary/src/lib.rs | 12 ++++--- substrate/frame/salary/src/migration.rs | 4 +-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 9803cec98ee8..698f17d05038 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -51,7 +51,9 @@ pub use ambassador::pallet_ambassador_origins; use alloc::{vec, vec::Vec}; use ambassador::{AmbassadorCoreInstance, AmbassadorSalaryInstance}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use fellowship::{pallet_fellowship_origins, Fellows, FellowshipCoreInstance, FellowshipSalaryInstance}; +use fellowship::{ + pallet_fellowship_origins, Fellows, FellowshipCoreInstance, FellowshipSalaryInstance, +}; use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -763,21 +765,26 @@ type Migrations = ( // unreleased pallet_core_fellowship::migration::MigrateV0ToV1, // unreleased - pallet_salary::migration::MigrateV0ToV1, - pallet_salary::migration::MigrateV0ToV1, + pallet_salary::migration::MigrateV0ToV1< + Runtime, + SalaryBlockNumberConverter, + FellowshipSalaryInstance, + >, + pallet_salary::migration::MigrateV0ToV1< + Runtime, + SalaryBlockNumberConverter, + AmbassadorSalaryInstance, + >, ); // Helpers for the salary pallet v0->v1 storage migration. use sp_runtime::traits::BlockNumberProvider; type SalaryLocalBlockNumber = ::BlockNumber; -type SalaryNewBlockNumber = +type SalaryNewBlockNumber = as BlockNumberProvider>::BlockNumber; pub struct SalaryBlockNumberConverter; -impl - pallet_salary::migration::v1::ConvertBlockNumber< - SalaryLocalBlockNumber, - SalaryNewBlockNumber, - > for SalaryBlockNumberConverter +impl pallet_salary::migration::v1::ConvertBlockNumber + for SalaryBlockNumberConverter { /// Simply convert the types. Cycle index storage item uses block number but is agnostic to the /// time that denotes for instance @@ -787,9 +794,7 @@ impl /// The equivalent moment in time from the perspective of the relay chain, starting from a /// local moment in time (system block number) - fn equivalent_moment_in_time( - local: SalaryLocalBlockNumber, - ) -> SalaryNewBlockNumber { + fn equivalent_moment_in_time(local: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { let block_number = System::block_number(); let local_duration = block_number.saturating_sub(local); let relay_duration = Self::equivalent_block_duration(local_duration); //6s to 6s @@ -800,9 +805,7 @@ impl /// The equivalent duration from the perspective of the relay chain, starting from /// a local duration (number of block). Identity function for Westend, since both /// relay and collectives chain run 6s block times - fn equivalent_block_duration( - local: SalaryLocalBlockNumber, - ) -> SalaryNewBlockNumber { + fn equivalent_block_duration(local: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { local } } diff --git a/substrate/frame/salary/src/benchmarking.rs b/substrate/frame/salary/src/benchmarking.rs index a3fda52cd341..f5562616e063 100644 --- a/substrate/frame/salary/src/benchmarking.rs +++ b/substrate/frame/salary/src/benchmarking.rs @@ -20,7 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use crate::{Pallet as Salary, BlockNumberFor as SalaryBlockNumberFor}; +use crate::{BlockNumberFor as SalaryBlockNumberFor, Pallet as Salary}; use frame_benchmarking::v2::*; use frame_system::RawOrigin; diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index 31d28cf2260b..a629dfb8e74c 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -40,8 +40,8 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; -pub mod weights; pub mod migration; +pub mod weights; pub use pallet::*; pub use weights::WeightInfo; @@ -90,9 +90,9 @@ pub struct ClaimantStatus { pub mod pallet { use super::*; use frame_support::{dispatch::Pays, pallet_prelude::*}; - use frame_system::pallet_prelude::{OriginFor, ensure_signed}; + use frame_system::pallet_prelude::{ensure_signed, OriginFor}; use sp_runtime::traits::BlockNumberProvider; - + /// The in-code storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); @@ -153,12 +153,14 @@ pub mod pallet { type BlockNumberProvider: BlockNumberProvider; } - pub type BlockNumberFor = <>::BlockNumberProvider as BlockNumberProvider>::BlockNumber; + pub type BlockNumberFor = + <>::BlockNumberProvider as BlockNumberProvider>::BlockNumber; pub type CycleIndexOf = BlockNumberFor; pub type BalanceOf = <>::Paymaster as Pay>::Balance; pub type IdOf = <>::Paymaster as Pay>::Id; pub type StatusOf = StatusType, BlockNumberFor, BalanceOf>; - pub type ClaimantStatusOf = ClaimantStatus, BalanceOf, IdOf>; + pub type ClaimantStatusOf = + ClaimantStatus, BalanceOf, IdOf>; /// The overall status of the system. #[pallet::storage] diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 85adf2ed30d4..a157896176dc 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -65,7 +65,7 @@ pub mod v1 { /// use relay current - ((current local - local) * equivalent_block_duration) fn equivalent_moment_in_time(local: L) -> N; - /// Returns the equivalent time duration as the previous type when represented as the new + /// Returns the equivalent time duration as the previous type when represented as the new /// type /// /// For instance - If you previously had 12s blocks and are now following the relay chain's @@ -118,7 +118,7 @@ pub mod v1 { }, ); - T::DbWeight::get().reads_writes(transactions, transactions) + T::DbWeight::get().reads_writes(transactions, transactions) } #[cfg(feature = "try-runtime")] From a31302c4d551e377bc9d811adfb72da935cc67f8 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 19:08:22 -0500 Subject: [PATCH 09/31] Add alloc crate back in --- substrate/frame/salary/src/lib.rs | 2 ++ substrate/frame/salary/src/migration.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index a629dfb8e74c..441734a257a0 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -19,6 +19,8 @@ #![cfg_attr(not(feature = "std"), no_std)] +extern crate alloc; + use codec::{Decode, Encode, MaxEncodedLen}; use core::marker::PhantomData; use scale_info::TypeInfo; diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index a157896176dc..1ff7c8f934c8 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -20,6 +20,8 @@ use super::*; use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; +#[cfg(feature = "try-runtime")] +use alloc::vec::Vec; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; From a07180353e506c93698744af770d3a250667ec7e Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 19:56:29 -0500 Subject: [PATCH 10/31] Fix noop issue --- substrate/frame/salary/src/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 1ff7c8f934c8..a27cecd869b4 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -82,7 +82,7 @@ pub mod v1 { { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, TryRuntimeError> { - if let Some(old_status) = v0::Status::::take() { + if let Some(old_status) = v0::Status::::get() { log::info!("\n Old status - {:?}\n", old_status); } From 47e7079ca6de83f0ad581f126c108bd4352d04a9 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 23 Dec 2024 19:56:41 -0500 Subject: [PATCH 11/31] Update spec version --- .../runtimes/collectives/collectives-westend/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 698f17d05038..430f07c006a4 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -128,7 +128,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: alloc::borrow::Cow::Borrowed("collectives-westend"), impl_name: alloc::borrow::Cow::Borrowed("collectives-westend"), authoring_version: 1, - spec_version: 1_017_001, + spec_version: 1_018_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 6, From 331469ee79f21750dc068bcc54c5a442bc1c066f Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 25 Dec 2024 11:21:15 -0500 Subject: [PATCH 12/31] Add space --- .../collectives/collectives-westend/src/ambassador/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs index b5d90ff23c35..e8e7de6050b2 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -270,5 +270,6 @@ impl pallet_salary::Config for Runtime { type PayoutPeriod = ConstU32<{ 15 * DAYS }>; // Total monthly salary budget. type Budget = ConstU128<{ 10_000 * DOLLARS }>; + type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; } From 5cea0ca8be94fa888addfba1ae99019168acb500 Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 25 Dec 2024 11:23:46 -0500 Subject: [PATCH 13/31] Remove testing functions --- substrate/frame/salary/src/migration.rs | 26 ------------------------- 1 file changed, 26 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index a27cecd869b4..a897e874b3b1 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -80,19 +80,6 @@ pub mod v1 { where BC: ConvertBlockNumber, NewBlockNumberFor>, { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { - if let Some(old_status) = v0::Status::::get() { - log::info!("\n Old status - {:?}\n", old_status); - } - - let _ = v0::Claimant::::iter().for_each(|(key, value)| { - log::info!("\n Old claimant - {:?} -> {:?}\n", key, value); - }); - - Ok(Default::default()) - } - fn on_runtime_upgrade() -> frame_support::weights::Weight { let mut transactions = 0; @@ -122,19 +109,6 @@ pub mod v1 { T::DbWeight::get().reads_writes(transactions, transactions) } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), TryRuntimeError> { - if let Some(new_status) = crate::Status::::get() { - log::info!("\n New status - {:?}\n", new_status); - } - - let _ = crate::Claimant::::iter().for_each(|(key, value)| { - log::info!("\n New claimant - {:?} -> {:?}\n", key, value); - }); - - Ok(()) - } } } From 30cc9912880cbbe65490feeca31fe1969a5903b1 Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 25 Dec 2024 11:24:32 -0500 Subject: [PATCH 14/31] Remove unused imports --- substrate/frame/salary/src/migration.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index a897e874b3b1..fcbae54be8ff 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -20,11 +20,6 @@ use super::*; use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; -#[cfg(feature = "try-runtime")] -use alloc::vec::Vec; -#[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; - mod v0 { use super::*; use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; From 25053cc1a28430a75d1e01bc413832a247309548 Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 25 Dec 2024 11:48:04 -0500 Subject: [PATCH 15/31] Update prdoc and cargo tomls --- Cargo.lock | 12 ++++++------ .../collectives/collectives-westend/Cargo.toml | 2 +- prdoc/pr_7000.prdoc | 15 +++++++++++++++ substrate/bin/node/runtime/Cargo.toml | 2 +- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/salary/Cargo.toml | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 prdoc/pr_7000.prdoc diff --git a/Cargo.lock b/Cargo.lock index 6151ed33c5b6..67b149e43e2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3640,7 +3640,7 @@ dependencies = [ [[package]] name = "collectives-westend-runtime" -version = "3.0.0" +version = "3.1.0" dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", @@ -3675,7 +3675,7 @@ dependencies = [ "pallet-proxy 28.0.0", "pallet-ranked-collective 28.0.0", "pallet-referenda 28.0.0", - "pallet-salary 13.0.0", + "pallet-salary 14.0.0", "pallet-scheduler 29.0.0", "pallet-session 28.0.0", "pallet-state-trie-migration 29.0.0", @@ -9507,7 +9507,7 @@ checksum = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" [[package]] name = "kitchensink-runtime" -version = "3.0.0-dev" +version = "3.0.1-dev" dependencies = [ "log", "node-primitives", @@ -15168,7 +15168,7 @@ dependencies = [ [[package]] name = "pallet-salary" -version = "13.0.0" +version = "14.0.0" dependencies = [ "frame-benchmarking 28.0.0", "frame-support 28.0.0", @@ -18765,7 +18765,7 @@ dependencies = [ "pallet-root-offences 25.0.0", "pallet-root-testing 4.0.0", "pallet-safe-mode 9.0.0", - "pallet-salary 13.0.0", + "pallet-salary 14.0.0", "pallet-scheduler 29.0.0", "pallet-scored-pool 28.0.0", "pallet-session 28.0.0", @@ -28180,7 +28180,7 @@ dependencies = [ "pallet-asset-conversion 10.0.0", "pallet-assets 29.1.0", "pallet-balances 28.0.0", - "pallet-salary 13.0.0", + "pallet-salary 14.0.0", "pallet-transaction-payment 28.0.0", "pallet-xcm 7.0.0", "parity-scale-codec", diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index 9c70b65060dd..ec5948263aed 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "collectives-westend-runtime" -version = "3.0.0" +version = "3.1.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" diff --git a/prdoc/pr_7000.prdoc b/prdoc/pr_7000.prdoc new file mode 100644 index 000000000000..99fc5e466c1c --- /dev/null +++ b/prdoc/pr_7000.prdoc @@ -0,0 +1,15 @@ +title: 'Adds BlockNumberProvider to pallet-core-fellowship' +doc: +- audience: Runtime Dev + description: |- + This PR adds a parameter 'BlockNumberProvider' to the pallet-salary + config such that a block provider can be set for use in the pallet. This would + usually be the frame system pallet or the appropriate relay chain. Previously + it defaulted to the frame system pallet. +crates: +- name: pallet-salary + bump: major +- name: collectives-westend-runtime + bump: minor +- name: kitchensink-runtime + bump: patch diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 6d377cc92cce..37464e84b6f8 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kitchensink-runtime" -version = "3.0.0-dev" +version = "3.0.1-dev" authors.workspace = true description = "Substrate node kitchensink runtime." edition.workspace = true diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 147dde3d1380..80e59242625a 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -177,7 +177,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 268, - impl_version: 0, + impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 2, system_version: 1, diff --git a/substrate/frame/salary/Cargo.toml b/substrate/frame/salary/Cargo.toml index b3ed95bf1de5..a21bfe206c34 100644 --- a/substrate/frame/salary/Cargo.toml +++ b/substrate/frame/salary/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-salary" -version = "13.0.0" +version = "14.0.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" From e53d8b9488cba204a6d54454e9e8695ef3433b84 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 6 Jan 2025 17:16:29 -0500 Subject: [PATCH 16/31] Cargo reversions, one doc --- Cargo.lock | 12 ++++++------ .../collectives/collectives-westend/Cargo.toml | 2 +- .../collectives/collectives-westend/src/lib.rs | 2 +- substrate/bin/node/runtime/Cargo.toml | 2 +- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/salary/Cargo.toml | 2 +- substrate/frame/salary/src/lib.rs | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67b149e43e2f..6151ed33c5b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3640,7 +3640,7 @@ dependencies = [ [[package]] name = "collectives-westend-runtime" -version = "3.1.0" +version = "3.0.0" dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", @@ -3675,7 +3675,7 @@ dependencies = [ "pallet-proxy 28.0.0", "pallet-ranked-collective 28.0.0", "pallet-referenda 28.0.0", - "pallet-salary 14.0.0", + "pallet-salary 13.0.0", "pallet-scheduler 29.0.0", "pallet-session 28.0.0", "pallet-state-trie-migration 29.0.0", @@ -9507,7 +9507,7 @@ checksum = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" [[package]] name = "kitchensink-runtime" -version = "3.0.1-dev" +version = "3.0.0-dev" dependencies = [ "log", "node-primitives", @@ -15168,7 +15168,7 @@ dependencies = [ [[package]] name = "pallet-salary" -version = "14.0.0" +version = "13.0.0" dependencies = [ "frame-benchmarking 28.0.0", "frame-support 28.0.0", @@ -18765,7 +18765,7 @@ dependencies = [ "pallet-root-offences 25.0.0", "pallet-root-testing 4.0.0", "pallet-safe-mode 9.0.0", - "pallet-salary 14.0.0", + "pallet-salary 13.0.0", "pallet-scheduler 29.0.0", "pallet-scored-pool 28.0.0", "pallet-session 28.0.0", @@ -28180,7 +28180,7 @@ dependencies = [ "pallet-asset-conversion 10.0.0", "pallet-assets 29.1.0", "pallet-balances 28.0.0", - "pallet-salary 14.0.0", + "pallet-salary 13.0.0", "pallet-transaction-payment 28.0.0", "pallet-xcm 7.0.0", "parity-scale-codec", diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index ec5948263aed..9c70b65060dd 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "collectives-westend-runtime" -version = "3.1.0" +version = "3.0.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 430f07c006a4..698f17d05038 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -128,7 +128,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: alloc::borrow::Cow::Borrowed("collectives-westend"), impl_name: alloc::borrow::Cow::Borrowed("collectives-westend"), authoring_version: 1, - spec_version: 1_018_000, + spec_version: 1_017_001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 6, diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 37464e84b6f8..6d377cc92cce 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kitchensink-runtime" -version = "3.0.1-dev" +version = "3.0.0-dev" authors.workspace = true description = "Substrate node kitchensink runtime." edition.workspace = true diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 80e59242625a..147dde3d1380 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -177,7 +177,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 268, - impl_version: 1, + impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, system_version: 1, diff --git a/substrate/frame/salary/Cargo.toml b/substrate/frame/salary/Cargo.toml index a21bfe206c34..b3ed95bf1de5 100644 --- a/substrate/frame/salary/Cargo.toml +++ b/substrate/frame/salary/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-salary" -version = "14.0.0" +version = "13.0.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" diff --git a/substrate/frame/salary/src/lib.rs b/substrate/frame/salary/src/lib.rs index 441734a257a0..064c79e6868f 100644 --- a/substrate/frame/salary/src/lib.rs +++ b/substrate/frame/salary/src/lib.rs @@ -151,7 +151,7 @@ pub mod pallet { /// Provides the current block number. /// /// This is usually `cumulus_pallet_parachain_system::RelaychainDataProvider` if a - /// parachain, or `frame_system::Pallet` if a solochain. + /// parachain, or `frame_system::Pallet` if a solo- or relaychain. type BlockNumberProvider: BlockNumberProvider; } From 0de99761bb3053b202e84fdab48deb54ee81bd0c Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 6 Jan 2025 17:28:37 -0500 Subject: [PATCH 17/31] Add to docs for migration block converter --- substrate/frame/salary/src/migration.rs | 64 +++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index fcbae54be8ff..dcb7593558df 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -53,20 +53,76 @@ pub mod v1 { /// if sticking with local block number as the provider. pub trait ConvertBlockNumber { /// Simply converts the type from L to N + /// + /// # Example Usage + /// + /// ```rust,ignore + /// // Let's say both L and N are u32, then a simple identity will suffice. + /// fn convert(local: u32) -> u32 { + /// local + /// } + /// + /// // But if L is u64 and N is u32, or some other problematic variation, + /// // you may need to do some checks. + /// fn convert(local: u64) -> u32 { + /// let new = u32::try_from(local); + /// match new { + /// Ok(v) => v, + /// Err(_) => u32::MAX // Or likely some custom logic. + /// } + /// } + /// ``` fn convert(local: L) -> N; /// Converts to the new type and finds the equivalent moment in time as relative to the new /// block provider /// /// For instance - if your new version uses the relay chain number, you'll want to - /// use relay current - ((current local - local) * equivalent_block_duration) + /// use relay current - ((current local - local) * equivalent_block_duration). + /// Note: This assumes consistent block times on both local chain and relay. + /// + /// # Example usage + /// + /// ```rust,ignore + /// // Let's say you are a parachain and switching block providers to the relay chain. + /// // This will return what the relay block number was at the moment the previous provider's + /// // number was `local`. + /// fn equivalent_moment_in_time(local: u32) -> u32 { + /// // How long it's been since 'local'. + /// let curr_block_number = System::block_number(); + /// let local_duration = curr_block_number.saturating_sub(local); + /// // How many blocks that is in relay block time. + /// let relay_duration = Self::equivalent_block_duration(local_duration); + /// // What the relay block number must have been at that moment. + /// let relay_block_number = ParachainSystem::last_relay_block_number(); + /// relay_block_number.saturating_sub(relay_duration) + /// } + /// ``` fn equivalent_moment_in_time(local: L) -> N; - /// Returns the equivalent time duration as the previous type when represented as the new - /// type + /// Returns the equivalent number of new blocks it would take to fulfill the same + /// amount of time in seconds as the old blocks. /// /// For instance - If you previously had 12s blocks and are now following the relay chain's - /// 6, one local block is equivalent to 2 relay blocks in duration + /// 6, one local block is equivalent to 2 relay blocks in duration. + /// + /// 6s 6s + /// |---------||---------| + /// + /// 12s + /// |--------------------| + /// + /// ^ Two 6s blocks passed per one 12s block. + /// + /// # Example Usage + /// + /// ```rust,ignore + /// // If your previous provider updated the block number every 12 seconds and + /// // your new updates every 6 - 2 new blocks would have taken place per one old block. + /// fn equivalent_block_duration(local: u32) -> u32 { + /// local * 2 + /// } + /// ``` fn equivalent_block_duration(local: L) -> N; } From b208d527079bb278a06ca5d45796aab98f4b61b0 Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 7 Jan 2025 08:56:02 -0500 Subject: [PATCH 18/31] Update migration.rs --- substrate/frame/salary/src/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index dcb7593558df..78c611a9a0b9 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -69,7 +69,7 @@ pub mod v1 { /// match new { /// Ok(v) => v, /// Err(_) => u32::MAX // Or likely some custom logic. - /// } + /// } /// } /// ``` fn convert(local: L) -> N; From 606812ba0de724024c9655e340cff514d58b569f Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 7 Jan 2025 09:57:21 -0500 Subject: [PATCH 19/31] Some more doc and naming updates, migration checks WIP --- .../collectives-westend/src/lib.rs | 8 ++-- substrate/frame/salary/src/migration.rs | 47 +++++++++++++------ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 698f17d05038..83529f289548 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -794,9 +794,9 @@ impl pallet_salary::migration::v1::ConvertBlockNumber SalaryNewBlockNumber { + fn equivalent_moment_in_time(local_moment: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { let block_number = System::block_number(); - let local_duration = block_number.saturating_sub(local); + let local_duration = block_number.saturating_sub(local_moment); let relay_duration = Self::equivalent_block_duration(local_duration); //6s to 6s let relay_block_number = ParachainSystem::last_relay_block_number(); relay_block_number.saturating_sub(relay_duration) @@ -805,8 +805,8 @@ impl pallet_salary::migration::v1::ConvertBlockNumber SalaryNewBlockNumber { - local + fn equivalent_block_duration(local_duration: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { + local_duration } } diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 78c611a9a0b9..8d62b660aca3 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -59,7 +59,7 @@ pub mod v1 { /// ```rust,ignore /// // Let's say both L and N are u32, then a simple identity will suffice. /// fn convert(local: u32) -> u32 { - /// local + /// local /// } /// /// // But if L is u64 and N is u32, or some other problematic variation, @@ -74,7 +74,7 @@ pub mod v1 { /// ``` fn convert(local: L) -> N; - /// Converts to the new type and finds the equivalent moment in time as relative to the new + /// Converts to the new type and finds the equivalent moment in time as from the view of the new /// block provider /// /// For instance - if your new version uses the relay chain number, you'll want to @@ -86,19 +86,19 @@ pub mod v1 { /// ```rust,ignore /// // Let's say you are a parachain and switching block providers to the relay chain. /// // This will return what the relay block number was at the moment the previous provider's - /// // number was `local`. - /// fn equivalent_moment_in_time(local: u32) -> u32 { - /// // How long it's been since 'local'. + /// // number was `local_moment`. + /// fn equivalent_moment_in_time(local_moment: u32) -> u32 { + /// // How long it's been since 'local_moment' from the parachains pov. /// let curr_block_number = System::block_number(); - /// let local_duration = curr_block_number.saturating_sub(local); - /// // How many blocks that is in relay block time. + /// let local_duration = curr_block_number.saturating_sub(local_moment); + /// // How many blocks that is from the relay's pov. /// let relay_duration = Self::equivalent_block_duration(local_duration); - /// // What the relay block number must have been at that moment. + /// // What the relay block number must have been at 'local_moment'. /// let relay_block_number = ParachainSystem::last_relay_block_number(); /// relay_block_number.saturating_sub(relay_duration) /// } /// ``` - fn equivalent_moment_in_time(local: L) -> N; + fn equivalent_moment_in_time(local_moment: L) -> N; /// Returns the equivalent number of new blocks it would take to fulfill the same /// amount of time in seconds as the old blocks. @@ -112,18 +112,17 @@ pub mod v1 { /// 12s /// |--------------------| /// - /// ^ Two 6s blocks passed per one 12s block. + /// ^ Two 6s relay blocks passed per one 12s local block. /// /// # Example Usage /// /// ```rust,ignore - /// // If your previous provider updated the block number every 12 seconds and - /// // your new updates every 6 - 2 new blocks would have taken place per one old block. - /// fn equivalent_block_duration(local: u32) -> u32 { - /// local * 2 + /// // Following the scenerio above. + /// fn equivalent_block_duration(local_duration: u32) -> u32 { + /// local_duration.saturating_mul(2) /// } /// ``` - fn equivalent_block_duration(local: L) -> N; + fn equivalent_block_duration(local_duration: L) -> N; } pub struct MigrateToV1(PhantomData<(T, BC, I)>); @@ -131,6 +130,13 @@ pub mod v1 { where BC: ConvertBlockNumber, NewBlockNumberFor>, { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, TryRuntimeError> { + let status_exists = v0::Status::::exists(); + let claimant_count = v0::Claimant::::iter().count(); + Ok((status_exists, claimant_count).encode()) + } + fn on_runtime_upgrade() -> frame_support::weights::Weight { let mut transactions = 0; @@ -160,6 +166,17 @@ pub mod v1 { T::DbWeight::get().reads_writes(transactions, transactions) } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), TryRuntimeError> { + let (status_existed, pre_claimaint_count) : (v0::StatusOf, v0::ClaimantStatusOf) = + Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); + + ensure!(crate::Status::::exists() == status_existed, "The Status' storage existence should remain the same before and after the upgrade."); + ensure!(crate::Claimant::::iter().count() == pre_claimaint_count, "The Claimant count should remain the same before and after the upgrade."); + Ok(()) + } + } } From 1cbf8bd94b262bfe149f8ee7ad7c9cd7e5c629ea Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 7 Jan 2025 10:07:14 -0500 Subject: [PATCH 20/31] fmt --- substrate/frame/salary/src/migration.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 8d62b660aca3..988ce8b8a22f 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -74,8 +74,8 @@ pub mod v1 { /// ``` fn convert(local: L) -> N; - /// Converts to the new type and finds the equivalent moment in time as from the view of the new - /// block provider + /// Converts to the new type and finds the equivalent moment in time as from the view of the + /// new block provider /// /// For instance - if your new version uses the relay chain number, you'll want to /// use relay current - ((current local - local) * equivalent_block_duration). @@ -169,14 +169,18 @@ pub mod v1 { #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), TryRuntimeError> { - let (status_existed, pre_claimaint_count) : (v0::StatusOf, v0::ClaimantStatusOf) = - Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); - + let (status_existed, pre_claimaint_count): ( + v0::StatusOf, + v0::ClaimantStatusOf, + ) = Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); + ensure!(crate::Status::::exists() == status_existed, "The Status' storage existence should remain the same before and after the upgrade."); - ensure!(crate::Claimant::::iter().count() == pre_claimaint_count, "The Claimant count should remain the same before and after the upgrade."); + ensure!( + crate::Claimant::::iter().count() == pre_claimaint_count, + "The Claimant count should remain the same before and after the upgrade." + ); Ok(()) } - } } From 0a47eb6f756be50aea50244c9f7b2a6e5ce22179 Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 7 Jan 2025 10:24:36 -0500 Subject: [PATCH 21/31] fix migration checks --- substrate/frame/salary/src/migration.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 988ce8b8a22f..6487f7043300 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -20,6 +20,11 @@ use super::*; use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; +#[cfg(feature = "try-runtime")] +use alloc::vec::Vec; +#[cfg(feature = "try-runtime")] +use sp_runtime::TryRuntimeError; + mod v0 { use super::*; use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; @@ -133,7 +138,7 @@ pub mod v1 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, TryRuntimeError> { let status_exists = v0::Status::::exists(); - let claimant_count = v0::Claimant::::iter().count(); + let claimant_count = v0::Claimant::::iter().count() as u32; Ok((status_exists, claimant_count).encode()) } @@ -169,14 +174,13 @@ pub mod v1 { #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), TryRuntimeError> { - let (status_existed, pre_claimaint_count): ( - v0::StatusOf, - v0::ClaimantStatusOf, - ) = Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); + let (status_existed, pre_claimaint_count): (bool, u32) = + Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); ensure!(crate::Status::::exists() == status_existed, "The Status' storage existence should remain the same before and after the upgrade."); + let post_claimant_count = crate::Claimant::::iter().count() as u32; ensure!( - crate::Claimant::::iter().count() == pre_claimaint_count, + post_claimant_count == pre_claimaint_count, "The Claimant count should remain the same before and after the upgrade." ); Ok(()) From cbc90ebd9e27c14bdff9dc8c3c81a1684c37b7cc Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 7 Jan 2025 10:24:42 -0500 Subject: [PATCH 22/31] fmt --- .../collectives/collectives-westend/src/ambassador/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs index e8e7de6050b2..4039195e6bfc 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs @@ -270,6 +270,6 @@ impl pallet_salary::Config for Runtime { type PayoutPeriod = ConstU32<{ 15 * DAYS }>; // Total monthly salary budget. type Budget = ConstU128<{ 10_000 * DOLLARS }>; - + type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; } From 724795dd0ad6b771b39016289470f4ac2fb7c370 Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 7 Jan 2025 12:31:40 -0500 Subject: [PATCH 23/31] Allow for future moments, some wording and syntax --- .../collectives-westend/src/lib.rs | 20 ++++++++++++------- substrate/frame/salary/src/migration.rs | 14 +++++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 83529f289548..75b3eba02af2 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -787,24 +787,30 @@ impl pallet_salary::migration::v1::ConvertBlockNumber SalaryNewBlockNumber { local } /// The equivalent moment in time from the perspective of the relay chain, starting from a - /// local moment in time (system block number) + /// local moment in time (system block number). fn equivalent_moment_in_time(local_moment: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { - let block_number = System::block_number(); - let local_duration = block_number.saturating_sub(local_moment); - let relay_duration = Self::equivalent_block_duration(local_duration); //6s to 6s + let local_block_number = System::block_number(); + let local_duration = u32::abs_diff(local_block_number, local_moment); + let relay_duration = Self::equivalent_block_duration(local_duration); // 6s to 6s let relay_block_number = ParachainSystem::last_relay_block_number(); - relay_block_number.saturating_sub(relay_duration) + if local_block_number >= local_moment { + // Moment was in past. + relay_block_number.saturating_sub(relay_duration) + } else { + // Moment is in future. + relay_block_number.saturating_add(relay_duration) + } } /// The equivalent duration from the perspective of the relay chain, starting from /// a local duration (number of block). Identity function for Westend, since both - /// relay and collectives chain run 6s block times + /// relay and collectives chain run 6s block times. fn equivalent_block_duration(local_duration: SalaryLocalBlockNumber) -> SalaryNewBlockNumber { local_duration } diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 6487f7043300..e7d1e197eed0 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -83,7 +83,7 @@ pub mod v1 { /// new block provider /// /// For instance - if your new version uses the relay chain number, you'll want to - /// use relay current - ((current local - local) * equivalent_block_duration). + /// use relay current (+ or -) ((current local - local) * equivalent_block_duration). /// Note: This assumes consistent block times on both local chain and relay. /// /// # Example usage @@ -94,13 +94,19 @@ pub mod v1 { /// // number was `local_moment`. /// fn equivalent_moment_in_time(local_moment: u32) -> u32 { /// // How long it's been since 'local_moment' from the parachains pov. - /// let curr_block_number = System::block_number(); - /// let local_duration = curr_block_number.saturating_sub(local_moment); + /// let local_block_number = System::block_number(); + /// let local_duration = u32::abs_diff(local_block_number, local_moment); /// // How many blocks that is from the relay's pov. /// let relay_duration = Self::equivalent_block_duration(local_duration); /// // What the relay block number must have been at 'local_moment'. /// let relay_block_number = ParachainSystem::last_relay_block_number(); - /// relay_block_number.saturating_sub(relay_duration) + /// if local_block_number >= local_moment { + /// // Moment was in past. + /// relay_block_number.saturating_sub(relay_duration) + /// } else { + /// // Moment is in future. + /// relay_block_number.saturating_add(relay_duration) + /// } /// } /// ``` fn equivalent_moment_in_time(local_moment: L) -> N; From 7a77e7e53d793dfcf8adcbb3f7eab702b3dac08e Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 8 Jan 2025 10:12:25 -0500 Subject: [PATCH 24/31] Add runtime user to prdoc --- prdoc/pr_7000.prdoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prdoc/pr_7000.prdoc b/prdoc/pr_7000.prdoc index 99fc5e466c1c..e41c3b6ffd39 100644 --- a/prdoc/pr_7000.prdoc +++ b/prdoc/pr_7000.prdoc @@ -6,6 +6,11 @@ doc: config such that a block provider can be set for use in the pallet. This would usually be the frame system pallet or the appropriate relay chain. Previously it defaulted to the frame system pallet. +- audience: Runtime User + description: |- + This PR updates the Westend runtime to use the relaychain's block number for + salary pallet logic. The type remains the same, but the values have + shifted. crates: - name: pallet-salary bump: major From 519a71dcfa364f6d20bad273e78be0f0b1ea60bd Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 8 Jan 2025 19:33:44 -0500 Subject: [PATCH 25/31] Fix missing config type issue --- polkadot/xcm/xcm-builder/src/tests/pay/salary.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs index 6a2945c6a9b9..ee0fbaf91dff 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs @@ -113,6 +113,7 @@ impl pallet_salary::Config for Test { type RegistrationPeriod = RegistrationPeriod; type PayoutPeriod = PayoutPeriod; type Budget = Budget; + type BlockNumberProvider = System; } /// Scenario: From 8d4cf70623d54ad20c14492c6e71a6af66336942 Mon Sep 17 00:00:00 2001 From: Dom Date: Wed, 8 Jan 2025 19:41:15 -0500 Subject: [PATCH 26/31] Update pr_7000.prdoc --- prdoc/pr_7000.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_7000.prdoc b/prdoc/pr_7000.prdoc index e41c3b6ffd39..6cde3059f079 100644 --- a/prdoc/pr_7000.prdoc +++ b/prdoc/pr_7000.prdoc @@ -18,3 +18,5 @@ crates: bump: minor - name: kitchensink-runtime bump: patch +- name: staging-xcm-builder + bump: patch From d8e7a4ed0470e826e125c5ac1bf621f35d05f661 Mon Sep 17 00:00:00 2001 From: Dom Date: Thu, 9 Jan 2025 09:41:15 -0500 Subject: [PATCH 27/31] Documentation fixes --- substrate/frame/salary/src/migration.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index e7d1e197eed0..1f6341b61fee 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Storage migrations for the salary pallet. +//! Storage migrations for the `pallet_salary`. use super::*; use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; @@ -55,7 +55,7 @@ pub mod v1 { use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; /// Converts previous (local) block number into the new one. May just be identity functions - /// if sticking with local block number as the provider. + /// if sticking with local block number as the block provider. pub trait ConvertBlockNumber { /// Simply converts the type from L to N /// @@ -82,16 +82,12 @@ pub mod v1 { /// Converts to the new type and finds the equivalent moment in time as from the view of the /// new block provider /// - /// For instance - if your new version uses the relay chain number, you'll want to - /// use relay current (+ or -) ((current local - local) * equivalent_block_duration). - /// Note: This assumes consistent block times on both local chain and relay. - /// /// # Example usage /// /// ```rust,ignore /// // Let's say you are a parachain and switching block providers to the relay chain. /// // This will return what the relay block number was at the moment the previous provider's - /// // number was `local_moment`. + /// // number was `local_moment`, assuming consistent block times on both chains. /// fn equivalent_moment_in_time(local_moment: u32) -> u32 { /// // How long it's been since 'local_moment' from the parachains pov. /// let local_block_number = System::block_number(); @@ -117,6 +113,9 @@ pub mod v1 { /// For instance - If you previously had 12s blocks and are now following the relay chain's /// 6, one local block is equivalent to 2 relay blocks in duration. /// + /// # Visualized + /// + /// ```text /// 6s 6s /// |---------||---------| /// @@ -124,7 +123,8 @@ pub mod v1 { /// |--------------------| /// /// ^ Two 6s relay blocks passed per one 12s local block. - /// + /// ``` + /// /// # Example Usage /// /// ```rust,ignore @@ -194,7 +194,7 @@ pub mod v1 { } } -/// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`] wrapped in a +/// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`](v1::MigrateToV1) wrapped in a /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 /// - The on-chain storage version is updated to `1` after the migration executes From 9f4c28a97c4c615f3b95688ae230a9676db8ef4c Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 10 Jan 2025 09:00:46 -0500 Subject: [PATCH 28/31] Fixes after update to umbrella crate --- substrate/frame/salary/src/benchmarking.rs | 2 +- substrate/frame/salary/src/migration.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/substrate/frame/salary/src/benchmarking.rs b/substrate/frame/salary/src/benchmarking.rs index 3a485c05f115..6651d9598db6 100644 --- a/substrate/frame/salary/src/benchmarking.rs +++ b/substrate/frame/salary/src/benchmarking.rs @@ -20,7 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use crate::{BlockNumberFor as SalaryBlockNumberFor, Pallet as Salary}; +use crate::{pallet::BlockNumberFor as SalaryBlockNumberFor, Pallet as Salary}; use frame::benchmarking::prelude::*; diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 1f6341b61fee..72bee389f8c8 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -18,16 +18,16 @@ //! Storage migrations for the `pallet_salary`. use super::*; -use frame_support::{pallet_prelude::*, storage_alias, traits::UncheckedOnRuntimeUpgrade}; +use frame::{storage_alias, traits::UncheckedOnRuntimeUpgrade, deps::frame_support::migrations::VersionedMigration}; #[cfg(feature = "try-runtime")] use alloc::vec::Vec; #[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; +use frame::try_runtime::TryRuntimeError; mod v0 { use super::*; - use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; + use frame::prelude::BlockNumberFor as LocalBlockNumberFor; // V0 types. pub type CycleIndexOf = LocalBlockNumberFor; @@ -51,8 +51,8 @@ mod v0 { } pub mod v1 { - use super::{BlockNumberFor as NewBlockNumberFor, *}; - use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor; + use super::{pallet::BlockNumberFor as NewBlockNumberFor, *}; + use frame::prelude::BlockNumberFor as LocalBlockNumberFor; /// Converts previous (local) block number into the new one. May just be identity functions /// if sticking with local block number as the block provider. @@ -148,7 +148,7 @@ pub mod v1 { Ok((status_exists, claimant_count).encode()) } - fn on_runtime_upgrade() -> frame_support::weights::Weight { + fn on_runtime_upgrade() -> Weight { let mut transactions = 0; // Status storage option @@ -195,11 +195,11 @@ pub mod v1 { } /// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`](v1::MigrateToV1) wrapped in a -/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: +/// [`VersionedMigration`](frame::deps::frame_support::migrations::VersionedMigration), which ensures that: /// - The migration only runs once when the on-chain storage version is 0 /// - The on-chain storage version is updated to `1` after the migration executes /// - Reads/Writes from checking/settings the on-chain storage version are accounted for -pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< +pub type MigrateV0ToV1 = VersionedMigration< 0, // The migration will only execute when the on-chain storage version is 0 1, // The on-chain storage version will be set to 1 after the migration is complete v1::MigrateToV1, From 5e7a5396c9c54e4ce6ea0a725681ee6405da813f Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 10 Jan 2025 09:02:46 -0500 Subject: [PATCH 29/31] small fix --- substrate/frame/salary/src/benchmarking.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/salary/src/benchmarking.rs b/substrate/frame/salary/src/benchmarking.rs index 6651d9598db6..d3a1ed6f3a21 100644 --- a/substrate/frame/salary/src/benchmarking.rs +++ b/substrate/frame/salary/src/benchmarking.rs @@ -21,7 +21,6 @@ use super::*; use crate::{pallet::BlockNumberFor as SalaryBlockNumberFor, Pallet as Salary}; - use frame::benchmarking::prelude::*; const SEED: u32 = 0; From 73536d9389428cc4e0f01048f7dc2452edb8c538 Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 10 Jan 2025 09:17:06 -0500 Subject: [PATCH 30/31] Update migration.rs --- substrate/frame/salary/src/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index 72bee389f8c8..f60381194f18 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -195,7 +195,7 @@ pub mod v1 { } /// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`](v1::MigrateToV1) wrapped in a -/// [`VersionedMigration`](frame::deps::frame_support::migrations::VersionedMigration), which ensures that: +/// [`VersionedMigration`], which ensures that: /// - The migration only runs once when the on-chain storage version is 0 /// - The on-chain storage version is updated to `1` after the migration executes /// - Reads/Writes from checking/settings the on-chain storage version are accounted for From d682adf6637fc47e1f4e92b9a0022f8bf6e87c56 Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 10 Jan 2025 19:29:07 -0500 Subject: [PATCH 31/31] fmt --- substrate/frame/salary/src/migration.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/substrate/frame/salary/src/migration.rs b/substrate/frame/salary/src/migration.rs index f60381194f18..a3d5c02cc9d0 100644 --- a/substrate/frame/salary/src/migration.rs +++ b/substrate/frame/salary/src/migration.rs @@ -18,7 +18,10 @@ //! Storage migrations for the `pallet_salary`. use super::*; -use frame::{storage_alias, traits::UncheckedOnRuntimeUpgrade, deps::frame_support::migrations::VersionedMigration}; +use frame::{ + deps::frame_support::migrations::VersionedMigration, storage_alias, + traits::UncheckedOnRuntimeUpgrade, +}; #[cfg(feature = "try-runtime")] use alloc::vec::Vec; @@ -123,8 +126,8 @@ pub mod v1 { /// |--------------------| /// /// ^ Two 6s relay blocks passed per one 12s local block. - /// ``` - /// + /// ``` + /// /// # Example Usage /// /// ```rust,ignore