Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Statemine state migration runtime changes. #1743

Merged
merged 11 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 22 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions parachains/runtimes/assets/statemine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sp-session = { git = "https://github.com/paritytech/substrate", default-features
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-state-trie-migration = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
cheme marked this conversation as resolved.
Show resolved Hide resolved

# Polkadot
kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
Expand Down Expand Up @@ -143,6 +144,7 @@ std = [
"pallet-multisig/std",
"pallet-proxy/std",
"pallet-session/std",
"pallet-state-trie-migration/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
Expand Down
73 changes: 70 additions & 3 deletions parachains/runtimes/assets/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{AsEnsureOriginWithArg, EitherOfDiverse, InstanceFilter},
traits::{AsEnsureOriginWithArg, EitherOfDiverse, InstanceFilter, SortedMembers},
weights::{ConstantMultiplier, Weight},
PalletId, RuntimeDebug,
};
Expand Down Expand Up @@ -87,11 +87,11 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemine"),
impl_name: create_runtime_str!("statemine"),
authoring_version: 1,
spec_version: 9300,
spec_version: 9301,
cheme marked this conversation as resolved.
Show resolved Hide resolved
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 8,
state_version: 0,
state_version: 1,
Copy link
Member

Choose a reason for hiding this comment

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

We should feature gate this for now.

As the GCP is still deploying the chain on Rococo for testing.

};

/// The version information used to identify this runtime when compiled natively.
Expand Down Expand Up @@ -596,6 +596,8 @@ construct_runtime!(
// The main stage.
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,

StateTrieMigration: pallet_state_trie_migration = 52,
Copy link
Member

Choose a reason for hiding this comment

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

Should also be feature gated.

cheme marked this conversation as resolved.
Show resolved Hide resolved
}
);

Expand Down Expand Up @@ -979,3 +981,68 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
CheckInherents = CheckInherents,
}

parameter_types! {
cheme marked this conversation as resolved.
Show resolved Hide resolved
// 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 = 2_000 * CENTS;
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;
// An origin that can control the whole pallet: should be Root, or a part of your council.
type ControlOrigin = frame_system::EnsureSignedBy<RootMigController, AccountId>;
cheme marked this conversation as resolved.
Show resolved Hide resolved
// specific account for the migration, can trigger the signed migrations.
type SignedFilter = frame_system::EnsureSignedBy<MigController, AccountId>;
//type SignedFilter = frame_system::EnsureSigned<Self::AccountId>;
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 SignedFilter = frame_system::EnsureSigned<Self::AccountId>;


// Replace this with weight based on your runtime.
type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight<Runtime>;

type MaxKeyLen = MigrationMaxKeyLen;
}

pub struct MigController;
pub struct RootMigController;

const KEY_ROOT_MIG_CONTROLLER: [u8; 32] = [
82, 188, 113, 193, 236, 165, 53, 55, 73, 84, 45, 253, 240, 175, 151, 191, 118, 79, 156, 47, 68,
232, 96, 205, 72, 95, 28, 216, 100, 0, 246, 73,
];

const KEY_MIG_CONTROLLER: [u8; 32] = [
82, 188, 113, 193, 236, 165, 53, 55, 73, 84, 45, 253, 240, 175, 151, 191, 118, 79, 156, 47, 68,
232, 96, 205, 72, 95, 28, 216, 100, 0, 246, 73,
];

impl SortedMembers<AccountId> for RootMigController {
fn sorted_members() -> Vec<AccountId> {
// hardcoded key of controller for manual migration
vec![KEY_ROOT_MIG_CONTROLLER.into()]
}
}

impl SortedMembers<AccountId> for MigController {
fn sorted_members() -> Vec<AccountId> {
// hardcoded key of controller for manual migration
vec![KEY_MIG_CONTROLLER.into()]
}
}
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
pub struct MigController;
pub struct RootMigController;
const KEY_ROOT_MIG_CONTROLLER: [u8; 32] = [
82, 188, 113, 193, 236, 165, 53, 55, 73, 84, 45, 253, 240, 175, 151, 191, 118, 79, 156, 47, 68,
232, 96, 205, 72, 95, 28, 216, 100, 0, 246, 73,
];
const KEY_MIG_CONTROLLER: [u8; 32] = [
82, 188, 113, 193, 236, 165, 53, 55, 73, 84, 45, 253, 240, 175, 151, 191, 118, 79, 156, 47, 68,
232, 96, 205, 72, 95, 28, 216, 100, 0, 246, 73,
];
impl SortedMembers<AccountId> for RootMigController {
fn sorted_members() -> Vec<AccountId> {
// hardcoded key of controller for manual migration
vec![KEY_ROOT_MIG_CONTROLLER.into()]
}
}
impl SortedMembers<AccountId> for MigController {
fn sorted_members() -> Vec<AccountId> {
// hardcoded key of controller for manual migration
vec![KEY_MIG_CONTROLLER.into()]
}
}
frame_support::ord_parameter_types! {
pub const KEY_MIG_CONTROLLER = hex!("INSERT_HEX_STRING");
pub const KEY_ROOT_MIG_CONTROLLER = hex!("INSERT_HEX_STRING");
}
const KEY_ROOT_MIG_CONTROLLER: [u8; 32] = [
82, 188, 113, 193, 236, 165, 53, 55, 73, 84, 45, 253, 240, 175, 151, 191, 118, 79, 156, 47, 68,
232, 96, 205, 72, 95, 28, 216, 100, 0, 246, 73,
];
const KEY_MIG_CONTROLLER: [u8; 32] = [
82, 188, 113, 193, 236, 165, 53, 55, 73, 84, 45, 253, 240, 175, 151, 191, 118, 79, 156, 47, 68,
232, 96, 205, 72, 95, 28, 216, 100, 0, 246, 73,
];
impl SortedMembers<AccountId> for RootMigController {
fn sorted_members() -> Vec<AccountId> {
// hardcoded key of controller for manual migration
vec![KEY_ROOT_MIG_CONTROLLER.into()]
}
}
impl SortedMembers<AccountId> for MigController {
fn sorted_members() -> Vec<AccountId> {
// hardcoded key of controller for manual migration
vec![KEY_MIG_CONTROLLER.into()]
}
}


#[test]
fn ensure_key_ss58() {
use sp_core::crypto::Ss58Codec;
let acc =
AccountId::from_ss58check("5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs").unwrap();
let acc: &[u8] = acc.as_ref();
assert_eq!(acc, &KEY_MIG_CONTROLLER[..]);
let acc =
AccountId::from_ss58check("5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs").unwrap();
let acc: &[u8] = acc.as_ref();
assert_eq!(acc, &KEY_ROOT_MIG_CONTROLLER[..]);
// panic!("{:?}", acc);
}