Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pools 6->7 migration #2942

Merged
merged 14 commits into from
Jan 26, 2024
2 changes: 1 addition & 1 deletion prdoc/pr_2796.prdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: Rococo and Westend Asset-Hub: XCM Transfers with Pallet-Uniques
title: "Rococo and Westend Asset-Hub: XCM Transfers with Pallet-Uniques"

doc:
- audience: Runtime User
Expand Down
5 changes: 3 additions & 2 deletions prdoc/pr_2920.prdoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# 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: Contracts: Stabilize sr25519_verify host function
title: "Contracts: Stabilize sr25519_verify host function"

doc:
- audience: Runtime Dev
description: |
Removed the `#[unstable]` attrribute on `sr25519_verify` host function.

crates: ["pallet-contracts"]
crates:
- name: "pallet-contracts"
13 changes: 13 additions & 0 deletions prdoc/pr_2942.prdoc
Original file line number Diff line number Diff line change
@@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description doesn't make sense to me, V6ToV7 will work regardless of V8 as it is always migrated before V8 right? Or is it fixing something that mod v8 broke?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V6ToV7 will work regardless

No sadly not. It should though - which is what this MR is correcting.
The migration tries to access storage from crate::pallet::BondedPoolInner etc, but this could still be unmigrated since the V8 migration could run afterwards.

It did work fine in the past, because the pallet storage definitions were not changed to V8 yet.


crates:
- name: "pallet-nomination-pools"
60 changes: 43 additions & 17 deletions substrate/frame/nomination-pools/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,7 @@ pub mod versioned {
pub mod v8 {
use super::*;

#[derive(Decode)]
pub struct OldCommission<T: Config> {
pub current: Option<(Perbill, T::AccountId)>,
pub max: Option<Perbill>,
pub change_rate: Option<CommissionChangeRate<BlockNumberFor<T>>>,
pub throttle_from: Option<BlockNumberFor<T>>,
}

#[derive(Decode)]
pub struct OldBondedPoolInner<T: Config> {
pub commission: OldCommission<T>,
pub member_counter: u32,
pub points: BalanceOf<T>,
pub roles: PoolRoles<T::AccountId>,
pub state: PoolState,
}
use super::v7::BondedPoolInner as OldBondedPoolInner;
ggwpez marked this conversation as resolved.
Show resolved Hide resolved

impl<T: Config> OldBondedPoolInner<T> {
fn migrate_to_v8(self) -> BondedPoolInner<T> {
Expand Down Expand Up @@ -128,9 +113,50 @@ 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 Commission<T: Config> {
pub current: Option<(Perbill, T::AccountId)>,
pub max: Option<Perbill>,
pub change_rate: Option<CommissionChangeRate<BlockNumberFor<T>>>,
pub throttle_from: Option<BlockNumberFor<T>>,
}

#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, DebugNoBound, PartialEq, Clone)]
#[codec(mel_bound(T: Config))]
#[scale_info(skip_type_params(T))]
pub struct BondedPoolInner<T: Config> {
pub commission: Commission<T>,
pub member_counter: u32,
pub points: BalanceOf<T>,
pub roles: PoolRoles<T::AccountId>,
pub state: PoolState,
}

#[allow(dead_code)]
#[derive(RuntimeDebugNoBound)]
#[cfg_attr(feature = "std", derive(Clone, PartialEq))]
pub struct BondedPool<T: Config> {
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
/// The identifier of the pool.
id: PoolId,
/// The inner fields.
inner: BondedPoolInner<T>,
}

impl<T: Config> BondedPool<T> {
fn bonded_account(&self) -> T::AccountId {
Pallet::<T>::create_bonded_account(self.id)
}
}

#[frame_support::storage_alias]
pub type BondedPools<T: Config> =
CountedStorageMap<Pallet<T>, Twox64Concat, PoolId, BondedPoolInner<T>>;

pub struct VersionUncheckedMigrateV6ToV7<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> VersionUncheckedMigrateV6ToV7<T> {
fn calculate_tvl_by_total_stake() -> BalanceOf<T> {
Expand Down