Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
81 changes: 43 additions & 38 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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! {
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -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<T>} = 42,
Expand Down Expand Up @@ -1243,7 +1227,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" <https://github.com/paritytech/polkadot/pull/6134>
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
parachains_ump::migration::v1::MigrateToV1<Runtime>,
Expand Down Expand Up @@ -1908,43 +1892,64 @@ 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 frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade};
use pallet_state_trie_migration::MigrationLimits;

#[cfg(not(feature = "std"))]
use sp_std::prelude::*;

struct Pallet<T>(sp_std::marker::PhantomData<T>);

impl<T> frame_support::traits::PalletInfoAccess for Pallet<T> {
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 }
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct Pallet<T>(sp_std::marker::PhantomData<T>);
impl<T> frame_support::traits::PalletInfoAccess for Pallet<T> {
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<T> = StorageValue<Pallet<T>, Option<MigrationLimits>, ValueQuery>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type AutoLimits<T> = StorageValue<Pallet<T>, Option<MigrationLimits>, ValueQuery>;
type AutoLimits = StorageValue<StateTrieMigration, Option<MigrationLimits>, ValueQuery>;


// Actual type of value is `MigrationTask<T>`, putting a dummy
// one to avoid the trait constraint on T.
// Since we only use `kill` it is fine.
#[storage_alias]
type MigrationProcess<T> = StorageValue<Pallet<T>, u32, ValueQuery>;

#[storage_alias]
type SignedMigrationMaxLimits<T> = StorageValue<Pallet<T>, MigrationLimits, OptionQuery>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type MigrationProcess<T> = StorageValue<Pallet<T>, u32, ValueQuery>;
#[storage_alias]
type SignedMigrationMaxLimits<T> = StorageValue<Pallet<T>, MigrationLimits, OptionQuery>;
type MigrationProcess = StorageValue<StateTrieMigration, u32, ValueQuery>;
#[storage_alias]
type SignedMigrationMaxLimits = StorageValue<StateTrieMigration, MigrationLimits, OptionQuery>;


/// 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<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)
}
MigrationProcess::<Runtime>::kill();
AutoLimits::<Runtime>::kill();
SignedMigrationMaxLimits::<Runtime>::kill();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use storage_alias to have the definition of them without including the pallet.

<Runtime as frame_system::Config>::DbWeight::get().writes(3)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_some(),
"Automigration started."
!AutoLimits::<Runtime>::exists() && !SignedMigrationMaxLimits::<Runtime>::exists(),
"State migration clean.",
);
Ok(())
}
Expand Down