Westend state trie to version 1 (#6336)

* Switch to state V1 and add state-trie-migration pallet with dummy manual
account.

* Initialize limit on runtime upgrade.

* add prelude

* sp_std prelude only for no_std

* Disable filter for signed migration

* revert hex dep

* use NeverEnsureOrigin

* fix

* correct fix

* check init state in try-runtime

Co-authored-by: parity-processbot <>
This commit is contained in:
cheme
2023-01-11 13:13:33 +01:00
committed by GitHub
parent 15ecfb2c02
commit 403320269e
3 changed files with 72 additions and 1 deletions
+1
View File
@@ -13035,6 +13035,7 @@ dependencies = [
"pallet-society", "pallet-society",
"pallet-staking", "pallet-staking",
"pallet-staking-reward-curve", "pallet-staking-reward-curve",
"pallet-state-trie-migration",
"pallet-sudo", "pallet-sudo",
"pallet-timestamp", "pallet-timestamp",
"pallet-transaction-payment", "pallet-transaction-payment",
+3
View File
@@ -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-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 = { 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-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-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-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 } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -155,6 +156,7 @@ std = [
"pallet-session/std", "pallet-session/std",
"pallet-society/std", "pallet-society/std",
"pallet-staking/std", "pallet-staking/std",
"pallet-state-trie-migration/std",
"pallet-sudo/std", "pallet-sudo/std",
"pallet-timestamp/std", "pallet-timestamp/std",
"pallet-treasury/std", "pallet-treasury/std",
@@ -255,6 +257,7 @@ try-runtime = [
"pallet-session/try-runtime", "pallet-session/try-runtime",
"pallet-society/try-runtime", "pallet-society/try-runtime",
"pallet-staking/try-runtime", "pallet-staking/try-runtime",
"pallet-state-trie-migration/try-runtime",
"pallet-sudo/try-runtime", "pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime", "pallet-timestamp/try-runtime",
"pallet-treasury/try-runtime", "pallet-treasury/try-runtime",
+68 -1
View File
@@ -116,7 +116,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
#[cfg(feature = "disable-runtime-api")] #[cfg(feature = "disable-runtime-api")]
apis: sp_version::create_apis_vec![[]], apis: sp_version::create_apis_vec![[]],
transaction_version: 15, transaction_version: 15,
state_version: 0, state_version: 1,
}; };
/// The BABE epoch configuration at genesis. /// The BABE epoch configuration at genesis.
@@ -1085,6 +1085,26 @@ impl pallet_nomination_pools::Config for Runtime {
type MaxPointsToBalance = MaxPointsToBalance; 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 SignedDepositPerItem = MigrationSignedDepositPerItem;
type SignedDepositBase = MigrationSignedDepositBase;
type ControlOrigin = EnsureRoot<AccountId>;
type SignedFilter = frame_support::traits::NeverEnsureOrigin<AccountId>;
// Use same weights as substrate ones.
type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight<Runtime>;
type MaxKeyLen = MigrationMaxKeyLen;
}
construct_runtime! { construct_runtime! {
pub enum Runtime where pub enum Runtime where
Block = Block, Block = Block,
@@ -1153,6 +1173,9 @@ construct_runtime! {
// Fast unstake pallet: extension to staking. // Fast unstake pallet: extension to staking.
FastUnstake: pallet_fast_unstake = 30, 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. // Parachains pallets. Start indices at 40 to leave room.
ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41, ParachainsOrigin: parachains_origin::{Pallet, Origin} = 41,
Configuration: parachains_configuration::{Pallet, Call, Storage, Config<T>} = 42, Configuration: parachains_configuration::{Pallet, Call, Storage, Config<T>} = 42,
@@ -1223,6 +1246,7 @@ pub type Migrations = (
pallet_staking::migrations::v13::MigrateToV13<Runtime>, pallet_staking::migrations::v13::MigrateToV13<Runtime>,
parachains_disputes::migration::v1::MigrateToV1<Runtime>, parachains_disputes::migration::v1::MigrateToV1<Runtime>,
parachains_configuration::migration::v4::MigrateToV4<Runtime>, parachains_configuration::migration::v4::MigrateToV4<Runtime>,
init_state_migration::InitMigrate,
); );
/// Unchecked extrinsic type as expected by this runtime. /// Unchecked extrinsic type as expected by this runtime.
@@ -1843,3 +1867,46 @@ mod remote_tests {
ext.execute_with(|| Runtime::on_runtime_upgrade(true)); ext.execute_with(|| Runtime::on_runtime_upgrade(true));
} }
} }
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<Vec<u8>, &'static str> {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_none(),
"Automigration already started."
);
Ok(Default::default())
}
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if MigrationProcess::<Runtime>::get() == Default::default() &&
AutoLimits::<Runtime>::get().is_none()
{
AutoLimits::<Runtime>::put(Some(MigrationLimits { item: 160, size: 204800 }));
log::info!("Automatic trie migration started.");
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, 1)
} else {
log::info!("Automatic trie migration not started.");
<Runtime as frame_system::Config>::DbWeight::get().reads(2)
}
}
#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_some(),
"Automigration started."
);
Ok(())
}
}
}