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

Westend state trie to version 1 #6336

Merged
merged 15 commits into from
Jan 11, 2023
Next Next commit
Switch to state V1 and add state-trie-migration pallet with dummy manual
account.
cheme committed Nov 23, 2022
commit a6b43bd41663d1cc3e6bb1d3061a76378bd2a0c1
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
@@ -83,7 +84,7 @@ pallet-election-provider-support-benchmarking = { git = "https://github.com/pari
pallet-nomination-pools-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
hex-literal = { version = "0.3.4", optional = true }
hex-literal = { version = "0.3.4" }

runtime-common = { package = "polkadot-runtime-common", path = "../common", default-features = false }
primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false }
@@ -95,7 +96,6 @@ xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", defa
xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default-features = false }

[dev-dependencies]
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" }
@@ -155,6 +155,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",
@@ -219,7 +220,6 @@ runtime-benchmarks = [
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"hex-literal",
"xcm-builder/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
@@ -255,6 +255,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",
30 changes: 29 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
#[cfg(feature = "disable-runtime-api")]
apis: sp_version::create_apis_vec![[]],
transaction_version: 14,
state_version: 0,
state_version: 1,
};

/// The BABE epoch configuration at genesis.
@@ -1086,6 +1086,31 @@ 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 SignedDepositPerItem = MigrationSignedDepositPerItem;
type SignedDepositBase = MigrationSignedDepositBase;
type ControlOrigin = EnsureRoot<AccountId>;
// specific account for the migration, can trigger the signed migrations.
type SignedFilter = frame_system::EnsureSignedBy<MigController, AccountId>;

// Use same weights as substrate ones.
type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight<Runtime>;
type MaxKeyLen = MigrationMaxKeyLen;
}

frame_support::ord_parameter_types! {
pub const MigController: AccountId = AccountId::from(hex_literal::hex!("8888888888888888888888888888888888888888888888888888888888888888"));
Copy link
Member

Choose a reason for hiding this comment

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

When we are running an automatic migration, do we need the controller account?

Copy link
Contributor Author

@cheme cheme Nov 25, 2022

Choose a reason for hiding this comment

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

No, but I did not find a good way to disable its declaration (I tried to replace it with Sudo but the types are differents).

Copy link
Member

Choose a reason for hiding this comment

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

Can you not set signedfilter to ensure root?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I tried, but got expected struct _sp_runtime::AccountId32, found ()``.
Just SignedOrigin got a constraint Success = Self::AccountId.
Starting trying to map to a dummy account without creating a new controller, but end up thinking that if I would be using a dummy account anyway.
But maybe I can local implement a noop `EnsureOrigin` (thinking twice this looks more harmless than allowing someone even if we know noone have the key).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did this instead a94fc6a

}

construct_runtime! {
pub enum Runtime where
Block = Block,
@@ -1154,6 +1179,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<T>} = 42,