From b3f55090e3a799a34c4e805fb1d8b459fbc3f629 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 26 Dec 2024 17:07:03 +0800 Subject: [PATCH 01/27] feat: add paseo migration --- parachain/runtime/litentry/src/lib.rs | 1 + .../runtime/litentry/src/migration/mod.rs | 57 +++++++++++++- parachain/runtime/paseo/src/lib.rs | 2 + .../runtime/paseo/src/migration/migration.md | 0 parachain/runtime/paseo/src/migration/mod.rs | 75 +++++++++++++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 parachain/runtime/paseo/src/migration/migration.md create mode 100644 parachain/runtime/paseo/src/migration/mod.rs diff --git a/parachain/runtime/litentry/src/lib.rs b/parachain/runtime/litentry/src/lib.rs index ff555e4d85..c76857b9d1 100644 --- a/parachain/runtime/litentry/src/lib.rs +++ b/parachain/runtime/litentry/src/lib.rs @@ -99,6 +99,7 @@ pub mod asset_config; pub mod constants; pub mod precompiles; +pub mod migration; pub mod weights; pub mod xcm_config; diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index d3f5a12faa..c4516a5c8f 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -1 +1,56 @@ - +// 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 . + +// By the time of this migration on Litentry 9220 (polkadot stable2407) +// The current storage version: pallet version: +// scheduler: - 0 +// multisig: - 0 +// preimage: - 0 +// balances: - 0 +// democracy: - 0 +// bounties: - 0 +// xcmpQueue: - 3 +// polkadotXcm: - 0 +// developerCommittee - 0 +// developerCommitteeMembership - 0 +// transactionPayment: V1Ancient 0 +// vesting: V1 0 + +// Our target storage version: pallet version: (stable2407) +// scheduler: - 0 => 4 +// multisig: - 0 => 1 +// preimage: - 0 => 1 +// balances: - 0 => 1 +// democracy: - 0 => 1 +// bounties: - 0 => 4 +// xcmpQueue: - 3 => 5 +// polkadotXcm: - 0 => 1 +// developerCommittee - 0 => 4 +// developerCommitteeMembership - 0 => 4 +// transactionPayment: V1Ancient => V2 0 (it is built by genesis, so maybe no fix is fine) +// vesting: V1 0 + +// In try-runtime, current implementation, the storage version is not checked, +// Pallet version is used instead. + +#![allow(clippy::type_complexity)] + +use frame_support::{ + migration::storage_key_iter, + pallet_prelude::*, + traits::{Get, OnRuntimeUpgrade}, + Twox64Concat, +}; diff --git a/parachain/runtime/paseo/src/lib.rs b/parachain/runtime/paseo/src/lib.rs index 597509e9b2..2e9d5ae502 100644 --- a/parachain/runtime/paseo/src/lib.rs +++ b/parachain/runtime/paseo/src/lib.rs @@ -102,6 +102,7 @@ pub mod constants; pub mod governance_v2; pub mod precompiles; +pub mod migration; #[cfg(test)] mod tests; pub mod weights; @@ -132,6 +133,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + migration::MigrateStorageVersionPatch, ); /// Unchecked extrinsic type as expected by this runtime. diff --git a/parachain/runtime/paseo/src/migration/migration.md b/parachain/runtime/paseo/src/migration/migration.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/parachain/runtime/paseo/src/migration/mod.rs b/parachain/runtime/paseo/src/migration/mod.rs new file mode 100644 index 0000000000..31caf7f235 --- /dev/null +++ b/parachain/runtime/paseo/src/migration/mod.rs @@ -0,0 +1,75 @@ +// 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 . + +// By the time of this migration on Paseo 9221 (polkadot stable2407) +// The current storage version: pallet version: +// xcmpQueue: - 3 +// transactionPayment: V2 0 +// vesting: V1 0 + +// Our target storage version: pallet version: (stable2407) +// xcmpQueue: - 3 => 5 +// transactionPayment: V2 0 +// vesting: V1 0 + +// In try-runtime, current implementation, the storage version is not checked, +// Pallet version is used instead. + +use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade}; +use sp_std::marker::PhantomData; + +pub struct MigrateStorageVersionPatch(PhantomData); +impl OnRuntimeUpgrade for MigrateStorageVersionPatch +where + T: frame_system::Config + cumulus_pallet_xcmp_queue::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + // Only checking the lowest storage version + let xcmp_queue_storage_version_check = + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::pre_upgrade()?; + + Ok(VersionedPostUpgradeData::MigrationExecuted(Inner::pre_upgrade()?).encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut weight = frame_support::weights::Weight::from_parts(0, 0); + // V3 to V4 + // XCMP QueueConfig has different default value + // Migration targeting at changing storage value to new default value if old value matched + // Our current Paseo setting has already hard-coded + // This migration should have no effect except bumping storage version + weight += cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::on_runtime_upgrade(); + // V4 to V5 + // Did nothing to storage + // Just checking MaxActiveOutboundChannels is not exceeded + // Our current Paseo Storage is 0 + // This migration should have no effect except bumping storage version + weight += cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5::on_runtime_upgrade(); + + weight + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade( + versioned_post_upgrade_data_bytes: alloc::vec::Vec, + ) -> Result<(), sp_runtime::TryRuntimeError> { + // Only checking the lowest storage version + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::post_upgrade( + versioned_post_upgrade_data_bytes, + ) + } +} From c40b4470e215cbf16208136181928bf9f7920166 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 26 Dec 2024 17:40:05 +0800 Subject: [PATCH 02/27] chore: fix --- parachain/runtime/paseo/src/lib.rs | 4 ++-- parachain/runtime/paseo/src/migration/mod.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/parachain/runtime/paseo/src/lib.rs b/parachain/runtime/paseo/src/lib.rs index 2e9d5ae502..564ff3cb8b 100644 --- a/parachain/runtime/paseo/src/lib.rs +++ b/parachain/runtime/paseo/src/lib.rs @@ -133,7 +133,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, - migration::MigrateStorageVersionPatch, + migration::MigrateStorageVersionPatch, ); /// Unchecked extrinsic type as expected by this runtime. @@ -1975,7 +1975,7 @@ impl_runtime_apis! { for ext in extrinsics.into_iter() { let _ = match &ext.0.function { RuntimeCall::Ethereum(pallet_ethereum::Call::transact { transaction }) => { - if transaction == traced_transaction { + if transaction == *traced_transaction { EvmTracer::new().trace(|| Executive::apply_extrinsic(ext)); return Ok(()); } else { diff --git a/parachain/runtime/paseo/src/migration/mod.rs b/parachain/runtime/paseo/src/migration/mod.rs index 31caf7f235..9e423238b7 100644 --- a/parachain/runtime/paseo/src/migration/mod.rs +++ b/parachain/runtime/paseo/src/migration/mod.rs @@ -28,7 +28,7 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade}; +use frame_support::traits::OnRuntimeUpgrade; use sp_std::marker::PhantomData; pub struct MigrateStorageVersionPatch(PhantomData); @@ -40,7 +40,7 @@ where fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { // Only checking the lowest storage version let xcmp_queue_storage_version_check = - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::pre_upgrade()?; + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::::pre_upgrade()?; Ok(VersionedPostUpgradeData::MigrationExecuted(Inner::pre_upgrade()?).encode()) } @@ -52,13 +52,15 @@ where // Migration targeting at changing storage value to new default value if old value matched // Our current Paseo setting has already hard-coded // This migration should have no effect except bumping storage version - weight += cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::on_runtime_upgrade(); + weight += + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::::on_runtime_upgrade(); // V4 to V5 // Did nothing to storage // Just checking MaxActiveOutboundChannels is not exceeded // Our current Paseo Storage is 0 // This migration should have no effect except bumping storage version - weight += cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5::on_runtime_upgrade(); + weight += + cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5::::on_runtime_upgrade(); weight } @@ -68,7 +70,7 @@ where versioned_post_upgrade_data_bytes: alloc::vec::Vec, ) -> Result<(), sp_runtime::TryRuntimeError> { // Only checking the lowest storage version - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::post_upgrade( + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::::post_upgrade( versioned_post_upgrade_data_bytes, ) } From d70657ae7b6be6cce86816d712badb05f0dffcd3 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 26 Dec 2024 21:38:16 +0800 Subject: [PATCH 03/27] chore: fix --- parachain/runtime/paseo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/runtime/paseo/src/lib.rs b/parachain/runtime/paseo/src/lib.rs index 564ff3cb8b..36be663eb6 100644 --- a/parachain/runtime/paseo/src/lib.rs +++ b/parachain/runtime/paseo/src/lib.rs @@ -133,7 +133,6 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, - migration::MigrateStorageVersionPatch, ); /// Unchecked extrinsic type as expected by this runtime. @@ -160,6 +159,7 @@ pub type Executive = frame_executive::Executive< // it was reverse order before. // See the comment before collation related pallets too. AllPalletsWithSystem, + migration::MigrateStorageVersionPatch, >; impl fp_self_contained::SelfContainedCall for RuntimeCall { From a89868d8740d7eeb5678e7b3273b6b0316c290ad Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 27 Dec 2024 13:13:48 +0800 Subject: [PATCH 04/27] chore: fix --- parachain/runtime/litentry/src/lib.rs | 2 +- parachain/runtime/litentry/src/migration/mod.rs | 10 ++-------- parachain/runtime/paseo/src/lib.rs | 2 +- parachain/runtime/paseo/src/migration/mod.rs | 4 +++- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/parachain/runtime/litentry/src/lib.rs b/parachain/runtime/litentry/src/lib.rs index 67b90b917e..b61354a50d 100644 --- a/parachain/runtime/litentry/src/lib.rs +++ b/parachain/runtime/litentry/src/lib.rs @@ -99,7 +99,7 @@ pub mod asset_config; pub mod constants; pub mod precompiles; -pub mod migration; +// pub mod migration; pub mod weights; pub mod xcm_config; diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index c4516a5c8f..d12df01706 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -46,11 +46,5 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -#![allow(clippy::type_complexity)] - -use frame_support::{ - migration::storage_key_iter, - pallet_prelude::*, - traits::{Get, OnRuntimeUpgrade}, - Twox64Concat, -}; +use frame_support::traits::OnRuntimeUpgrade; +use sp_std::marker::PhantomData; diff --git a/parachain/runtime/paseo/src/lib.rs b/parachain/runtime/paseo/src/lib.rs index fc188efa46..8a6c26dcda 100644 --- a/parachain/runtime/paseo/src/lib.rs +++ b/parachain/runtime/paseo/src/lib.rs @@ -2061,7 +2061,7 @@ impl_runtime_apis! { for ext in extrinsics.into_iter() { let _ = match &ext.0.function { RuntimeCall::Ethereum(pallet_ethereum::Call::transact { transaction }) => { - if transaction == *traced_transaction { + if transaction == traced_transaction { EvmTracer::new().trace(|| Executive::apply_extrinsic(ext)); return Ok(()); } else { diff --git a/parachain/runtime/paseo/src/migration/mod.rs b/parachain/runtime/paseo/src/migration/mod.rs index 9e423238b7..0f7ebb850e 100644 --- a/parachain/runtime/paseo/src/migration/mod.rs +++ b/parachain/runtime/paseo/src/migration/mod.rs @@ -34,7 +34,9 @@ use sp_std::marker::PhantomData; pub struct MigrateStorageVersionPatch(PhantomData); impl OnRuntimeUpgrade for MigrateStorageVersionPatch where - T: frame_system::Config + cumulus_pallet_xcmp_queue::Config, + T: frame_system::Config + + cumulus_pallet_xcmp_queue::Config + + cumulus_pallet_xcmp_queue::migration::v5::V5Config, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { From 569742fa3b1700ad4a1a93de4109edd7de357b7e Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 27 Dec 2024 14:41:23 +0800 Subject: [PATCH 05/27] chore: fix --- parachain/runtime/paseo/src/lib.rs | 2 +- parachain/runtime/paseo/src/migration/mod.rs | 63 +++++--------------- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/parachain/runtime/paseo/src/lib.rs b/parachain/runtime/paseo/src/lib.rs index 8a6c26dcda..107e9cfc55 100644 --- a/parachain/runtime/paseo/src/lib.rs +++ b/parachain/runtime/paseo/src/lib.rs @@ -159,7 +159,7 @@ pub type Executive = frame_executive::Executive< // it was reverse order before. // See the comment before collation related pallets too. AllPalletsWithSystem, - migration::MigrateStorageVersionPatch, + migration::Migrations, >; impl fp_self_contained::SelfContainedCall for RuntimeCall { diff --git a/parachain/runtime/paseo/src/migration/mod.rs b/parachain/runtime/paseo/src/migration/mod.rs index 0f7ebb850e..29bce4d298 100644 --- a/parachain/runtime/paseo/src/migration/mod.rs +++ b/parachain/runtime/paseo/src/migration/mod.rs @@ -28,52 +28,17 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use frame_support::traits::OnRuntimeUpgrade; -use sp_std::marker::PhantomData; - -pub struct MigrateStorageVersionPatch(PhantomData); -impl OnRuntimeUpgrade for MigrateStorageVersionPatch -where - T: frame_system::Config - + cumulus_pallet_xcmp_queue::Config - + cumulus_pallet_xcmp_queue::migration::v5::V5Config, -{ - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - // Only checking the lowest storage version - let xcmp_queue_storage_version_check = - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::::pre_upgrade()?; - - Ok(VersionedPostUpgradeData::MigrationExecuted(Inner::pre_upgrade()?).encode()) - } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - let mut weight = frame_support::weights::Weight::from_parts(0, 0); - // V3 to V4 - // XCMP QueueConfig has different default value - // Migration targeting at changing storage value to new default value if old value matched - // Our current Paseo setting has already hard-coded - // This migration should have no effect except bumping storage version - weight += - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::::on_runtime_upgrade(); - // V4 to V5 - // Did nothing to storage - // Just checking MaxActiveOutboundChannels is not exceeded - // Our current Paseo Storage is 0 - // This migration should have no effect except bumping storage version - weight += - cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5::::on_runtime_upgrade(); - - weight - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade( - versioned_post_upgrade_data_bytes: alloc::vec::Vec, - ) -> Result<(), sp_runtime::TryRuntimeError> { - // Only checking the lowest storage version - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::::post_upgrade( - versioned_post_upgrade_data_bytes, - ) - } -} +pub type Migrations = ( + // V3 to V4 + // XCMP QueueConfig has different default value + // Migration targeting at changing storage value to new default value if old value matched + // Our current Paseo setting has already hard-coded + // This migration should have no effect except bumping storage version + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, + // V4 to V5 + // Did nothing to storage + // Just checking MaxActiveOutboundChannels is not exceeded + // Our current Paseo Storage is 0 + // This migration should have no effect except bumping storage version + cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, +); \ No newline at end of file From 17208cb09414b2acecf3f15be32b0cc9c8302711 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 27 Dec 2024 15:46:55 +0800 Subject: [PATCH 06/27] chore: fix --- parachain/runtime/paseo/src/migration/mod.rs | 2 +- parachain/runtime/paseo/src/xcm_config.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/parachain/runtime/paseo/src/migration/mod.rs b/parachain/runtime/paseo/src/migration/mod.rs index 29bce4d298..3b492ef07a 100644 --- a/parachain/runtime/paseo/src/migration/mod.rs +++ b/parachain/runtime/paseo/src/migration/mod.rs @@ -41,4 +41,4 @@ pub type Migrations = ( // Our current Paseo Storage is 0 // This migration should have no effect except bumping storage version cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, -); \ No newline at end of file +); diff --git a/parachain/runtime/paseo/src/xcm_config.rs b/parachain/runtime/paseo/src/xcm_config.rs index c18fd3c7f2..ab90c4b9b5 100644 --- a/parachain/runtime/paseo/src/xcm_config.rs +++ b/parachain/runtime/paseo/src/xcm_config.rs @@ -244,3 +244,9 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight; type PriceForSiblingDelivery = NoPriceForMessageDelivery; } + +// TODO:: remove after migration of storage version finished +impl cumulus_pallet_xcmp_queue::migration::v5::V5Config for Runtime { + // This must be the same as the `ChannelInfo` from the `Config`: + type ChannelList = ParachainSystem; +} From 43ac264f26acfd9d3454ef2885aa97e967efe10c Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sat, 28 Dec 2024 19:30:47 +0800 Subject: [PATCH 07/27] chore: fix --- parachain/runtime/litentry/src/lib.rs | 2 +- .../runtime/litentry/src/migration/mod.rs | 83 ++++++++++++++++++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/parachain/runtime/litentry/src/lib.rs b/parachain/runtime/litentry/src/lib.rs index b61354a50d..67b90b917e 100644 --- a/parachain/runtime/litentry/src/lib.rs +++ b/parachain/runtime/litentry/src/lib.rs @@ -99,7 +99,7 @@ pub mod asset_config; pub mod constants; pub mod precompiles; -// pub mod migration; +pub mod migration; pub mod weights; pub mod xcm_config; diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index d12df01706..ea36eb0a20 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,6 +45,85 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. - -use frame_support::traits::OnRuntimeUpgrade; +use frame_support::{ + traits::{Get, OnRuntimeUpgrade}, + StorageHasher, Twox128, +}; +use frame_system::pallet_prelude::BlockNumberFor; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use sp_std::vec::Vec; +use xcm::Version; + +use pallet_scheduler::Agenda; + +pub type Migrations = ( + // Scheduler V0 => V4 + // The official pallet does not provide any available migration + // We, Litentry Storage have two old unexecuted expired root tasks. + // This storage should be clean up and update storage version to V4 directly. + // PS: Looks like two old tasks fits V2/V3 structure + RemoveSchedulerOldStorage, + // V3 to V4 + // XCMP QueueConfig has different default value + // Migration targeting at changing storage value to new default value if old value matched + // Our current Paseo setting has already hard-coded + // This migration should have no effect except bumping storage version + cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, + // V4 to V5 + // Did nothing to storage + // Just checking MaxActiveOutboundChannels is not exceeded + // Our current Paseo Storage is 0 + // This migration should have no effect except bumping storage version + cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, +); + +pub struct RemoveSchedulerOldStorage(PhantomData); +impl OnRuntimeUpgrade for RemoveSchedulerOldStorage +where + T: frame_system::Config + pallet_scheduler::Config, + BlockNumberFor: From, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + log::info!("Pre check pallet scheduler storage only has two precise tasks leftover"); + for (when, vec_schedule) in >::iter() { + assert!( + when == 3067200u128.into() || when == 2995200u128.into(), + "Extra schedule exists" + ); + } + Ok(Vec::::new()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + // Remove Scheduler Storage precisely of according block agenda only + // TODO: Very Weak safety + Agenda::::remove(2995200u128.into()); + Agenda::::remove(3067200u128.into()); + + #[allow(deprecated)] + frame_support::storage::migration::remove_storage_prefix( + b"Scheduler", + b"StorageVersion", + &[], + ); + StorageVersion::new(4).put::>(); + ::DbWeight::get().reads_writes(2, 4) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + use sp_io::KillStorageResult; + for (when, vec_schedule) in >::iter() { + assert!( + when != 3067200u128.into() && when != 2995200u128.into(), + "Old schedule still exists" + ); + } + + ensure!(StorageVersion::get::>() == 4, "Must upgrade"); + + Ok(()) + } +} From d91689be312e300d91bd2830f57dd5f81756080d Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sat, 28 Dec 2024 20:15:09 +0800 Subject: [PATCH 08/27] chore: fix clippy --- .../runtime/litentry/src/migration/mod.rs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index ea36eb0a20..9480a43b3e 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,17 +45,12 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use frame_support::{ - traits::{Get, OnRuntimeUpgrade}, - StorageHasher, Twox128, -}; -use frame_system::pallet_prelude::BlockNumberFor; +use frame_support::traits::{Get, OnRuntimeUpgrade}; +use frame_system::pallet_prelude::{BlockNumberFor, StorageVersion}; +use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] use sp_std::vec::Vec; -use xcm::Version; - -use pallet_scheduler::Agenda; pub type Migrations = ( // Scheduler V0 => V4 @@ -63,7 +58,15 @@ pub type Migrations = ( // We, Litentry Storage have two old unexecuted expired root tasks. // This storage should be clean up and update storage version to V4 directly. // PS: Looks like two old tasks fits V2/V3 structure - RemoveSchedulerOldStorage, + RemoveSchedulerOldStorage, + // Multsig V0 => V1 + // Remove old unsettled call storage and do the refund + // Does not matter if we do have old storage or not + // Should simply works + pallet_multisig::migrations::v1::MigrateToV1, + // Preimage V0 => V1 + // + pallet_preimage::migration::v1::Migration, // V3 to V4 // XCMP QueueConfig has different default value // Migration targeting at changing storage value to new default value if old value matched From 32a57b39f670f6bc82b4c4deb80112dad99ed988 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sat, 28 Dec 2024 21:19:09 +0800 Subject: [PATCH 09/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 9480a43b3e..ee8414e01a 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,8 +45,8 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use frame_support::traits::{Get, OnRuntimeUpgrade}; -use frame_system::pallet_prelude::{BlockNumberFor, StorageVersion}; +use frame_support::traits::{Get, OnRuntimeUpgrade, StorageVersion}; +use frame_system::pallet_prelude::BlockNumberFor; use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] From 963a2a4ae2aab223d422462e1a89bb84c41d61f8 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sat, 28 Dec 2024 21:58:07 +0800 Subject: [PATCH 10/27] chore: fix --- .../runtime/litentry/src/migration/mod.rs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index ee8414e01a..e8c8358142 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -90,11 +90,10 @@ where #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { log::info!("Pre check pallet scheduler storage only has two precise tasks leftover"); + let one: BlockNumberFor = 3067200u128.into(); + let two: BlockNumberFor = 2995200u128.into(); for (when, vec_schedule) in >::iter() { - assert!( - when == 3067200u128.into() || when == 2995200u128.into(), - "Extra schedule exists" - ); + assert!(when == one || when == two, "Extra schedule exists"); } Ok(Vec::::new()) } @@ -102,8 +101,10 @@ where fn on_runtime_upgrade() -> frame_support::weights::Weight { // Remove Scheduler Storage precisely of according block agenda only // TODO: Very Weak safety - Agenda::::remove(2995200u128.into()); - Agenda::::remove(3067200u128.into()); + let one: BlockNumberFor = 3067200u128.into(); + let two: BlockNumberFor = 2995200u128.into(); + Agenda::::remove(one); + Agenda::::remove(two); #[allow(deprecated)] frame_support::storage::migration::remove_storage_prefix( @@ -117,12 +118,10 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - use sp_io::KillStorageResult; + let one: BlockNumberFor = 3067200u128.into(); + let two: BlockNumberFor = 2995200u128.into(); for (when, vec_schedule) in >::iter() { - assert!( - when != 3067200u128.into() && when != 2995200u128.into(), - "Old schedule still exists" - ); + assert!(when != one && when != two, "Old schedule still exists"); } ensure!(StorageVersion::get::>() == 4, "Must upgrade"); From b0f8e73d6f4979e1dd3202ceb95177395e9bc884 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sun, 29 Dec 2024 14:33:46 +0800 Subject: [PATCH 11/27] feat: add all migrations --- parachain/runtime/litentry/src/lib.rs | 1 + .../runtime/litentry/src/migration/mod.rs | 217 +++++++++++++++++- 2 files changed, 217 insertions(+), 1 deletion(-) diff --git a/parachain/runtime/litentry/src/lib.rs b/parachain/runtime/litentry/src/lib.rs index 67b90b917e..e801e211a2 100644 --- a/parachain/runtime/litentry/src/lib.rs +++ b/parachain/runtime/litentry/src/lib.rs @@ -157,6 +157,7 @@ pub type Executive = frame_executive::Executive< // It was reverse order before. // See the comment before collation related pallets too. AllPalletsWithSystem, + migration::Migrations, >; impl fp_self_contained::SelfContainedCall for RuntimeCall { diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index e8c8358142..99d291852d 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,6 +45,7 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. +use super::{DeveloperCommittee, DeveloperCommitteeMembership}; use frame_support::traits::{Get, OnRuntimeUpgrade, StorageVersion}; use frame_system::pallet_prelude::BlockNumberFor; use pallet_scheduler::Agenda; @@ -65,8 +66,21 @@ pub type Migrations = ( // Should simply works pallet_multisig::migrations::v1::MigrateToV1, // Preimage V0 => V1 - // + // Migrate old StatusFor and PreimageFor Storage into new Storage pallet_preimage::migration::v1::Migration, + // Balances V0 => V1 + // The official pallet migration is not need since we do not have any XCM deactive accounts + // But our onchain inactiveIssuance storage of pallet_balance is non-negative + // TODO: Where does this number come from? + BalancesUpdateStorageVersionResetInactive, + // Democracy V0 => V1 + // This migration only effects onging proposal/referedum, NextExternal + // The referedum info's proposal hash is migrated if the hash is in old form (In our case, even for an onging one it will do nothing) + pallet_democracy::migrations::v1::Migration, + // Bounties V0 => V4 + // The official migration does nothing but change pallet name and bump version + // So we just bump version storage instead + BountiesUpdateStorageVersion, // V3 to V4 // XCMP QueueConfig has different default value // Migration targeting at changing storage value to new default value if old value matched @@ -79,6 +93,19 @@ pub type Migrations = ( // Our current Paseo Storage is 0 // This migration should have no effect except bumping storage version cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, + // PolkadotXcm V0 => V1 + // Our storage is already correct + // This migration is for can old weightInfo into new weightInfo form + // Should do nothing but bump version storage for us + pallet_xcm::migration::v1::MigrateToV1, + // DeveloperCommittee V0 => V4 + // The official migration does nothing but change pallet name and bump version + // So we just bump version storage instead + DeveloperCommitteeUpdateStorageVersion, + // DeveloperCommitteeMembership V0 => V4 + // The official migration does nothing but change pallet name and bump version + // So we just bump version storage instead + DeveloperCommitteeMembershipUpdateStorageVersion, ); pub struct RemoveSchedulerOldStorage(PhantomData); @@ -129,3 +156,191 @@ where Ok(()) } } + +pub struct BalancesUpdateStorageVersionResetInactive(PhantomData<(T, I)>); +impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive +where + T: frame_system::Config + pallet_balances::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + ensure!( + StorageVersion::get::>() == 0, + "Already upgrade to some non-zero version" + ); + Ok(Vec::::new()) + } + + fn on_runtime_upgrade() -> Weight { + let on_chain_version = Pallet::::on_chain_storage_version(); + + if on_chain_version == 0 { + // Remove the old `StorageVersion` type. + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + pallet_balances::Pallet::::name().as_bytes(), + "StorageVersion".as_bytes(), + )); + + InactiveIssuance::::kill(); + + // Set storage version to `1`. + StorageVersion::new(1).put::>(); + + log::info!(target: LOG_TARGET, "Storage to version 1"); + T::DbWeight::get().reads_writes(1, 3) + } else { + log::info!( + target: LOG_TARGET, + "Migration did not execute. This probably should be removed" + ); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + ensure!(StorageVersion::get::>() == 1, "Must upgrade"); + Ok(()) + } +} + +pub struct BountiesUpdateStorageVersion(PhantomData); +impl OnRuntimeUpgrade for BountiesUpdateStorageVersion +where + T: frame_system::Config + pallet_bounties::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + ensure!( + StorageVersion::get::>() == 0, + "Already upgrade to some non-zero version" + ); + Ok(Vec::::new()) + } + + fn on_runtime_upgrade() -> Weight { + let on_chain_version = Pallet::::on_chain_storage_version(); + + if on_chain_version == 0 { + // Remove the old `StorageVersion` type. + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + pallet_bounties::Pallet::::name().as_bytes(), + "StorageVersion".as_bytes(), + )); + + InactiveIssuance::::kill(); + + // Set storage version to `4`. + StorageVersion::new(4).put::>(); + + log::info!(target: LOG_TARGET, "Storage to version 4"); + T::DbWeight::get().reads_writes(1, 3) + } else { + log::info!( + target: LOG_TARGET, + "Migration did not execute. This probably should be removed" + ); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + ensure!(StorageVersion::get::>() == 4, "Must upgrade"); + Ok(()) + } +} + +pub struct DeveloperCommitteeUpdateStorageVersion(PhantomData<(T, I)>); +impl OnRuntimeUpgrade for DeveloperCommitteeUpdateStorageVersion +where + T: frame_system::Config + pallet_collective::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + ensure!( + StorageVersion::get::() == 0, + "Already upgrade to some non-zero version" + ); + Ok(Vec::::new()) + } + + fn on_runtime_upgrade() -> Weight { + let on_chain_version = Pallet::::on_chain_storage_version(); + + if on_chain_version == 0 { + // Remove the old `StorageVersion` type. + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + DeveloperCommittee::name().as_bytes(), + "StorageVersion".as_bytes(), + )); + + InactiveIssuance::::kill(); + + // Set storage version to `4`. + StorageVersion::new(4).put::(); + + log::info!(target: LOG_TARGET, "Storage to version 4"); + T::DbWeight::get().reads_writes(1, 3) + } else { + log::info!( + target: LOG_TARGET, + "Migration did not execute. This probably should be removed" + ); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + ensure!(StorageVersion::get::() == 4, "Must upgrade"); + Ok(()) + } +} + +pub struct DeveloperCommitteeMembershipUpdateStorageVersion(PhantomData<(T, I)>); +impl OnRuntimeUpgrade for DeveloperCommitteeMembershipUpdateStorageVersion +where + T: frame_system::Config + pallet_collective::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + ensure!( + StorageVersion::get::() == 0, + "Already upgrade to some non-zero version" + ); + Ok(Vec::::new()) + } + + fn on_runtime_upgrade() -> Weight { + let on_chain_version = Pallet::::on_chain_storage_version(); + + if on_chain_version == 0 { + // Remove the old `StorageVersion` type. + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + DeveloperCommitteeMembership::name().as_bytes(), + "StorageVersion".as_bytes(), + )); + + InactiveIssuance::::kill(); + + // Set storage version to `4`. + StorageVersion::new(4).put::(); + + log::info!(target: LOG_TARGET, "Storage to version 4"); + T::DbWeight::get().reads_writes(1, 3) + } else { + log::info!( + target: LOG_TARGET, + "Migration did not execute. This probably should be removed" + ); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + ensure!(StorageVersion::get::() == 4, "Must upgrade"); + Ok(()) + } +} From d3161229ac846274b50b54ea6e6882178ed94340 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sun, 29 Dec 2024 15:10:43 +0800 Subject: [PATCH 12/27] chore: fix --- .../runtime/litentry/src/migration/mod.rs | 49 ++++++++++--------- parachain/runtime/litentry/src/xcm_config.rs | 6 +++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 99d291852d..ce6bb6157a 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -46,8 +46,9 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. use super::{DeveloperCommittee, DeveloperCommitteeMembership}; -use frame_support::traits::{Get, OnRuntimeUpgrade, StorageVersion}; +use frame_support::traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}; use frame_system::pallet_prelude::BlockNumberFor; +use pallet_balances::InactiveIssuance; use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] @@ -76,7 +77,7 @@ pub type Migrations = ( // Democracy V0 => V1 // This migration only effects onging proposal/referedum, NextExternal // The referedum info's proposal hash is migrated if the hash is in old form (In our case, even for an onging one it will do nothing) - pallet_democracy::migrations::v1::Migration, + pallet_democracy::migrations::v1::v1::Migration, // Bounties V0 => V4 // The official migration does nothing but change pallet name and bump version // So we just bump version storage instead @@ -97,7 +98,7 @@ pub type Migrations = ( // Our storage is already correct // This migration is for can old weightInfo into new weightInfo form // Should do nothing but bump version storage for us - pallet_xcm::migration::v1::MigrateToV1, + pallet_xcm::migration::v1::MigrateToV1, // DeveloperCommittee V0 => V4 // The official migration does nothing but change pallet name and bump version // So we just bump version storage instead @@ -157,6 +158,7 @@ where } } +const BALANCES_LOG_TARGET: &str = "runtime::balances"; pub struct BalancesUpdateStorageVersionResetInactive(PhantomData<(T, I)>); impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive where @@ -171,8 +173,8 @@ where Ok(Vec::::new()) } - fn on_runtime_upgrade() -> Weight { - let on_chain_version = Pallet::::on_chain_storage_version(); + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let on_chain_version = pallet_balances::Pallet::::on_chain_storage_version(); if on_chain_version == 0 { // Remove the old `StorageVersion` type. @@ -186,11 +188,11 @@ where // Set storage version to `1`. StorageVersion::new(1).put::>(); - log::info!(target: LOG_TARGET, "Storage to version 1"); + log::info!(target: BALANCES_LOG_TARGET, "Storage to version 1"); T::DbWeight::get().reads_writes(1, 3) } else { log::info!( - target: LOG_TARGET, + target: BALANCES_LOG_TARGET, "Migration did not execute. This probably should be removed" ); T::DbWeight::get().reads(1) @@ -204,10 +206,11 @@ where } } -pub struct BountiesUpdateStorageVersion(PhantomData); -impl OnRuntimeUpgrade for BountiesUpdateStorageVersion +const BOUNTIES_LOG_TARGET: &str = "runtime::bounties"; +pub struct BountiesUpdateStorageVersion(PhantomData<(T, I)>); +impl OnRuntimeUpgrade for BountiesUpdateStorageVersion where - T: frame_system::Config + pallet_bounties::Config, + T: frame_system::Config + pallet_bounties::Config, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { @@ -218,8 +221,8 @@ where Ok(Vec::::new()) } - fn on_runtime_upgrade() -> Weight { - let on_chain_version = Pallet::::on_chain_storage_version(); + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let on_chain_version = pallet_bounties::Pallet::::on_chain_storage_version(); if on_chain_version == 0 { // Remove the old `StorageVersion` type. @@ -233,11 +236,11 @@ where // Set storage version to `4`. StorageVersion::new(4).put::>(); - log::info!(target: LOG_TARGET, "Storage to version 4"); + log::info!(target: BOUNTIES_LOG_TARGET, "Storage to version 4"); T::DbWeight::get().reads_writes(1, 3) } else { log::info!( - target: LOG_TARGET, + target: BOUNTIES_LOG_TARGET, "Migration did not execute. This probably should be removed" ); T::DbWeight::get().reads(1) @@ -251,6 +254,7 @@ where } } +const DEVELOPER_COMMITTEE_LOG_TARGET: &str = "runtime::collective3"; pub struct DeveloperCommitteeUpdateStorageVersion(PhantomData<(T, I)>); impl OnRuntimeUpgrade for DeveloperCommitteeUpdateStorageVersion where @@ -265,8 +269,8 @@ where Ok(Vec::::new()) } - fn on_runtime_upgrade() -> Weight { - let on_chain_version = Pallet::::on_chain_storage_version(); + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let on_chain_version = DeveloperCommittee::on_chain_storage_version(); if on_chain_version == 0 { // Remove the old `StorageVersion` type. @@ -280,11 +284,11 @@ where // Set storage version to `4`. StorageVersion::new(4).put::(); - log::info!(target: LOG_TARGET, "Storage to version 4"); + log::info!(target: DEVELOPER_COMMITTEE_LOG_TARGET, "Storage to version 4"); T::DbWeight::get().reads_writes(1, 3) } else { log::info!( - target: LOG_TARGET, + target: DEVELOPER_COMMITTEE_LOG_TARGET, "Migration did not execute. This probably should be removed" ); T::DbWeight::get().reads(1) @@ -298,6 +302,7 @@ where } } +const DEVELOPER_COMMITTEE_MEMBERSHIP_LOG_TARGET: &str = "runtime::membership3"; pub struct DeveloperCommitteeMembershipUpdateStorageVersion(PhantomData<(T, I)>); impl OnRuntimeUpgrade for DeveloperCommitteeMembershipUpdateStorageVersion where @@ -312,8 +317,8 @@ where Ok(Vec::::new()) } - fn on_runtime_upgrade() -> Weight { - let on_chain_version = Pallet::::on_chain_storage_version(); + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let on_chain_version = DeveloperCommitteeMembership::on_chain_storage_version(); if on_chain_version == 0 { // Remove the old `StorageVersion` type. @@ -327,11 +332,11 @@ where // Set storage version to `4`. StorageVersion::new(4).put::(); - log::info!(target: LOG_TARGET, "Storage to version 4"); + log::info!(target: DEVELOPER_COMMITTEE_MEMBERSHIP_LOG_TARGET, "Storage to version 4"); T::DbWeight::get().reads_writes(1, 3) } else { log::info!( - target: LOG_TARGET, + target: DEVELOPER_COMMITTEE_MEMBERSHIP_LOG_TARGET, "Migration did not execute. This probably should be removed" ); T::DbWeight::get().reads(1) diff --git a/parachain/runtime/litentry/src/xcm_config.rs b/parachain/runtime/litentry/src/xcm_config.rs index c18fd3c7f2..ab90c4b9b5 100644 --- a/parachain/runtime/litentry/src/xcm_config.rs +++ b/parachain/runtime/litentry/src/xcm_config.rs @@ -244,3 +244,9 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight; type PriceForSiblingDelivery = NoPriceForMessageDelivery; } + +// TODO:: remove after migration of storage version finished +impl cumulus_pallet_xcmp_queue::migration::v5::V5Config for Runtime { + // This must be the same as the `ChannelInfo` from the `Config`: + type ChannelList = ParachainSystem; +} From 965592285c7b56bc69b7da14f4db7e2eb1e013e6 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sun, 29 Dec 2024 15:41:18 +0800 Subject: [PATCH 13/27] chore: fix --- .../runtime/litentry/src/migration/mod.rs | 75 +++++++++++-------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index ce6bb6157a..f4d476005a 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,8 +45,9 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use super::{DeveloperCommittee, DeveloperCommitteeMembership}; -use frame_support::traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}; +use frame_support::traits::{ + Get, GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion, +}; use frame_system::pallet_prelude::BlockNumberFor; use pallet_balances::InactiveIssuance; use pallet_scheduler::Agenda; @@ -113,13 +114,13 @@ pub struct RemoveSchedulerOldStorage(PhantomData); impl OnRuntimeUpgrade for RemoveSchedulerOldStorage where T: frame_system::Config + pallet_scheduler::Config, - BlockNumberFor: From, + BlockNumberFor: From, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { log::info!("Pre check pallet scheduler storage only has two precise tasks leftover"); - let one: BlockNumberFor = 3067200u128.into(); - let two: BlockNumberFor = 2995200u128.into(); + let one: BlockNumberFor = 3067200u32.into(); + let two: BlockNumberFor = 2995200u32.into(); for (when, vec_schedule) in >::iter() { assert!(when == one || when == two, "Extra schedule exists"); } @@ -129,8 +130,8 @@ where fn on_runtime_upgrade() -> frame_support::weights::Weight { // Remove Scheduler Storage precisely of according block agenda only // TODO: Very Weak safety - let one: BlockNumberFor = 3067200u128.into(); - let two: BlockNumberFor = 2995200u128.into(); + let one: BlockNumberFor = 3067200u32.into(); + let two: BlockNumberFor = 2995200u32.into(); Agenda::::remove(one); Agenda::::remove(two); @@ -146,8 +147,8 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - let one: BlockNumberFor = 3067200u128.into(); - let two: BlockNumberFor = 2995200u128.into(); + let one: BlockNumberFor = 3067200u32.into(); + let two: BlockNumberFor = 2995200u32.into(); for (when, vec_schedule) in >::iter() { assert!(when != one && when != two, "Old schedule still exists"); } @@ -159,10 +160,10 @@ where } const BALANCES_LOG_TARGET: &str = "runtime::balances"; -pub struct BalancesUpdateStorageVersionResetInactive(PhantomData<(T, I)>); -impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive +pub struct BalancesUpdateStorageVersionResetInactive(PhantomData); +impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive where - T: frame_system::Config + pallet_balances::Config, + T: frame_system::Config + pallet_balances::Config, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { @@ -174,19 +175,19 @@ where } fn on_runtime_upgrade() -> frame_support::weights::Weight { - let on_chain_version = pallet_balances::Pallet::::on_chain_storage_version(); + let on_chain_version = pallet_balances::Pallet::::on_chain_storage_version(); if on_chain_version == 0 { // Remove the old `StorageVersion` type. frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( - pallet_balances::Pallet::::name().as_bytes(), + pallet_balances::Pallet::::name().as_bytes(), "StorageVersion".as_bytes(), )); - InactiveIssuance::::kill(); + InactiveIssuance::::kill(); // Set storage version to `1`. - StorageVersion::new(1).put::>(); + StorageVersion::new(1).put::>(); log::info!(target: BALANCES_LOG_TARGET, "Storage to version 1"); T::DbWeight::get().reads_writes(1, 3) @@ -231,8 +232,6 @@ where "StorageVersion".as_bytes(), )); - InactiveIssuance::::kill(); - // Set storage version to `4`. StorageVersion::new(4).put::>(); @@ -263,26 +262,28 @@ where #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { ensure!( - StorageVersion::get::() == 0, + StorageVersion::get::>() + == 0, "Already upgrade to some non-zero version" ); Ok(Vec::::new()) } fn on_runtime_upgrade() -> frame_support::weights::Weight { - let on_chain_version = DeveloperCommittee::on_chain_storage_version(); + let on_chain_version = + pallet_collective::Pallet::::on_chain_storage_version( + ); if on_chain_version == 0 { // Remove the old `StorageVersion` type. frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( - DeveloperCommittee::name().as_bytes(), + pallet_collective::Pallet::::name().as_bytes(), "StorageVersion".as_bytes(), )); - InactiveIssuance::::kill(); - // Set storage version to `4`. - StorageVersion::new(4).put::(); + StorageVersion::new(4) + .put::>(); log::info!(target: DEVELOPER_COMMITTEE_LOG_TARGET, "Storage to version 4"); T::DbWeight::get().reads_writes(1, 3) @@ -297,7 +298,11 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - ensure!(StorageVersion::get::() == 4, "Must upgrade"); + ensure!( + StorageVersion::get::>() + == 4, + "Must upgrade" + ); Ok(()) } } @@ -311,26 +316,28 @@ where #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { ensure!( - StorageVersion::get::() == 0, + StorageVersion::get::>() + == 0, "Already upgrade to some non-zero version" ); Ok(Vec::::new()) } fn on_runtime_upgrade() -> frame_support::weights::Weight { - let on_chain_version = DeveloperCommitteeMembership::on_chain_storage_version(); + let on_chain_version = + pallet_membership::Pallet::::on_chain_storage_version( + ); if on_chain_version == 0 { // Remove the old `StorageVersion` type. frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( - DeveloperCommitteeMembership::name().as_bytes(), + pallet_membership::Pallet::::name().as_bytes(), "StorageVersion".as_bytes(), )); - InactiveIssuance::::kill(); - // Set storage version to `4`. - StorageVersion::new(4).put::(); + StorageVersion::new(4) + .put::>(); log::info!(target: DEVELOPER_COMMITTEE_MEMBERSHIP_LOG_TARGET, "Storage to version 4"); T::DbWeight::get().reads_writes(1, 3) @@ -345,7 +352,11 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - ensure!(StorageVersion::get::() == 4, "Must upgrade"); + ensure!( + StorageVersion::get::>() + == 4, + "Must upgrade" + ); Ok(()) } } From 8be0f13694c19465663094dd66723fe3fe08e9e1 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sun, 29 Dec 2024 16:05:26 +0800 Subject: [PATCH 14/27] chore: fix --- .../runtime/litentry/src/migration/mod.rs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index f4d476005a..c40cf56b3d 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -161,7 +161,7 @@ where const BALANCES_LOG_TARGET: &str = "runtime::balances"; pub struct BalancesUpdateStorageVersionResetInactive(PhantomData); -impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive +impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive where T: frame_system::Config + pallet_balances::Config, { @@ -208,10 +208,10 @@ where } const BOUNTIES_LOG_TARGET: &str = "runtime::bounties"; -pub struct BountiesUpdateStorageVersion(PhantomData<(T, I)>); -impl OnRuntimeUpgrade for BountiesUpdateStorageVersion +pub struct BountiesUpdateStorageVersion(PhantomData); +impl OnRuntimeUpgrade for BountiesUpdateStorageVersion where - T: frame_system::Config + pallet_bounties::Config, + T: frame_system::Config + pallet_bounties::Config, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { @@ -254,15 +254,15 @@ where } const DEVELOPER_COMMITTEE_LOG_TARGET: &str = "runtime::collective3"; -pub struct DeveloperCommitteeUpdateStorageVersion(PhantomData<(T, I)>); -impl OnRuntimeUpgrade for DeveloperCommitteeUpdateStorageVersion +pub struct DeveloperCommitteeUpdateStorageVersion(PhantomData); +impl OnRuntimeUpgrade for DeveloperCommitteeUpdateStorageVersion where - T: frame_system::Config + pallet_collective::Config, + T: frame_system::Config + pallet_collective::Config, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { ensure!( - StorageVersion::get::>() + StorageVersion::get::>() == 0, "Already upgrade to some non-zero version" ); @@ -271,19 +271,19 @@ where fn on_runtime_upgrade() -> frame_support::weights::Weight { let on_chain_version = - pallet_collective::Pallet::::on_chain_storage_version( + pallet_collective::Pallet::::on_chain_storage_version( ); if on_chain_version == 0 { // Remove the old `StorageVersion` type. frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( - pallet_collective::Pallet::::name().as_bytes(), + pallet_collective::Pallet::::name().as_bytes(), "StorageVersion".as_bytes(), )); // Set storage version to `4`. StorageVersion::new(4) - .put::>(); + .put::>(); log::info!(target: DEVELOPER_COMMITTEE_LOG_TARGET, "Storage to version 4"); T::DbWeight::get().reads_writes(1, 3) @@ -299,7 +299,7 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { ensure!( - StorageVersion::get::>() + StorageVersion::get::>() == 4, "Must upgrade" ); @@ -308,10 +308,10 @@ where } const DEVELOPER_COMMITTEE_MEMBERSHIP_LOG_TARGET: &str = "runtime::membership3"; -pub struct DeveloperCommitteeMembershipUpdateStorageVersion(PhantomData<(T, I)>); -impl OnRuntimeUpgrade for DeveloperCommitteeMembershipUpdateStorageVersion +pub struct DeveloperCommitteeMembershipUpdateStorageVersion(PhantomData); +impl OnRuntimeUpgrade for DeveloperCommitteeMembershipUpdateStorageVersion where - T: frame_system::Config + pallet_collective::Config, + T: frame_system::Config + pallet_membership::Config, { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { From a7230bb2d845ee2b2e97ec7e71d1bb8b4e7d62ab Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sun, 29 Dec 2024 16:14:54 +0800 Subject: [PATCH 15/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index c40cf56b3d..2bb7a2f3a5 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -223,7 +223,7 @@ where } fn on_runtime_upgrade() -> frame_support::weights::Weight { - let on_chain_version = pallet_bounties::Pallet::::on_chain_storage_version(); + let on_chain_version = pallet_bounties::Pallet::::on_chain_storage_version(); if on_chain_version == 0 { // Remove the old `StorageVersion` type. From 77767515be9330904a63bf658de188a418a82198 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 2 Jan 2025 13:51:13 +0800 Subject: [PATCH 16/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 2bb7a2f3a5..e6b5f298b3 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -86,13 +86,13 @@ pub type Migrations = ( // V3 to V4 // XCMP QueueConfig has different default value // Migration targeting at changing storage value to new default value if old value matched - // Our current Paseo setting has already hard-coded + // Our current Litentry setting has already hard-coded // This migration should have no effect except bumping storage version cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, // V4 to V5 // Did nothing to storage // Just checking MaxActiveOutboundChannels is not exceeded - // Our current Paseo Storage is 0 + // Our current Litentry Storage is 0 // This migration should have no effect except bumping storage version cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, // PolkadotXcm V0 => V1 @@ -184,7 +184,8 @@ where "StorageVersion".as_bytes(), )); - InactiveIssuance::::kill(); + // For security purpose, we may not want to do this now + // InactiveIssuance::::kill(); // Set storage version to `1`. StorageVersion::new(1).put::>(); From 5a12c3a3ea47c3d7636e6e9409819a1d74b44857 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 2 Jan 2025 14:01:47 +0800 Subject: [PATCH 17/27] chore: fix --- .../runtime/litentry/src/migration/mod.rs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index e6b5f298b3..20b94cc1c0 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,11 +45,11 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use frame_support::traits::{ - Get, GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion, +use frame_support::{ + ensure, + traits::{Get, GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}, }; use frame_system::pallet_prelude::BlockNumberFor; -use pallet_balances::InactiveIssuance; use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] @@ -117,11 +117,11 @@ where BlockNumberFor: From, { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { log::info!("Pre check pallet scheduler storage only has two precise tasks leftover"); let one: BlockNumberFor = 3067200u32.into(); let two: BlockNumberFor = 2995200u32.into(); - for (when, vec_schedule) in >::iter() { + for (when, _vec_schedule) in >::iter() { assert!(when == one || when == two, "Extra schedule exists"); } Ok(Vec::::new()) @@ -146,7 +146,7 @@ where } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { let one: BlockNumberFor = 3067200u32.into(); let two: BlockNumberFor = 2995200u32.into(); for (when, vec_schedule) in >::iter() { @@ -166,7 +166,7 @@ where T: frame_system::Config + pallet_balances::Config, { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { ensure!( StorageVersion::get::>() == 0, "Already upgrade to some non-zero version" @@ -202,7 +202,7 @@ where } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { ensure!(StorageVersion::get::>() == 1, "Must upgrade"); Ok(()) } @@ -215,7 +215,7 @@ where T: frame_system::Config + pallet_bounties::Config, { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { ensure!( StorageVersion::get::>() == 0, "Already upgrade to some non-zero version" @@ -248,7 +248,7 @@ where } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { ensure!(StorageVersion::get::>() == 4, "Must upgrade"); Ok(()) } @@ -261,7 +261,7 @@ where T: frame_system::Config + pallet_collective::Config, { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { ensure!( StorageVersion::get::>() == 0, @@ -298,7 +298,7 @@ where } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { ensure!( StorageVersion::get::>() == 4, @@ -315,7 +315,7 @@ where T: frame_system::Config + pallet_membership::Config, { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { ensure!( StorageVersion::get::>() == 0, @@ -352,7 +352,7 @@ where } #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { ensure!( StorageVersion::get::>() == 4, From 13fd353e8f5879e4f2ea12fa435ee5fbee969248 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 2 Jan 2025 14:21:05 +0800 Subject: [PATCH 18/27] chore: fix --- parachain/Cargo.lock | 1 + parachain/node/Cargo.toml | 2 ++ parachain/runtime/litentry/Cargo.toml | 1 - parachain/runtime/litentry/src/migration/mod.rs | 2 +- parachain/runtime/paseo/Cargo.toml | 1 - 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index 570f9b7e5c..908e8da5dc 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -5692,6 +5692,7 @@ dependencies = [ "frame-benchmarking-cli", "frame-support", "frame-system-rpc-runtime-api", + "frame-try-runtime", "futures 0.3.30", "jsonrpsee", "litentry-parachain-runtime", diff --git a/parachain/node/Cargo.toml b/parachain/node/Cargo.toml index 1ff4a6d02c..b81edacd32 100644 --- a/parachain/node/Cargo.toml +++ b/parachain/node/Cargo.toml @@ -105,6 +105,7 @@ xcm = { workspace = true } frame-benchmarking = { workspace = true } frame-benchmarking-cli = { workspace = true } frame-system-rpc-runtime-api = { workspace = true } +frame-try-runtime = { workspace = true, optional = true } core-primitives = { workspace = true, features = ["std"] } litentry-parachain-runtime = { workspace = true, features = ["std"] } @@ -148,5 +149,6 @@ try-runtime = [ "polkadot-service/try-runtime", "runtime-common/try-runtime", "sp-runtime/try-runtime", + "frame-try-runtime", ] std = [] diff --git a/parachain/runtime/litentry/Cargo.toml b/parachain/runtime/litentry/Cargo.toml index d1f8b10039..b82890181a 100644 --- a/parachain/runtime/litentry/Cargo.toml +++ b/parachain/runtime/litentry/Cargo.toml @@ -308,7 +308,6 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime", - "frame-try-runtime?/try-runtime", "hex", "pallet-account-fix/try-runtime", "pallet-asset-manager/try-runtime", diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 20b94cc1c0..2c4f116c80 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -149,7 +149,7 @@ where fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { let one: BlockNumberFor = 3067200u32.into(); let two: BlockNumberFor = 2995200u32.into(); - for (when, vec_schedule) in >::iter() { + for (when, _vec_schedule) in >::iter() { assert!(when != one && when != two, "Old schedule still exists"); } diff --git a/parachain/runtime/paseo/Cargo.toml b/parachain/runtime/paseo/Cargo.toml index 2fb76e12e4..1fc6d5fa19 100644 --- a/parachain/runtime/paseo/Cargo.toml +++ b/parachain/runtime/paseo/Cargo.toml @@ -353,7 +353,6 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime", - "frame-try-runtime?/try-runtime", "pallet-account-fix/try-runtime", "pallet-asset-manager/try-runtime", "pallet-assets-handler/try-runtime", From a0c104f1bd1642c32dfea553457a27847a22bc0f Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 2 Jan 2025 14:44:22 +0800 Subject: [PATCH 19/27] chore: clippy --- parachain/runtime/litentry/src/migration/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 2c4f116c80..ea9df9af11 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -45,9 +45,10 @@ // In try-runtime, current implementation, the storage version is not checked, // Pallet version is used instead. -use frame_support::{ - ensure, - traits::{Get, GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}, +#[cfg(feature = "try-runtime")] +use frame_support::ensure; +use frame_support::traits::{ + Get, GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion, }; use frame_system::pallet_prelude::BlockNumberFor; use pallet_scheduler::Agenda; From 093c82ec704a26acd0f161de08102950f7ba0023 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 14:36:20 +0800 Subject: [PATCH 20/27] chore: add preimage clean --- .../runtime/litentry/src/migration/mod.rs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index ea9df9af11..df3f8c1b05 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -68,6 +68,8 @@ pub type Migrations = ( // Does not matter if we do have old storage or not // Should simply works pallet_multisig::migrations::v1::MigrateToV1, + // Clean correpted preimage storage + RemoveCorreptedPreimageStorage, // Preimage V0 => V1 // Migrate old StatusFor and PreimageFor Storage into new Storage pallet_preimage::migration::v1::Migration, @@ -129,6 +131,7 @@ where } fn on_runtime_upgrade() -> frame_support::weights::Weight { + log::info!("Begin cleaning pallet scheduler storage two precise tasks leftover"); // Remove Scheduler Storage precisely of according block agenda only // TODO: Very Weak safety let one: BlockNumberFor = 3067200u32.into(); @@ -148,6 +151,7 @@ where #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!("Post check pallet scheduler storage two precise tasks cleaned"); let one: BlockNumberFor = 3067200u32.into(); let two: BlockNumberFor = 2995200u32.into(); for (when, _vec_schedule) in >::iter() { @@ -160,6 +164,95 @@ where } } +/// The original data layout of the preimage pallet without a specific version number. +mod preimage_helper { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[derive(Clone, Eq, PartialEq, Encode, Decode, TypeInfo, MaxEncodedLen, RuntimeDebug)] + pub enum OldRequestStatus { + Unrequested(Option<(AccountId, Balance)>), + Requested(u32), + } + + #[storage_alias] + pub type PreimageFor = StorageMap< + Pallet, + Identity, + ::Hash, + BoundedVec>, + >; + + #[storage_alias] + pub type StatusFor = StorageMap< + Pallet, + Identity, + ::Hash, + OldRequestStatus<::AccountId, BalanceOf>, + >; + + /// Returns the number of images or `None` if the storage is corrupted. + #[cfg(feature = "try-runtime")] + pub fn image_count() -> (u32, u32) { + let images = PreimageFor::::iter_values().count() as u32; + let status = StatusFor::::iter_values().count() as u32; + + (images, status) + } +} + +const PREIMAGE_LOG_TARGET: &str = "runtime::preimage"; +pub struct RemoveCorreptedPreimageStorage(PhantomData); +impl OnRuntimeUpgrade for RemoveCorreptedPreimageStorage +where + T: frame_system::Config + pallet_preimage::Config, +{ + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + let (image, status) = preimage_helper::image_count::(); + assert!(image != status, "Preimage storage not correpted"); + Ok(Vec::::new()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + // Remove preimage correpted storage + // TODO: Very Weak safety + let mut weight = T::DbWeight::get().reads(1); + if StorageVersion::get::>() != 0 { + log::warn!( + target: TARGET, + "skipping MovePreimagesIntoBuckets: executed on wrong storage version.\ + Expected version 0" + ); + return weight; + } + + let status = preimage_helper::StatusFor::::drain().collect::>(); + weight.saturating_accrue(T::DbWeight::get().reads(status.len() as u64)); + + let preimages = preimage_helper::PreimageFor::::drain().collect::>(); + weight.saturating_accrue(T::DbWeight::get().reads(preimages.len() as u64)); + + for (hash, status) in status.into_iter() { + if preimages.get(&hash).is_none() { + log::info!(target: PREIMAGE_LOG_TARGET, "Clean status for hash {:?}", &hash); + preimage_helper::StatusFor::::remove(hash); + }; + weight + .saturating_accrue(::DbWeight::get().reads_writes(1, 1)); + } + weight + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { + let (image, status) = preimage_helper::image_count::(); + assert!(image == status, "Preimage storage still correpted"); + + Ok(()) + } +} + const BALANCES_LOG_TARGET: &str = "runtime::balances"; pub struct BalancesUpdateStorageVersionResetInactive(PhantomData); impl OnRuntimeUpgrade for BalancesUpdateStorageVersionResetInactive From 8fd12b040178e059d77f9f6318d83736b75a6d98 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 15:11:11 +0800 Subject: [PATCH 21/27] chore: fix --- .../runtime/litentry/src/migration/mod.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index df3f8c1b05..0ddad09e1d 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -166,8 +166,8 @@ where /// The original data layout of the preimage pallet without a specific version number. mod preimage_helper { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; + use alloc::collections::btree_map::BTreeMap; + use frame_support::{pallet_prelude::*, storage_alias}; #[derive(Clone, Eq, PartialEq, Encode, Decode, TypeInfo, MaxEncodedLen, RuntimeDebug)] pub enum OldRequestStatus { @@ -176,24 +176,24 @@ mod preimage_helper { } #[storage_alias] - pub type PreimageFor = StorageMap< - Pallet, - Identity, + pub type PreimageFor = StorageMap< + pallet_preimage::Pallet, + pallet_preimage::Identity, ::Hash, - BoundedVec>, + BoundedVec>, >; #[storage_alias] pub type StatusFor = StorageMap< - Pallet, - Identity, + pallet_preimage::Pallet, + pallet_preimage::Identity, ::Hash, - OldRequestStatus<::AccountId, BalanceOf>, + OldRequestStatus<::AccountId, pallet_preimage::BalanceOf>, >; /// Returns the number of images or `None` if the storage is corrupted. #[cfg(feature = "try-runtime")] - pub fn image_count() -> (u32, u32) { + pub fn image_count() -> (u32, u32) { let images = PreimageFor::::iter_values().count() as u32; let status = StatusFor::::iter_values().count() as u32; From 8983ba4c0a657cdedaae6913f502df1184ee784d Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 15:39:06 +0800 Subject: [PATCH 22/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 0ddad09e1d..a59ea116c2 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -167,7 +167,11 @@ where /// The original data layout of the preimage pallet without a specific version number. mod preimage_helper { use alloc::collections::btree_map::BTreeMap; - use frame_support::{pallet_prelude::*, storage_alias}; + use frame_support::{pallet_prelude::*, storage_alias, traits::Currency}; + + type BalanceOf = <::Currency as Currency< + ::AccountId, + >>::Balance; #[derive(Clone, Eq, PartialEq, Encode, Decode, TypeInfo, MaxEncodedLen, RuntimeDebug)] pub enum OldRequestStatus { @@ -178,7 +182,7 @@ mod preimage_helper { #[storage_alias] pub type PreimageFor = StorageMap< pallet_preimage::Pallet, - pallet_preimage::Identity, + Identity, ::Hash, BoundedVec>, >; @@ -186,9 +190,9 @@ mod preimage_helper { #[storage_alias] pub type StatusFor = StorageMap< pallet_preimage::Pallet, - pallet_preimage::Identity, + Identity, ::Hash, - OldRequestStatus<::AccountId, pallet_preimage::BalanceOf>, + OldRequestStatus<::AccountId, BalanceOf>, >; /// Returns the number of images or `None` if the storage is corrupted. From db6b60e5a79fdf3c33d521fa06136463d8963e49 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 15:41:44 +0800 Subject: [PATCH 23/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index a59ea116c2..329c90a8b4 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -55,6 +55,7 @@ use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] use sp_std::vec::Vec; +extern crate alloc; pub type Migrations = ( // Scheduler V0 => V4 @@ -219,10 +220,11 @@ where } fn on_runtime_upgrade() -> frame_support::weights::Weight { + use alloc::collections::btree_map::BTreeMap; // Remove preimage correpted storage // TODO: Very Weak safety let mut weight = T::DbWeight::get().reads(1); - if StorageVersion::get::>() != 0 { + if StorageVersion::get::>() != 0 { log::warn!( target: TARGET, "skipping MovePreimagesIntoBuckets: executed on wrong storage version.\ From 11fb7d12da42ddd6656484e894247d8a5535219d Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 15:50:13 +0800 Subject: [PATCH 24/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 329c90a8b4..4ad2b5bb27 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -55,7 +55,9 @@ use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] use sp_std::vec::Vec; + extern crate alloc; +use alloc::collections::btree_map::BTreeMap; pub type Migrations = ( // Scheduler V0 => V4 @@ -167,7 +169,6 @@ where /// The original data layout of the preimage pallet without a specific version number. mod preimage_helper { - use alloc::collections::btree_map::BTreeMap; use frame_support::{pallet_prelude::*, storage_alias, traits::Currency}; type BalanceOf = <::Currency as Currency< @@ -220,13 +221,12 @@ where } fn on_runtime_upgrade() -> frame_support::weights::Weight { - use alloc::collections::btree_map::BTreeMap; // Remove preimage correpted storage // TODO: Very Weak safety let mut weight = T::DbWeight::get().reads(1); if StorageVersion::get::>() != 0 { log::warn!( - target: TARGET, + target: PREIMAGE_LOG_TARGET, "skipping MovePreimagesIntoBuckets: executed on wrong storage version.\ Expected version 0" ); From 6ed3089b3484a0fae1b88ee6e345354e5bd57374 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 16:00:15 +0800 Subject: [PATCH 25/27] chore: fix clippy --- parachain/runtime/litentry/src/migration/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 4ad2b5bb27..48b324fb47 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -239,7 +239,7 @@ where let preimages = preimage_helper::PreimageFor::::drain().collect::>(); weight.saturating_accrue(T::DbWeight::get().reads(preimages.len() as u64)); - for (hash, status) in status.into_iter() { + for (hash, _status) in status.into_iter() { if preimages.get(&hash).is_none() { log::info!(target: PREIMAGE_LOG_TARGET, "Clean status for hash {:?}", &hash); preimage_helper::StatusFor::::remove(hash); From a975e7daf4baf008c8a7bc2bb30ed141f37672bc Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 16:27:31 +0800 Subject: [PATCH 26/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 48b324fb47..9ed75b85d3 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -240,7 +240,7 @@ where weight.saturating_accrue(T::DbWeight::get().reads(preimages.len() as u64)); for (hash, _status) in status.into_iter() { - if preimages.get(&hash).is_none() { + if !preimages.contains_key(&hash) { log::info!(target: PREIMAGE_LOG_TARGET, "Clean status for hash {:?}", &hash); preimage_helper::StatusFor::::remove(hash); }; From 68a4299f244661e55e15346034537214e5f40d8d Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 3 Jan 2025 16:55:40 +0800 Subject: [PATCH 27/27] chore: fix --- parachain/runtime/litentry/src/migration/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/parachain/runtime/litentry/src/migration/mod.rs b/parachain/runtime/litentry/src/migration/mod.rs index 9ed75b85d3..15209e348d 100644 --- a/parachain/runtime/litentry/src/migration/mod.rs +++ b/parachain/runtime/litentry/src/migration/mod.rs @@ -53,7 +53,6 @@ use frame_support::traits::{ use frame_system::pallet_prelude::BlockNumberFor; use pallet_scheduler::Agenda; use sp_std::marker::PhantomData; -#[cfg(feature = "try-runtime")] use sp_std::vec::Vec; extern crate alloc;