From b1d55c688e9a8a2fbd155f0a9ddaba9766ad101c Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 17 Feb 2023 08:38:35 +0100 Subject: [PATCH 1/9] clean state_trie_migration from westend --- runtime/westend/Cargo.toml | 4 --- runtime/westend/src/lib.rs | 60 -------------------------------------- 2 files changed, 64 deletions(-) diff --git a/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index cb53fa136e97..9509d68992b5 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -65,7 +65,6 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma pallet-society = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking-reward-curve = { package = "pallet-staking-reward-curve", git = "https://github.com/paritytech/substrate", branch = "master" } -pallet-state-trie-migration = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -99,7 +98,6 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default hex-literal = "0.3.4" tiny-keccak = { version = "2.0.2", features = ["keccak"] } keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } serde_json = "1.0.81" remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master", package = "frame-remote-externalities" } tokio = { version = "1.24.2", features = ["macros"] } @@ -156,7 +154,6 @@ std = [ "pallet-session/std", "pallet-society/std", "pallet-staking/std", - "pallet-state-trie-migration/std", "pallet-sudo/std", "pallet-timestamp/std", "pallet-treasury/std", @@ -257,7 +254,6 @@ try-runtime = [ "pallet-session/try-runtime", "pallet-society/try-runtime", "pallet-staking/try-runtime", - "pallet-state-trie-migration/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-treasury/try-runtime", diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index cb2f3b6e04d8..d37697e259ca 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1097,19 +1097,6 @@ parameter_types! { pub const MigrationMaxKeyLen: u32 = 512; } -impl pallet_state_trie_migration::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type SignedDepositPerItem = MigrationSignedDepositPerItem; - type SignedDepositBase = MigrationSignedDepositBase; - type ControlOrigin = EnsureRoot; - type SignedFilter = frame_support::traits::NeverEnsureOrigin; - - // Use same weights as substrate ones. - type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; - type MaxKeyLen = MigrationMaxKeyLen; -} - construct_runtime! { pub enum Runtime where Block = Block, @@ -1178,9 +1165,6 @@ construct_runtime! { // Fast unstake pallet: extension to staking. FastUnstake: pallet_fast_unstake = 30, - // State trie migration pallet, only temporary. - StateTrieMigration: pallet_state_trie_migration = 35, - // Parachains pallets. Start indices at 40 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, @@ -1243,7 +1227,6 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { /// /// Should be cleared after every release. pub type Migrations = ( - init_state_migration::InitMigrate, // "Use 2D weights in XCM v3" pallet_xcm::migration::v1::MigrateToV1, parachains_ump::migration::v1::MigrateToV1, @@ -1907,46 +1890,3 @@ mod remote_tests { ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost)); } } - -mod init_state_migration { - use super::Runtime; - use frame_support::traits::OnRuntimeUpgrade; - use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess}; - #[cfg(not(feature = "std"))] - use sp_std::prelude::*; - - /// Initialize an automatic migration process. - pub struct InitMigrate; - impl OnRuntimeUpgrade for InitMigrate { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - frame_support::ensure!( - AutoLimits::::get().is_none(), - "Automigration already started." - ); - Ok(Default::default()) - } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - if MigrationProcess::::get() == Default::default() && - AutoLimits::::get().is_none() - { - AutoLimits::::put(Some(MigrationLimits { item: 160, size: 204800 })); - log::info!("Automatic trie migration started."); - ::DbWeight::get().reads_writes(2, 1) - } else { - log::info!("Automatic trie migration not started."); - ::DbWeight::get().reads(2) - } - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - frame_support::ensure!( - AutoLimits::::get().is_some(), - "Automigration started." - ); - Ok(()) - } - } -} From 893f458612248066cbf39bb813a8558a214ca8e0 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 17 Feb 2023 08:47:29 +0100 Subject: [PATCH 2/9] update cargo.lock --- Cargo.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7deb480ee375..8da3671fdf0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13278,7 +13278,6 @@ dependencies = [ "pallet-society", "pallet-staking", "pallet-staking-reward-curve", - "pallet-state-trie-migration", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -13317,7 +13316,6 @@ dependencies = [ "sp-std", "sp-tracing", "sp-transaction-pool", - "sp-trie", "sp-version", "substrate-wasm-builder", "tiny-keccak", From 10819c8842064af663109bcb7a8a5f9126a24c59 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 17 Feb 2023 08:59:41 +0100 Subject: [PATCH 3/9] Revert "clean state_trie_migration from westend" This reverts commit b1d55c688e9a8a2fbd155f0a9ddaba9766ad101c. --- runtime/westend/Cargo.toml | 4 +++ runtime/westend/src/lib.rs | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index 9509d68992b5..cb53fa136e97 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -65,6 +65,7 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma pallet-society = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking-reward-curve = { package = "pallet-staking-reward-curve", git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-state-trie-migration = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -98,6 +99,7 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default hex-literal = "0.3.4" tiny-keccak = { version = "2.0.2", features = ["keccak"] } keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } serde_json = "1.0.81" remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master", package = "frame-remote-externalities" } tokio = { version = "1.24.2", features = ["macros"] } @@ -154,6 +156,7 @@ std = [ "pallet-session/std", "pallet-society/std", "pallet-staking/std", + "pallet-state-trie-migration/std", "pallet-sudo/std", "pallet-timestamp/std", "pallet-treasury/std", @@ -254,6 +257,7 @@ try-runtime = [ "pallet-session/try-runtime", "pallet-society/try-runtime", "pallet-staking/try-runtime", + "pallet-state-trie-migration/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-treasury/try-runtime", diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index d37697e259ca..cb2f3b6e04d8 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1097,6 +1097,19 @@ parameter_types! { pub const MigrationMaxKeyLen: u32 = 512; } +impl pallet_state_trie_migration::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type SignedDepositPerItem = MigrationSignedDepositPerItem; + type SignedDepositBase = MigrationSignedDepositBase; + type ControlOrigin = EnsureRoot; + type SignedFilter = frame_support::traits::NeverEnsureOrigin; + + // Use same weights as substrate ones. + type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; + type MaxKeyLen = MigrationMaxKeyLen; +} + construct_runtime! { pub enum Runtime where Block = Block, @@ -1165,6 +1178,9 @@ construct_runtime! { // Fast unstake pallet: extension to staking. FastUnstake: pallet_fast_unstake = 30, + // State trie migration pallet, only temporary. + StateTrieMigration: pallet_state_trie_migration = 35, + // Parachains pallets. Start indices at 40 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, @@ -1227,6 +1243,7 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { /// /// Should be cleared after every release. pub type Migrations = ( + init_state_migration::InitMigrate, // "Use 2D weights in XCM v3" pallet_xcm::migration::v1::MigrateToV1, parachains_ump::migration::v1::MigrateToV1, @@ -1890,3 +1907,46 @@ mod remote_tests { ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost)); } } + +mod init_state_migration { + use super::Runtime; + use frame_support::traits::OnRuntimeUpgrade; + use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess}; + #[cfg(not(feature = "std"))] + use sp_std::prelude::*; + + /// Initialize an automatic migration process. + pub struct InitMigrate; + impl OnRuntimeUpgrade for InitMigrate { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + frame_support::ensure!( + AutoLimits::::get().is_none(), + "Automigration already started." + ); + Ok(Default::default()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + if MigrationProcess::::get() == Default::default() && + AutoLimits::::get().is_none() + { + AutoLimits::::put(Some(MigrationLimits { item: 160, size: 204800 })); + log::info!("Automatic trie migration started."); + ::DbWeight::get().reads_writes(2, 1) + } else { + log::info!("Automatic trie migration not started."); + ::DbWeight::get().reads(2) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + frame_support::ensure!( + AutoLimits::::get().is_some(), + "Automigration started." + ); + Ok(()) + } + } +} From 0d0ef739de8ad3f9bca33ee02ae2a96a7564c820 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 17 Feb 2023 09:59:27 +0100 Subject: [PATCH 4/9] cleanup. --- Cargo.lock | 1 + runtime/westend/Cargo.toml | 1 - runtime/westend/src/lib.rs | 34 +++++++++++++--------------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8da3671fdf0c..47a380693cab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13278,6 +13278,7 @@ dependencies = [ "pallet-society", "pallet-staking", "pallet-staking-reward-curve", + "pallet-state-trie-migration", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", diff --git a/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index cb53fa136e97..07c918a50615 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -99,7 +99,6 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default hex-literal = "0.3.4" tiny-keccak = { version = "2.0.2", features = ["keccak"] } keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } serde_json = "1.0.81" remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master", package = "frame-remote-externalities" } tokio = { version = "1.24.2", features = ["macros"] } diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index cb2f3b6e04d8..aafa14215e96 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1243,7 +1243,7 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { /// /// Should be cleared after every release. pub type Migrations = ( - init_state_migration::InitMigrate, + clean_state_migration::CleanMigrate, // "Use 2D weights in XCM v3" pallet_xcm::migration::v1::MigrateToV1, parachains_ump::migration::v1::MigrateToV1, @@ -1908,43 +1908,35 @@ mod remote_tests { } } -mod init_state_migration { +mod clean_state_migration { use super::Runtime; use frame_support::traits::OnRuntimeUpgrade; - use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess}; + use pallet_state_trie_migration::{AutoLimits, MigrationProcess, SignedMigrationMaxLimits}; #[cfg(not(feature = "std"))] use sp_std::prelude::*; /// Initialize an automatic migration process. - pub struct InitMigrate; - impl OnRuntimeUpgrade for InitMigrate { + pub struct CleanMigrate; + impl OnRuntimeUpgrade for CleanMigrate { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { - frame_support::ensure!( - AutoLimits::::get().is_none(), - "Automigration already started." - ); Ok(Default::default()) } fn on_runtime_upgrade() -> frame_support::weights::Weight { - if MigrationProcess::::get() == Default::default() && - AutoLimits::::get().is_none() - { - AutoLimits::::put(Some(MigrationLimits { item: 160, size: 204800 })); - log::info!("Automatic trie migration started."); - ::DbWeight::get().reads_writes(2, 1) - } else { - log::info!("Automatic trie migration not started."); - ::DbWeight::get().reads(2) - } + MigrationProcess::::kill(); + AutoLimits::::kill(); + SignedMigrationMaxLimits::::kill(); + ::DbWeight::get().writes(3) } #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { frame_support::ensure!( - AutoLimits::::get().is_some(), - "Automigration started." + !MigrationProcess::::exists() && + !AutoLimits::::exists() && + !SignedMigrationMaxLimits::::exists(), + "State migration clean.", ); Ok(()) } From 5289745d1592a14db0063d9ee111137473993f41 Mon Sep 17 00:00:00 2001 From: Emeric Chevalier Date: Fri, 17 Feb 2023 16:53:18 +0100 Subject: [PATCH 5/9] use storage_alias --- runtime/westend/src/lib.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index aafa14215e96..5018dc39a3fe 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1097,19 +1097,6 @@ parameter_types! { pub const MigrationMaxKeyLen: u32 = 512; } -impl pallet_state_trie_migration::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type SignedDepositPerItem = MigrationSignedDepositPerItem; - type SignedDepositBase = MigrationSignedDepositBase; - type ControlOrigin = EnsureRoot; - type SignedFilter = frame_support::traits::NeverEnsureOrigin; - - // Use same weights as substrate ones. - type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; - type MaxKeyLen = MigrationMaxKeyLen; -} - construct_runtime! { pub enum Runtime where Block = Block, @@ -1178,9 +1165,6 @@ construct_runtime! { // Fast unstake pallet: extension to staking. FastUnstake: pallet_fast_unstake = 30, - // State trie migration pallet, only temporary. - StateTrieMigration: pallet_state_trie_migration = 35, - // Parachains pallets. Start indices at 40 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, @@ -1910,13 +1894,24 @@ mod remote_tests { mod clean_state_migration { use super::Runtime; - use frame_support::traits::OnRuntimeUpgrade; - use pallet_state_trie_migration::{AutoLimits, MigrationProcess, SignedMigrationMaxLimits}; + use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade}; + use pallet_state_trie_migration::{Config, MigrationLimits, MigrationTask, Pallet}; + #[cfg(not(feature = "std"))] use sp_std::prelude::*; + #[storage_alias] + type AutoLimits = StorageValue, Option, ValueQuery>; + + #[storage_alias] + type MigrationProcess = StorageValue, MigrationTask, ValueQuery>; + + #[storage_alias] + type SignedMigrationMaxLimits = StorageValue, MigrationLimits, OptionQuery>; + /// Initialize an automatic migration process. pub struct CleanMigrate; + impl OnRuntimeUpgrade for CleanMigrate { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { @@ -1933,9 +1928,7 @@ mod clean_state_migration { #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { frame_support::ensure!( - !MigrationProcess::::exists() && - !AutoLimits::::exists() && - !SignedMigrationMaxLimits::::exists(), + !AutoLimits::::exists() && !SignedMigrationMaxLimits::::exists(), "State migration clean.", ); Ok(()) From d4c688acdddf29a09c79a4eef52ab4095128e5b3 Mon Sep 17 00:00:00 2001 From: Emeric Chevalier Date: Fri, 17 Feb 2023 16:54:18 +0100 Subject: [PATCH 6/9] Revert "use storage_alias" This reverts commit 5289745d1592a14db0063d9ee111137473993f41. --- runtime/westend/src/lib.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 5018dc39a3fe..aafa14215e96 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1097,6 +1097,19 @@ parameter_types! { pub const MigrationMaxKeyLen: u32 = 512; } +impl pallet_state_trie_migration::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type SignedDepositPerItem = MigrationSignedDepositPerItem; + type SignedDepositBase = MigrationSignedDepositBase; + type ControlOrigin = EnsureRoot; + type SignedFilter = frame_support::traits::NeverEnsureOrigin; + + // Use same weights as substrate ones. + type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; + type MaxKeyLen = MigrationMaxKeyLen; +} + construct_runtime! { pub enum Runtime where Block = Block, @@ -1165,6 +1178,9 @@ construct_runtime! { // Fast unstake pallet: extension to staking. FastUnstake: pallet_fast_unstake = 30, + // State trie migration pallet, only temporary. + StateTrieMigration: pallet_state_trie_migration = 35, + // Parachains pallets. Start indices at 40 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, @@ -1894,24 +1910,13 @@ mod remote_tests { mod clean_state_migration { use super::Runtime; - use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade}; - use pallet_state_trie_migration::{Config, MigrationLimits, MigrationTask, Pallet}; - + use frame_support::traits::OnRuntimeUpgrade; + use pallet_state_trie_migration::{AutoLimits, MigrationProcess, SignedMigrationMaxLimits}; #[cfg(not(feature = "std"))] use sp_std::prelude::*; - #[storage_alias] - type AutoLimits = StorageValue, Option, ValueQuery>; - - #[storage_alias] - type MigrationProcess = StorageValue, MigrationTask, ValueQuery>; - - #[storage_alias] - type SignedMigrationMaxLimits = StorageValue, MigrationLimits, OptionQuery>; - /// Initialize an automatic migration process. pub struct CleanMigrate; - impl OnRuntimeUpgrade for CleanMigrate { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { @@ -1928,7 +1933,9 @@ mod clean_state_migration { #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { frame_support::ensure!( - !AutoLimits::::exists() && !SignedMigrationMaxLimits::::exists(), + !MigrationProcess::::exists() && + !AutoLimits::::exists() && + !SignedMigrationMaxLimits::::exists(), "State migration clean.", ); Ok(()) From 6b53ed00a693608e1ab144d65027d336291babd0 Mon Sep 17 00:00:00 2001 From: Emeric Chevalier Date: Fri, 17 Feb 2023 17:08:00 +0100 Subject: [PATCH 7/9] Revert "Revert "use storage_alias"" This reverts commit d4c688acdddf29a09c79a4eef52ab4095128e5b3. --- runtime/westend/src/lib.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index aafa14215e96..5018dc39a3fe 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1097,19 +1097,6 @@ parameter_types! { pub const MigrationMaxKeyLen: u32 = 512; } -impl pallet_state_trie_migration::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type SignedDepositPerItem = MigrationSignedDepositPerItem; - type SignedDepositBase = MigrationSignedDepositBase; - type ControlOrigin = EnsureRoot; - type SignedFilter = frame_support::traits::NeverEnsureOrigin; - - // Use same weights as substrate ones. - type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; - type MaxKeyLen = MigrationMaxKeyLen; -} - construct_runtime! { pub enum Runtime where Block = Block, @@ -1178,9 +1165,6 @@ construct_runtime! { // Fast unstake pallet: extension to staking. FastUnstake: pallet_fast_unstake = 30, - // State trie migration pallet, only temporary. - StateTrieMigration: pallet_state_trie_migration = 35, - // Parachains pallets. Start indices at 40 to leave room. ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, Configuration: parachains_configuration::{Pallet, Call, Storage, Config} = 42, @@ -1910,13 +1894,24 @@ mod remote_tests { mod clean_state_migration { use super::Runtime; - use frame_support::traits::OnRuntimeUpgrade; - use pallet_state_trie_migration::{AutoLimits, MigrationProcess, SignedMigrationMaxLimits}; + use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade}; + use pallet_state_trie_migration::{Config, MigrationLimits, MigrationTask, Pallet}; + #[cfg(not(feature = "std"))] use sp_std::prelude::*; + #[storage_alias] + type AutoLimits = StorageValue, Option, ValueQuery>; + + #[storage_alias] + type MigrationProcess = StorageValue, MigrationTask, ValueQuery>; + + #[storage_alias] + type SignedMigrationMaxLimits = StorageValue, MigrationLimits, OptionQuery>; + /// Initialize an automatic migration process. pub struct CleanMigrate; + impl OnRuntimeUpgrade for CleanMigrate { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { @@ -1933,9 +1928,7 @@ mod clean_state_migration { #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { frame_support::ensure!( - !MigrationProcess::::exists() && - !AutoLimits::::exists() && - !SignedMigrationMaxLimits::::exists(), + !AutoLimits::::exists() && !SignedMigrationMaxLimits::::exists(), "State migration clean.", ); Ok(()) From 71b2f322ba9d514ea64f244d3dcadd88d1858804 Mon Sep 17 00:00:00 2001 From: Emeric Chevalier Date: Fri, 17 Feb 2023 17:50:56 +0100 Subject: [PATCH 8/9] Force alias. --- runtime/westend/src/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 5018dc39a3fe..044ee3083c4f 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1895,16 +1895,36 @@ mod remote_tests { mod clean_state_migration { use super::Runtime; use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade}; - use pallet_state_trie_migration::{Config, MigrationLimits, MigrationTask, Pallet}; + use pallet_state_trie_migration::MigrationLimits; #[cfg(not(feature = "std"))] use sp_std::prelude::*; + struct Pallet(sp_std::marker::PhantomData); + + impl frame_support::traits::PalletInfoAccess for Pallet { + fn index() -> usize { + 35 + } + fn name() -> &'static str { + "StateTrieMigration" + } + fn module_name() -> &'static str { + "pallet_state_trie_migration" + } + fn crate_version() -> frame_support::traits::CrateVersion { + frame_support::traits::CrateVersion { major: 4u16, minor: 0u8, patch: 0u8 } + } + } + #[storage_alias] type AutoLimits = StorageValue, Option, ValueQuery>; + // Actual type of value is `MigrationTask`, putting a dummy + // one to avoid the trait constraint on T. + // Since we only use `kill` it is fine. #[storage_alias] - type MigrationProcess = StorageValue, MigrationTask, ValueQuery>; + type MigrationProcess = StorageValue, u32, ValueQuery>; #[storage_alias] type SignedMigrationMaxLimits = StorageValue, MigrationLimits, OptionQuery>; From e4321f066e9dddadef712a52a65e8ec01b5a3147 Mon Sep 17 00:00:00 2001 From: Emeric Chevalier Date: Fri, 17 Feb 2023 18:15:14 +0100 Subject: [PATCH 9/9] magic --- runtime/westend/src/lib.rs | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 044ee3083c4f..92501007b910 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1900,34 +1900,17 @@ mod clean_state_migration { #[cfg(not(feature = "std"))] use sp_std::prelude::*; - struct Pallet(sp_std::marker::PhantomData); - - impl frame_support::traits::PalletInfoAccess for Pallet { - fn index() -> usize { - 35 - } - fn name() -> &'static str { - "StateTrieMigration" - } - fn module_name() -> &'static str { - "pallet_state_trie_migration" - } - fn crate_version() -> frame_support::traits::CrateVersion { - frame_support::traits::CrateVersion { major: 4u16, minor: 0u8, patch: 0u8 } - } - } - #[storage_alias] - type AutoLimits = StorageValue, Option, ValueQuery>; + type AutoLimits = StorageValue, ValueQuery>; // Actual type of value is `MigrationTask`, putting a dummy // one to avoid the trait constraint on T. // Since we only use `kill` it is fine. #[storage_alias] - type MigrationProcess = StorageValue, u32, ValueQuery>; + type MigrationProcess = StorageValue; #[storage_alias] - type SignedMigrationMaxLimits = StorageValue, MigrationLimits, OptionQuery>; + type SignedMigrationMaxLimits = StorageValue; /// Initialize an automatic migration process. pub struct CleanMigrate; @@ -1939,16 +1922,16 @@ mod clean_state_migration { } fn on_runtime_upgrade() -> frame_support::weights::Weight { - MigrationProcess::::kill(); - AutoLimits::::kill(); - SignedMigrationMaxLimits::::kill(); + MigrationProcess::kill(); + AutoLimits::kill(); + SignedMigrationMaxLimits::kill(); ::DbWeight::get().writes(3) } #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { frame_support::ensure!( - !AutoLimits::::exists() && !SignedMigrationMaxLimits::::exists(), + !AutoLimits::exists() && !SignedMigrationMaxLimits::exists(), "State migration clean.", ); Ok(())