From cf84f76fba567122cce75d5478adbd8c2a51bb07 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 1 Feb 2024 13:07:28 +0100 Subject: [PATCH 1/2] Backport of fix Pools 6->7 migration (#2942) (#3093) This should result as a patched `25.0.1` version for https://crates.io/crates/pallet-nomination-pools/25.0.0. Relates to: https://github.com/polkadot-fellows/runtimes/pull/159 Co-authored-by: Oliver Tale-Yazdi --- prdoc/pr_2942.prdoc | 13 ++++ .../frame/nomination-pools/src/migration.rs | 69 +++++++++++++------ 2 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 prdoc/pr_2942.prdoc diff --git a/prdoc/pr_2942.prdoc b/prdoc/pr_2942.prdoc new file mode 100644 index 000000000000..caa276c099b3 --- /dev/null +++ b/prdoc/pr_2942.prdoc @@ -0,0 +1,13 @@ +# 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: Fix pallet-nomination-pools v6 to v7 migration + +doc: + - audience: Node Dev + description: | + Restores the behaviour of the nomination pools `V6ToV7` migration so that it still works when + the pallet will be upgraded to V8 afterwards. + +crates: + - name: "pallet-nomination-pools" diff --git a/substrate/frame/nomination-pools/src/migration.rs b/substrate/frame/nomination-pools/src/migration.rs index 3adfd926d95c..559baf76e4c6 100644 --- a/substrate/frame/nomination-pools/src/migration.rs +++ b/substrate/frame/nomination-pools/src/migration.rs @@ -57,26 +57,9 @@ pub mod versioned { } pub mod v8 { - use super::*; - - #[derive(Decode)] - pub struct OldCommission { - pub current: Option<(Perbill, T::AccountId)>, - pub max: Option, - pub change_rate: Option>>, - pub throttle_from: Option>, - } - - #[derive(Decode)] - pub struct OldBondedPoolInner { - pub commission: OldCommission, - pub member_counter: u32, - pub points: BalanceOf, - pub roles: PoolRoles, - pub state: PoolState, - } + use super::{v7::V7BondedPoolInner, *}; - impl OldBondedPoolInner { + impl V7BondedPoolInner { fn migrate_to_v8(self) -> BondedPoolInner { BondedPoolInner { commission: Commission { @@ -104,7 +87,7 @@ pub mod v8 { fn on_runtime_upgrade() -> Weight { let mut translated = 0u64; - BondedPools::::translate::, _>(|_key, old_value| { + BondedPools::::translate::, _>(|_key, old_value| { translated.saturating_inc(); Some(old_value.migrate_to_v8()) }); @@ -128,16 +111,58 @@ pub mod v8 { /// /// WARNING: This migration works under the assumption that the [`BondedPools`] cannot be inflated /// arbitrarily. Otherwise this migration could fail due to too high weight. -mod v7 { +pub(crate) mod v7 { use super::*; + #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, DebugNoBound, PartialEq, Clone)] + #[codec(mel_bound(T: Config))] + #[scale_info(skip_type_params(T))] + pub struct V7Commission { + pub current: Option<(Perbill, T::AccountId)>, + pub max: Option, + pub change_rate: Option>>, + pub throttle_from: Option>, + } + + #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, DebugNoBound, PartialEq, Clone)] + #[codec(mel_bound(T: Config))] + #[scale_info(skip_type_params(T))] + pub struct V7BondedPoolInner { + pub commission: V7Commission, + pub member_counter: u32, + pub points: BalanceOf, + pub roles: PoolRoles, + pub state: PoolState, + } + + #[allow(dead_code)] + #[derive(RuntimeDebugNoBound)] + #[cfg_attr(feature = "std", derive(Clone, PartialEq))] + pub struct V7BondedPool { + /// The identifier of the pool. + id: PoolId, + /// The inner fields. + inner: V7BondedPoolInner, + } + + impl V7BondedPool { + fn bonded_account(&self) -> T::AccountId { + Pallet::::create_bonded_account(self.id) + } + } + + // NOTE: We cannot put a V7 prefix here since that would change the storage key. + #[frame_support::storage_alias] + pub type BondedPools = + CountedStorageMap, Twox64Concat, PoolId, V7BondedPoolInner>; + pub struct VersionUncheckedMigrateV6ToV7(sp_std::marker::PhantomData); impl VersionUncheckedMigrateV6ToV7 { fn calculate_tvl_by_total_stake() -> BalanceOf { BondedPools::::iter() .map(|(id, inner)| { T::Staking::total_stake( - &BondedPool { id, inner: inner.clone() }.bonded_account(), + &V7BondedPool { id, inner: inner.clone() }.bonded_account(), ) .unwrap_or_default() }) From 4f7012755ec2f21377ab8c3bea07018b8bd5a9c2 Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Mon, 29 Jan 2024 11:06:51 +0100 Subject: [PATCH 2/2] Fix markdown lint error (#3104) --- substrate/frame/sassafras/src/data/tickets-sort.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/sassafras/src/data/tickets-sort.md b/substrate/frame/sassafras/src/data/tickets-sort.md index 4d96a6825c88..64fc45e4fb00 100644 --- a/substrate/frame/sassafras/src/data/tickets-sort.md +++ b/substrate/frame/sassafras/src/data/tickets-sort.md @@ -267,7 +267,7 @@ buffer (i.e. how many tickets we retain from the last processed segment) | 3 | 14 | | 2 | 17 | | 1 | 9 | -| 0 | 13 +| 0 | 13 | # Graph of the same data