diff --git a/CHANGELOG.md b/CHANGELOG.md index a968daee7a..6578f07d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added +- Remove state-trie-migration pallet from kusama, add state trie migration to V1 on polkadot ([polkadot-fellows/runtimes#170](https://github.com/polkadot-fellows/runtimes/pull/170)) - Introduce chain spec generator ([polkadot-fellows/runtimes#127](https://github.com/polkadot-fellows/runtimes/pull/127)) - Add [Encointer](https://encointer.org) system parachain runtime, completing [RFC22](https://github.com/polkadot-fellows/RFCs/blob/main/text/ 0022-adopt-encointer-runtime.md) ([polkadot-fellows/runtimes#80](https://github.com/polkadot-fellows/runtimes/pull/80)) diff --git a/Cargo.lock b/Cargo.lock index 4ed11ea462..138a9ed681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9443,6 +9443,7 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-staking-reward-fn", "pallet-staking-runtime-api", + "pallet-state-trie-migration", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", @@ -13277,7 +13278,6 @@ dependencies = [ "pallet-society", "pallet-staking", "pallet-staking-runtime-api", - "pallet-state-trie-migration", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index 3457beaec4..a6f119469b 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -72,7 +72,6 @@ pallet-session = { default-features = false , version = "29.0.0" } pallet-society = { default-features = false, version = "29.0.0" } frame-support = { default-features = false , features = [ "tuples-96" ] , version = "29.0.0" } pallet-staking = { default-features = false , version = "29.0.0" } -pallet-state-trie-migration = { default-features = false , version = "30.0.0" } pallet-staking-runtime-api = { default-features = false , version = "15.0.0" } frame-system = { default-features = false , version = "29.0.0" } frame-system-rpc-runtime-api = { default-features = false , version = "27.0.0" } @@ -175,7 +174,6 @@ std = [ "pallet-society/std", "pallet-staking-runtime-api/std", "pallet-staking/std", - "pallet-state-trie-migration/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", @@ -246,7 +244,6 @@ runtime-benchmarks = [ "pallet-session-benchmarking/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-staking/runtime-benchmarks", - "pallet-state-trie-migration/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", @@ -300,7 +297,6 @@ try-runtime = [ "pallet-session/try-runtime", "pallet-society/try-runtime", "pallet-staking/try-runtime", - "pallet-state-trie-migration/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-treasury/try-runtime", diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 835f1a8adc..8469611408 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1541,27 +1541,6 @@ impl pallet_nomination_pools::Config for Runtime { type MaxPointsToBalance = MaxPointsToBalance; } -parameter_types! { - // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) - pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS; - pub const MigrationSignedDepositBase: Balance = 20 * CENTS * 100; - pub const MigrationMaxKeyLen: u32 = 512; -} - -impl pallet_state_trie_migration::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type RuntimeHoldReason = RuntimeHoldReason; - 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; -} - impl pallet_asset_rate::Config for Runtime { type WeightInfo = weights::pallet_asset_rate::WeightInfo; type RuntimeEvent = RuntimeEvent; @@ -1739,9 +1718,6 @@ construct_runtime! { Crowdloan: crowdloan = 73, Coretime: coretime = 74, - // State trie migration pallet, only temporary. - StateTrieMigration: pallet_state_trie_migration = 98, - // Pallet for sending XCM. XcmPallet: pallet_xcm = 99, @@ -1852,6 +1828,7 @@ pub mod migrations { } parameter_types! { + pub const StateTrieMigrationName: &'static str = "StateTrieMigration"; pub const ImOnlinePalletName: &'static str = "ImOnline"; } @@ -1968,6 +1945,7 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( + frame_support::migrations::RemovePallet, pallet_nomination_pools::migration::versioned::V7ToV8, pallet_staking::migrations::v14::MigrateToV14, parachains_configuration::migration::v10::MigrateToV10, @@ -3064,63 +3042,3 @@ mod remote_tests { }); } } - -mod init_state_migration { - use super::Runtime; - use frame_support::traits::OnRuntimeUpgrade; - use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess}; - - /// Initialize an automatic migration process. - pub struct InitMigrate; - impl OnRuntimeUpgrade for InitMigrate { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - use parity_scale_codec::Encode; - let migration_should_start = AutoLimits::::get().is_none() && - MigrationProcess::::get() == Default::default(); - Ok(migration_should_start.encode()) - } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - if AutoLimits::::get().is_some() { - log::warn!("Automatic trie migration already started, not proceeding."); - return ::DbWeight::get().reads(1) - }; - - if MigrationProcess::::get() != Default::default() { - log::warn!("MigrationProcess is not Default. Not proceeding."); - return ::DbWeight::get().reads(2) - }; - - // Migration is not already running and `MigraitonProcess` is Default. Ready to run - // migrations. - // - // We use limits to target 600ko proofs per block and - // avg 800_000_000_000 of weight per block. - // See spreadsheet 4800_400 in - // https://raw.githubusercontent.com/cheme/substrate/try-runtime-mig/ksm.ods - AutoLimits::::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 })); - log::info!("Automatic trie migration started."); - ::DbWeight::get().reads_writes(2, 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade( - migration_should_start_bytes: sp_std::vec::Vec, - ) -> Result<(), sp_runtime::DispatchError> { - use parity_scale_codec::Decode; - let migration_should_start: bool = - Decode::decode(&mut migration_should_start_bytes.as_slice()) - .expect("failed to decode migration should start"); - - if migration_should_start { - frame_support::ensure!( - AutoLimits::::get().is_some(), - sp_runtime::DispatchError::Other("Automigration did not start as expected.") - ); - } - - Ok(()) - } - } -} diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 4aae319eed..f6de7e364f 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -69,6 +69,7 @@ pallet-staking = { default-features = false , version = "29.0.0" } pallet-staking-reward-fn = { default-features = false, version = "20.0.0" } pallet-staking-reward-curve = { version = "11.0.0" } pallet-staking-runtime-api = { default-features = false , version = "15.0.0" } +pallet-state-trie-migration = { default-features = false , version = "30.0.0" } frame-system = { default-features = false , version = "29.0.0" } frame-system-rpc-runtime-api = { default-features = false , version = "27.0.0" } polkadot-runtime-constants = { package = "polkadot-runtime-constants", path = "constants", default-features = false } @@ -166,6 +167,7 @@ std = [ "pallet-staking-reward-fn/std", "pallet-staking-runtime-api/std", "pallet-staking/std", + "pallet-state-trie-migration/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", @@ -233,6 +235,7 @@ runtime-benchmarks = [ "pallet-scheduler/runtime-benchmarks", "pallet-session-benchmarking/runtime-benchmarks", "pallet-staking/runtime-benchmarks", + "pallet-state-trie-migration/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", @@ -282,6 +285,7 @@ try-runtime = [ "pallet-scheduler/try-runtime", "pallet-session/try-runtime", "pallet-staking/try-runtime", + "pallet-state-trie-migration/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-treasury/try-runtime", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 179575437b..0d5c2f94e4 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -151,7 +151,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 25, - state_version: 0, + state_version: 1, }; /// The BABE epoch configuration at genesis. @@ -1541,6 +1541,27 @@ impl frame_support::traits::OnRuntimeUpgrade for InitiateNominationPools { } } +parameter_types! { + // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) + pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS; + pub const MigrationSignedDepositBase: Balance = 20 * CENTS * 100; + pub const MigrationMaxKeyLen: u32 = 512; +} + +impl pallet_state_trie_migration::Config for Runtime { + type RuntimeHoldReason = RuntimeHoldReason; + 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; +} + impl pallet_asset_rate::Config for Runtime { type WeightInfo = weights::pallet_asset_rate::WeightInfo; type RuntimeEvent = RuntimeEvent; @@ -1697,6 +1718,9 @@ construct_runtime! { Auctions: auctions = 72, Crowdloan: crowdloan = 73, + // State trie migration pallet, only temporary. + StateTrieMigration: pallet_state_trie_migration = 98, + // Pallet for sending XCM. XcmPallet: pallet_xcm = 99, @@ -1843,6 +1867,7 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( + init_state_migration::InitMigrate, // Upgrade SessionKeys to exclude ImOnline key UpgradeSessionKeys, pallet_nomination_pools::migration::versioned::V7ToV8, @@ -3153,3 +3178,65 @@ mod remote_tests { }); } } + +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, sp_runtime::DispatchError> { + use parity_scale_codec::Encode; + let migration_should_start = AutoLimits::::get().is_none() && + MigrationProcess::::get() == Default::default(); + Ok(migration_should_start.encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + if AutoLimits::::get().is_some() { + log::warn!("Automatic trie migration already started, not proceeding."); + return ::DbWeight::get().reads(1) + }; + + if MigrationProcess::::get() != Default::default() { + log::warn!("MigrationProcess is not Default. Not proceeding."); + return ::DbWeight::get().reads(2) + }; + + // Migration is not already running and `MigraitonProcess` is Default. Ready to run + // migrations. + // + // We use limits to target 600ko proofs per block and + // avg 800_000_000_000 of weight per block. + // See spreadsheet 4800_400 in + // https://raw.githubusercontent.com/cheme/substrate/try-runtime-mig/ksm.ods + AutoLimits::::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 })); + log::info!("Automatic trie migration started."); + ::DbWeight::get().reads_writes(2, 1) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade( + migration_should_start_bytes: Vec, + ) -> Result<(), sp_runtime::DispatchError> { + use parity_scale_codec::Decode; + let migration_should_start: bool = + Decode::decode(&mut migration_should_start_bytes.as_slice()) + .expect("failed to decode migration should start"); + + if migration_should_start { + frame_support::ensure!( + AutoLimits::::get().is_some(), + sp_runtime::DispatchError::Other("Automigration did not start as expected.") + ); + } + + Ok(()) + } + } +}