From d2ba051b3f8c44ab079d7a2e69076fab162ed00a Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Thu, 9 May 2024 16:48:58 +0800 Subject: [PATCH 1/2] update state tire version to 1 --- Cargo.lock | 1 + Cargo.toml | 1 + runtime/mandala/Cargo.toml | 4 ++++ runtime/mandala/src/lib.rs | 31 ++++++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index adb0b2327..3e521dc86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6040,6 +6040,7 @@ dependencies = [ "pallet-root-testing", "pallet-scheduler", "pallet-session", + "pallet-state-trie-migration", "pallet-sudo", "pallet-timestamp", "pallet-tips", diff --git a/Cargo.toml b/Cargo.toml index a5d505c0d..c62949f33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -311,6 +311,7 @@ sp-weights = { version = "30.0.0", default-features = false } xcm = { version = "10.0.0", package = "staging-xcm", default-features = false } xcm-builder = { version = "10.0.0", package = "staging-xcm-builder", default-features = false } xcm-executor = { version = "10.0.0", package = "staging-xcm-executor", default-features = false } +pallet-state-trie-migration = { version = "32.0.0", default-features = false } # polkadot-sdk (client) cumulus-client-cli = { version = "0.10.0" } diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index f8cb1333d..e066bb211 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -58,6 +58,7 @@ sp-staking = { workspace = true } sp-std = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } +pallet-state-trie-migration = { workspace = true, optional = true } # cumulus cumulus-pallet-aura-ext = { workspace = true } @@ -208,6 +209,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "pallet-state-trie-migration/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", @@ -307,6 +309,7 @@ runtime-benchmarks = [ "pallet-utility/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", + "pallet-state-trie-migration/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", @@ -380,6 +383,7 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-treasury/try-runtime", "pallet-utility/try-runtime", + "pallet-state-trie-migration/try-runtime", "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index bedc91316..036ba6599 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { #[cfg(feature = "disable-runtime-api")] apis: sp_version::create_apis_vec![[]], transaction_version: 3, - state_version: 0, + state_version: 1, }; /// The version information used to identify this runtime when compiled @@ -1872,6 +1872,33 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +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 MigrationSignedDepositPerItem: Balance = dollar(ACA); + pub MigrationSignedDepositBase: Balance = dollar(ACA); + pub const MigrationMaxKeyLen: u32 = 512; +} + +frame_support::ord_parameter_types! { + // Empty account + pub const SignedFilterController: AccountId = AccountId::from(hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000000")); +} + +impl pallet_state_trie_migration::Config for Runtime { + // An origin that can control the whole pallet: should be Root, or a part of your council. + type ControlOrigin = EnsureRootOrTwoThirdsTechnicalCommittee; + // specific account for the migration, can trigger the signed migrations. + type SignedFilter = frame_system::EnsureSignedBy; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; + type MaxKeyLen = MigrationMaxKeyLen; + type SignedDepositPerItem = MigrationSignedDepositPerItem; + type SignedDepositBase = MigrationSignedDepositBase; + // Replace this with weight based on your runtime. + type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; +} + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] pub struct ConvertEthereumTx; @@ -2141,6 +2168,8 @@ construct_runtime!( // Parachain System, always put it at the end ParachainSystem: cumulus_pallet_parachain_system = 160, + StateTrieMigration: pallet_state_trie_migration = 254, + // Dev Sudo: pallet_sudo = 255, } From bf5525b1dc3679ea5b61b90b663e4898a903ed92 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 10 May 2024 11:12:06 +0800 Subject: [PATCH 2/2] use NeverEnsureOrigin --- runtime/mandala/src/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 036ba6599..79515d9fb 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1879,16 +1879,11 @@ parameter_types! { pub const MigrationMaxKeyLen: u32 = 512; } -frame_support::ord_parameter_types! { - // Empty account - pub const SignedFilterController: AccountId = AccountId::from(hex_literal::hex!("0000000000000000000000000000000000000000000000000000000000000000")); -} - impl pallet_state_trie_migration::Config for Runtime { // An origin that can control the whole pallet: should be Root, or a part of your council. type ControlOrigin = EnsureRootOrTwoThirdsTechnicalCommittee; // specific account for the migration, can trigger the signed migrations. - type SignedFilter = frame_system::EnsureSignedBy; + type SignedFilter = frame_support::traits::NeverEnsureOrigin; type RuntimeEvent = RuntimeEvent; type Currency = Balances; type RuntimeHoldReason = RuntimeHoldReason;