diff --git a/runtime/litentry/src/lib.rs b/runtime/litentry/src/lib.rs index d14e9400d3..8d225b5f09 100644 --- a/runtime/litentry/src/lib.rs +++ b/runtime/litentry/src/lib.rs @@ -135,6 +135,10 @@ pub type Executive = frame_executive::Executive< // See the comment before collation related pallets too. AllPalletsWithSystem, ( + migration::ReplacePalletIdentityStorage, + migration::ReplacePalletMultisigStorage, + migration::ReplacePalletProxyStorage, + migration::ReplacePalletVestingStorage, migration::pallet_bounty::ReplacePalletBountyStorage, migration::pallet_treasury::ReplaceTreasuryStorage, migration::pallet_preimage::ReplacePreImageStorage, diff --git a/runtime/litentry/src/migration/balances_transaction_payment.rs b/runtime/litentry/src/migration/balances_transaction_payment.rs index ce4547b57e..69d74a5c4f 100644 --- a/runtime/litentry/src/migration/balances_transaction_payment.rs +++ b/runtime/litentry/src/migration/balances_transaction_payment.rs @@ -122,18 +122,20 @@ where let storage_item_prefix: &[u8] = b"Locks"; let mut weight: Weight = frame_support::weights::Weight::zero(); - for (account, mut locks) in storage_key_iter::< + for (account, locks) in storage_key_iter::< T::AccountId, - WeakBoundedVec, T::MaxLocks>, + WeakBoundedVec, T::MaxLocks>, Blake2_128Concat, >(pallet_prefix, storage_item_prefix) .drain() { - let new_locks: &mut WeakBoundedVec, T::MaxLocks> = &mut locks; - for balance_lock in new_locks.into_iter() { + let mut locks_vec = locks.into_inner(); + for balance_lock in locks_vec.iter_mut() { balance_lock.amount = balance_lock.amount.saturating_mul(DECIMAL_CONVERTOR); } - >::insert(&account, new_locks); + let updated_locks = + WeakBoundedVec::, T::MaxLocks>::force_from(locks_vec, None); + Locks::::insert(&account, updated_locks); weight += T::DbWeight::get().reads_writes(1, 1); } diff --git a/runtime/litentry/src/migration/migrate_identity.rs b/runtime/litentry/src/migration/migrate_identity.rs new file mode 100644 index 0000000000..e673ad41c3 --- /dev/null +++ b/runtime/litentry/src/migration/migrate_identity.rs @@ -0,0 +1,215 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +#![allow(clippy::type_complexity)] + +use frame_support::{ + migration::storage_key_iter, + pallet_prelude::*, + traits::{Currency, Get, OnRuntimeUpgrade}, + Twox64Concat, +}; +use sp_std::{marker::PhantomData, vec::Vec}; + +#[cfg(feature = "try-runtime")] +use parity_scale_codec::{Decode, Encode}; + +use pallet_identity::{RegistrarInfo, Registration}; +use storage::migration::get_storage_value; +type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +// Replace Parachain Staking Storage for Decimal Change from 12 to 18 +pub struct ReplacePalletIdentityStorage(PhantomData); + +impl ReplacePalletIdentityStorage +where + T: pallet_identity::Config, +{ + // pallet_identity + pub fn check_identityof_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletIdentityStorage", + "Running check to ParachainIdentity IdentityOf" + ); + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"IdentityOf"; + + assert!(storage_key_iter::< + T::AccountId, + Registration, T::MaxRegistrars, T::MaxAdditionalFields>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + let weight = T::DbWeight::get(); + frame_support::weights::Weight::from_parts(0, weight.read) + } + + pub fn check_subsof_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletIdentityStorage", + "Running check to ParachainIdentity SubsOf" + ); + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"SubsOf"; + + assert!(storage_key_iter::< + T::AccountId, + Registration, T::MaxRegistrars, T::MaxAdditionalFields>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + let weight = T::DbWeight::get(); + frame_support::weights::Weight::from_parts(0, weight.read) + } + + pub fn check_registrars_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletIdentityStorage", + "Running check to ParachainIdentity Registrars" + ); + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"Registrars"; + + assert!(get_storage_value::< + BoundedVec, T::AccountId>>, T::MaxRegistrars>, + >(pallet_prefix, storage_item_prefix, b"") + .is_none()); + + let weight = T::DbWeight::get(); + frame_support::weights::Weight::from_parts(0, weight.read) + } +} + +#[cfg(feature = "try-runtime")] +impl ReplacePalletIdentityStorage +where + T: pallet_identity::Config, +{ + // pallet_identity + pub fn pre_upgrade_identityof_storage() -> Result, &'static str> { + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"IdentityOf"; + + assert!(storage_key_iter::< + T::AccountId, + Registration, T::MaxRegistrars, T::MaxAdditionalFields>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + Ok(Vec::::new()) + } + pub fn post_upgrade_identityof_storage(_state: Vec) -> Result<(), &'static str> { + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"IdentityOf"; + + assert!(storage_key_iter::< + T::AccountId, + Registration, T::MaxRegistrars, T::MaxAdditionalFields>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + Ok(()) + } + pub fn pre_upgrade_subsof_storage() -> Result, &'static str> { + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"SubsOf"; + + assert!(storage_key_iter::< + T::AccountId, + Registration, T::MaxRegistrars, T::MaxAdditionalFields>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + Ok(Vec::::new()) + } + pub fn post_upgrade_subsof_storage(_state: Vec) -> Result<(), &'static str> { + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"SubsOf"; + + assert!(storage_key_iter::< + T::AccountId, + Registration, T::MaxRegistrars, T::MaxAdditionalFields>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + + Ok(()) + } + pub fn pre_upgrade_registrars_storage() -> Result, &'static str> { + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"Registrars"; + + assert!(get_storage_value::< + BoundedVec, T::AccountId>>, T::MaxRegistrars>, + >(pallet_prefix, storage_item_prefix, b"") + .is_none()); + Ok(Vec::::new()) + } + pub fn post_upgrade_registrars_storage(_state: Vec) -> Result<(), &'static str> { + let pallet_prefix: &[u8] = b"ParachainIdentity"; + let storage_item_prefix: &[u8] = b"Registrars"; + + assert!(get_storage_value::< + BoundedVec, T::AccountId>>, T::MaxRegistrars>, + >(pallet_prefix, storage_item_prefix, b"") + .is_none()); + Ok(()) + } +} + +impl OnRuntimeUpgrade for ReplacePalletIdentityStorage +where + T: frame_system::Config + pallet_identity::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + // pallet_identity + let identityof_vec = Self::pre_upgrade_identityof_storage()?; + let subsof_vec = Self::pre_upgrade_subsof_storage()?; + let registrars_vec = Self::pre_upgrade_registrars_storage()?; + + Ok((identityof_vec, subsof_vec, registrars_vec).encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut weight = frame_support::weights::Weight::from_parts(0, 0); + // pallet_identity + weight += Self::check_identityof_storage(); + weight += Self::check_subsof_storage(); + weight += Self::check_registrars_storage(); + + weight + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), &'static str> { + let pre_vec: (Vec, Vec, Vec) = + Decode::decode(&mut &state[..]).map_err(|_| "Failed to decode Tuple")?; + // pallet_identity + Self::post_upgrade_identityof_storage(pre_vec.0)?; + Self::post_upgrade_subsof_storage(pre_vec.1)?; + Self::post_upgrade_registrars_storage(pre_vec.2)?; + + Ok(()) + } +} diff --git a/runtime/litentry/src/migration/migrate_multisig.rs b/runtime/litentry/src/migration/migrate_multisig.rs new file mode 100644 index 0000000000..e81d012738 --- /dev/null +++ b/runtime/litentry/src/migration/migrate_multisig.rs @@ -0,0 +1,95 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +#![allow(clippy::type_complexity)] + +use frame_support::{ + pallet_prelude::*, + traits::{Get, OnRuntimeUpgrade}, +}; +use sp_std::{marker::PhantomData, vec::Vec}; + +#[cfg(feature = "try-runtime")] +use parity_scale_codec::Encode; + +use pallet_multisig::Multisigs; + +// Replace Parachain Staking Storage for Decimal Change from 12 to 18 +pub struct ReplacePalletMultisigStorage(PhantomData); + +impl ReplacePalletMultisigStorage +where + T: pallet_multisig::Config, +{ + // pallet_multisig + pub fn check_multisig_multisigs_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletMultisigStorage", + "Running checking to Multisig - Multisigs" + ); + + assert!(Multisigs::::iter().next().is_none()); + + let weight = T::DbWeight::get(); + frame_support::weights::Weight::from_parts(0, weight.read) + } +} + +#[cfg(feature = "try-runtime")] +impl ReplacePalletMultisigStorage +where + T: pallet_multisig::Config, +{ + pub fn pre_upgrade_multisig_multisigs_storage() -> Result, &'static str> { + assert!(Multisigs::::iter().next().is_none()); + Ok(Vec::::new()) + } + + pub fn post_upgrade_multisig_multisigs_storage(_state: Vec) -> Result<(), &'static str> { + assert!(Multisigs::::iter().next().is_none()); + Ok(()) + } +} + +impl OnRuntimeUpgrade for ReplacePalletMultisigStorage +where + T: frame_system::Config + pallet_multisig::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + // pallet_multisig + let multisigs_vec = Self::pre_upgrade_multisig_multisigs_storage()?; + + Ok((multisigs_vec,).encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut weight = frame_support::weights::Weight::from_parts(0, 0); + // pallet_multisig + weight += Self::check_multisig_multisigs_storage(); + + weight + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), &'static str> { + let pre_vec: (Vec,) = + Decode::decode(&mut &state[..]).map_err(|_| "Failed to decode Tuple")?; + + // pallet_multisig + Self::post_upgrade_multisig_multisigs_storage(pre_vec.0)?; + Ok(()) + } +} diff --git a/runtime/litentry/src/migration/migrate_proxy.rs b/runtime/litentry/src/migration/migrate_proxy.rs new file mode 100644 index 0000000000..c5be78ebdc --- /dev/null +++ b/runtime/litentry/src/migration/migrate_proxy.rs @@ -0,0 +1,265 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +#![allow(clippy::type_complexity)] + +use frame_support::{ + migration::storage_key_iter, + pallet_prelude::*, + traits::{Currency, Get, OnRuntimeUpgrade}, + Twox64Concat, +}; +use sp_runtime::{traits::Hash, Saturating}; +use sp_std::{marker::PhantomData, vec::Vec}; + +pub const DECIMAL_CONVERTOR: u32 = 1_000_000; + +#[cfg(feature = "try-runtime")] +use parity_scale_codec::Encode; +#[cfg(feature = "try-runtime")] +use sp_std::collections::btree_map::BTreeMap; + +use pallet_proxy::{Announcement, Announcements, Proxies, ProxyDefinition}; +type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +type CallHashOf = <::CallHasher as Hash>::Output; + +pub struct ReplacePalletProxyStorage(PhantomData); + +impl ReplacePalletProxyStorage +where + T: pallet_proxy::Config, +{ + // pallet_proxy + pub fn replace_proxy_proxies_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletProxyStorage", + "Running migration to Proxy - Proxies" + ); + + let mut weight = frame_support::weights::Weight::zero(); + + let pallet_prefix: &[u8] = b"Proxy"; + let storage_item_prefix: &[u8] = b"Proxies"; + + for (account, (proxies, amount)) in storage_key_iter::< + T::AccountId, + ( + BoundedVec< + ProxyDefinition, + T::MaxProxies, + >, + BalanceOf, + ), + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .drain() + { + let new_amount = amount.saturating_mul(DECIMAL_CONVERTOR.into()); + >::insert(account, (proxies, new_amount)); + + weight += T::DbWeight::get().reads_writes(1, 1); + } + + weight + } + + pub fn replace_proxy_announcements_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletProxyStorage", + "Running migration to Proxy - Announcements" + ); + + let mut weight = frame_support::weights::Weight::zero(); + + let pallet_prefix: &[u8] = b"Proxy"; + let storage_item_prefix: &[u8] = b"Announcements"; + + for (account, (announcements, amount)) in storage_key_iter::< + T::AccountId, + ( + BoundedVec< + Announcement, T::BlockNumber>, + T::MaxPending, + >, + BalanceOf, + ), + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .drain() + { + let new_amount = amount.saturating_mul(DECIMAL_CONVERTOR.into()); + >::insert(account, (announcements, new_amount)); + + weight += T::DbWeight::get().reads_writes(1, 1); + } + + weight + } +} + +#[cfg(feature = "try-runtime")] +impl ReplacePalletProxyStorage +where + T: pallet_proxy::Config, +{ + // pallet_proxy + pub fn pre_upgrade_proxy_proxies_storage() -> Result, &'static str> { + let result: BTreeMap< + T::AccountId, + ( + BoundedVec< + ProxyDefinition, + T::MaxProxies, + >, + BalanceOf, + ), + > = >::iter() + .map(|(account, (proxies, amount))| { + let new_amount = amount.saturating_mul(DECIMAL_CONVERTOR.into()); + (account, (proxies, new_amount)) + }) + .collect(); + Ok(result.encode()) + } + + pub fn post_upgrade_proxy_proxies_storage(state: Vec) -> Result<(), &'static str> { + let expected_state = BTreeMap::< + T::AccountId, + ( + BoundedVec< + ProxyDefinition, + T::MaxProxies, + >, + BalanceOf, + ), + >::decode(&mut &state[..]) + .map_err(|_| "Failed to decode BoundedVec")?; + for (account, actual_result) in >::iter() { + let expected_result: ( + BoundedVec< + ProxyDefinition, + T::MaxProxies, + >, + BalanceOf, + ) = expected_state + .get(&account) + .ok_or("Not Expected BoundedVec")? + .clone(); + assert_eq!(expected_result.encode(), actual_result.encode()); + } + Ok(()) + } + + pub fn pre_upgrade_proxy_announcements_storage() -> Result, &'static str> { + let result: BTreeMap< + T::AccountId, + ( + BoundedVec< + Announcement, T::BlockNumber>, + T::MaxPending, + >, + BalanceOf, + ), + > = >::iter() + .map(|(account, (announcements, amount))| { + let new_amount = amount.saturating_mul(DECIMAL_CONVERTOR.into()); + (account, (announcements, new_amount)) + }) + .collect(); + Ok(result.encode()) + } + + pub fn post_upgrade_proxy_announcements_storage(state: Vec) -> Result<(), &'static str> { + let expected_state = BTreeMap::< + T::AccountId, + ( + BoundedVec< + Announcement, T::BlockNumber>, + T::MaxPending, + >, + BalanceOf, + ), + >::decode(&mut &state[..]) + .map_err(|_| "Failed to decode BoundedVec")?; + for (account, actual_result) in >::iter() { + let expected_result: ( + BoundedVec< + Announcement, T::BlockNumber>, + T::MaxPending, + >, + BalanceOf, + ) = expected_state + .get(&account) + .ok_or("Not Expected BoundedVec")? + .clone(); + assert_eq!(expected_result.encode(), actual_result.encode()); + } + Ok(()) + } +} + +impl OnRuntimeUpgrade for ReplacePalletProxyStorage +where + T: pallet_proxy::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + // pallet_proxy + let proxies_vec = Self::pre_upgrade_proxy_proxies_storage()?; + let announcements_vec = Self::pre_upgrade_proxy_announcements_storage()?; + + log::info!( + target: "ReplacePalletProxyStorage", + "Finished performing Proxy pre upgrade checks" + ); + + Ok((proxies_vec, announcements_vec).encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut weight = frame_support::weights::Weight::from_parts(0, 0); + + // pallet_proxy + weight += Self::replace_proxy_proxies_storage(); + weight += Self::replace_proxy_announcements_storage(); + + log::info!( + target: "ReplacePalletProxyStorage", + "Finished performing Proxy storage migration" + ); + + weight + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), &'static str> { + let pre_vec: (Vec, Vec) = + Decode::decode(&mut &state[..]).map_err(|_| "Failed to decode Tuple")?; + + // pallet_proxy + Self::post_upgrade_proxy_proxies_storage(pre_vec.0)?; + Self::post_upgrade_proxy_announcements_storage(pre_vec.1)?; + + log::info!( + target: "ReplacePalletProxyStorage", + "Finished performing Proxy post upgrade checks" + ); + + Ok(()) + } +} diff --git a/runtime/litentry/src/migration/migrate_vesting.rs b/runtime/litentry/src/migration/migrate_vesting.rs new file mode 100644 index 0000000000..99e0a6ea61 --- /dev/null +++ b/runtime/litentry/src/migration/migrate_vesting.rs @@ -0,0 +1,172 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +#![allow(clippy::type_complexity)] + +use frame_support::{ + migration::storage_key_iter, + pallet_prelude::*, + traits::{Currency, Get, OnRuntimeUpgrade}, + Blake2_128Concat, +}; +use sp_runtime::Saturating; +use sp_std::{marker::PhantomData, vec::Vec}; + +pub const DECIMAL_CONVERTOR: u32 = 1_000_000; + +#[cfg(feature = "try-runtime")] +use parity_scale_codec::Encode; +#[cfg(feature = "try-runtime")] +use sp_std::collections::btree_map::BTreeMap; + +use pallet_vesting::{MaxVestingSchedulesGet, Vesting, VestingInfo}; +type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +pub struct ReplacePalletVestingStorage(PhantomData); + +impl ReplacePalletVestingStorage +where + T: pallet_vesting::Config, +{ + // pallet_vesting + pub fn replace_vesting_vesting_storage() -> frame_support::weights::Weight { + log::info!( + target: "ReplacePalletVestingStorage", + "Running migration to Vesting - Vesting" + ); + + let mut weight = frame_support::weights::Weight::zero(); + + let pallet_prefix: &[u8] = b"Vesting"; + let storage_item_prefix: &[u8] = b"Vesting"; + + for (account, mut vest_info) in storage_key_iter::< + T::AccountId, + BoundedVec, T::BlockNumber>, MaxVestingSchedulesGet>, + Blake2_128Concat, + >(pallet_prefix, storage_item_prefix) + .drain() + { + for vest in vest_info.iter_mut() { + *vest = VestingInfo::new( + vest.locked().saturating_mul(DECIMAL_CONVERTOR.into()), + vest.per_block().saturating_mul(DECIMAL_CONVERTOR.into()), + vest.starting_block(), + ); + } + + Vesting::::insert(&account, vest_info); + weight += T::DbWeight::get().reads_writes(1, 1); + } + + weight + } +} + +#[cfg(feature = "try-runtime")] +impl ReplacePalletVestingStorage +where + T: pallet_vesting::Config, +{ + // pallet_vesting + pub fn pre_upgrade_vesting_vesting_storage() -> Result, &'static str> { + let result: BTreeMap< + T::AccountId, + BoundedVec, T::BlockNumber>, MaxVestingSchedulesGet>, + > = >::iter() + .map(|(account, vest_vec)| { + let mut new_vest_vec: BoundedVec< + VestingInfo, T::BlockNumber>, + MaxVestingSchedulesGet, + > = vest_vec; + for vest in new_vest_vec.iter_mut() { + *vest = VestingInfo::new( + vest.locked().saturating_mul(DECIMAL_CONVERTOR.into()), + vest.per_block().saturating_mul(DECIMAL_CONVERTOR.into()), + vest.starting_block(), + ); + } + (account, new_vest_vec) + }) + .collect(); + Ok(result.encode()) + } + + pub fn post_upgrade_vesting_vesting_storage(state: Vec) -> Result<(), &'static str> { + let expected_state = BTreeMap::< + T::AccountId, + BoundedVec, T::BlockNumber>, MaxVestingSchedulesGet>, + >::decode(&mut &state[..]) + .map_err(|_| "Failed to decode BoundedVec")?; + for (account, actual_result) in >::iter() { + let expected_result: BoundedVec< + VestingInfo, T::BlockNumber>, + MaxVestingSchedulesGet, + > = expected_state + .get(&account) + .ok_or("Not Expected BoundedVec")? + .clone(); + assert_eq!(expected_result.encode(), actual_result.encode()); + } + Ok(()) + } +} + +impl OnRuntimeUpgrade for ReplacePalletVestingStorage +where + T: pallet_vesting::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + // pallet_vesting + let vesting_vec = Self::pre_upgrade_vesting_vesting_storage()?; + + log::info!( + target: "ReplacePalletVestingStorage", + "Finished performing Vesting pre upgrade checks" + ); + + Ok((vesting_vec).encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut weight = frame_support::weights::Weight::zero(); + // pallet_vesting + weight += Self::replace_vesting_vesting_storage(); + + log::info!( + target: "ReplacePalletVestingStorage", + "Finished performing Vesting storage migration" + ); + + weight + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), &'static str> { + let pre_vec: (Vec,) = + Decode::decode(&mut &state[..]).map_err(|_| "Failed to decode Tuple")?; + Self::post_upgrade_vesting_vesting_storage(pre_vec.0)?; + + log::info!( + target: "ReplacePalletVestingStorage", + "Finished performing Vesting post upgrade checks" + ); + + Ok(()) + } +} diff --git a/runtime/litentry/src/migration/mod.rs b/runtime/litentry/src/migration/mod.rs index b49dc38701..96f2f0927a 100644 --- a/runtime/litentry/src/migration/mod.rs +++ b/runtime/litentry/src/migration/mod.rs @@ -1,3 +1,11 @@ +pub mod migrate_identity; +pub use migrate_identity::ReplacePalletIdentityStorage; +pub mod migrate_multisig; +pub use migrate_multisig::ReplacePalletMultisigStorage; +pub mod migrate_proxy; +pub use migrate_proxy::ReplacePalletProxyStorage; +pub mod migrate_vesting; +pub use migrate_vesting::ReplacePalletVestingStorage; pub mod bridge_related; pub use bridge_related::ReplaceBridgeRelatedStorage; pub mod parachain_staking;