-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Westend state trie to version 1 #6336
Changes from 6 commits
a6b43bd
98eb976
6dda492
0d01e51
a94fc6a
e9c4cdf
21c9093
1b1ed4a
93a70d0
9b75e96
f9c7796
84416a8
24ede00
b48585c
99ed695
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,40 @@ 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>; | ||
type SignedFilter = Disable<Runtime>; | ||
|
||
// Use same weights as substrate ones. | ||
type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight<Runtime>; | ||
type MaxKeyLen = MigrationMaxKeyLen; | ||
} | ||
|
||
pub struct Disable<T>(sp_std::marker::PhantomData<T>); | ||
impl<T: frame_system::Config> frame_support::traits::EnsureOrigin<T::RuntimeOrigin> for Disable<T> { | ||
type Success = T::AccountId; | ||
fn try_origin(o: T::RuntimeOrigin) -> Result<Self::Success, T::RuntimeOrigin> { | ||
Err(o) | ||
} | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
fn try_successful_origin() -> Result<T::RuntimeOrigin, ()> { | ||
// Not correct but this should only cost more. | ||
Ok(T::RuntimeOrigin::root()) | ||
} | ||
} | ||
|
||
construct_runtime! { | ||
pub enum Runtime where | ||
Block = Block, | ||
|
@@ -1154,6 +1188,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, | ||
|
@@ -1231,6 +1268,7 @@ pub type Executive = frame_executive::Executive< | |
parachains_configuration::migration::v3::MigrateToV3<Runtime>, | ||
pallet_election_provider_multi_phase::migrations::v1::MigrateToV1<Runtime>, | ||
pallet_fast_unstake::migrations::v1::MigrateToV1<Runtime>, | ||
init_state_migration::InitMigrate, | ||
), | ||
>; | ||
/// The payload being signed in transactions. | ||
|
@@ -1836,3 +1874,42 @@ mod remote_tests { | |
ext.execute_with(|| Runtime::on_runtime_upgrade()); | ||
} | ||
} | ||
|
||
mod init_state_migration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have sudo on westend. We can set any of these manually as well FYI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, I think it is better to start it manually via sudo than bundling it with the migration. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like it to run the exact same way as it will be on kusama and polkadot, so without sudo |
||
use super::Runtime; | ||
use frame_support::traits::OnRuntimeUpgrade; | ||
use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess}; | ||
#[cfg(feature = "no_std")] | ||
use sp_std::prelude::*; | ||
|
||
/// Initialize an automatic migration process. | ||
pub struct InitMigrate; | ||
impl OnRuntimeUpgrade for InitMigrate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you put this into Substrate for future use or always copy&paste? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More copy&paste, I mean this is specific to the migration strategy of the chain. |
||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> { | ||
Ok(Default::default()) | ||
ggwpez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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(()) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks (my searching skills are definitely rather bad :( )