-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove state trie migration from kusama, add it to polkadot #170
Changes from 14 commits
00618f4
46601d5
2562c33
887198b
a5c6693
fb43dde
ee79954
43ed739
d0569ca
4c7d743
342e60a
f6a42bb
9cf2f52
fae1ddb
fdfb381
006653b
bbeb66b
b9269c0
7ad07a7
2a998dd
4c0d999
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 | ||||
---|---|---|---|---|---|---|
|
@@ -1466,26 +1466,6 @@ 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 = frame_support::traits::NeverEnsureOrigin<AccountId>; | ||||||
|
||||||
// Use same weights as substrate ones. | ||||||
type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight<Runtime>; | ||||||
type MaxKeyLen = MigrationMaxKeyLen; | ||||||
} | ||||||
|
||||||
impl pallet_asset_rate::Config for Runtime { | ||||||
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>; | ||||||
type RuntimeEvent = RuntimeEvent; | ||||||
|
@@ -1608,9 +1588,6 @@ construct_runtime! { | |||||
Auctions: auctions = 72, | ||||||
Crowdloan: crowdloan = 73, | ||||||
|
||||||
// State trie migration pallet, only temporary. | ||||||
StateTrieMigration: pallet_state_trie_migration = 98, | ||||||
|
||||||
// Pallet for sending XCM. | ||||||
XcmPallet: pallet_xcm = 99, | ||||||
|
||||||
|
@@ -1671,6 +1648,7 @@ pub mod migrations { | |||||
|
||||||
bkchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/// Unreleased migrations. Add new ones here: | ||||||
pub type Unreleased = ( | ||||||
crate::clean_state_migration::CleanMigrate, | ||||||
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.
Suggested change
|
||||||
pallet_nomination_pools::migration::versioned::V5toV6<Runtime>, | ||||||
pallet_nomination_pools::migration::versioned::V6ToV7<Runtime>, | ||||||
pallet_nomination_pools::migration::versioned::V7ToV8<Runtime>, | ||||||
|
@@ -2714,63 +2692,45 @@ mod remote_tests { | |||||
} | ||||||
} | ||||||
|
||||||
mod init_state_migration { | ||||||
mod clean_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. Now you can remove all of this code. 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. whoa looks amazing, thx |
||||||
use super::Runtime; | ||||||
use frame_support::traits::OnRuntimeUpgrade; | ||||||
use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess}; | ||||||
#[cfg(not(feature = "std"))] | ||||||
use sp_std::prelude::*; | ||||||
|
||||||
/// Initialize an automatic migration process. | ||||||
pub struct InitMigrate; | ||||||
impl OnRuntimeUpgrade for InitMigrate { | ||||||
use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade}; | ||||||
use pallet_state_trie_migration::MigrationLimits; | ||||||
use sp_std::vec::Vec; | ||||||
|
||||||
#[storage_alias] | ||||||
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 = StorageValue<StateTrieMigration, u32, ValueQuery>; | ||||||
|
||||||
#[storage_alias] | ||||||
type SignedMigrationMaxLimits = StorageValue<StateTrieMigration, MigrationLimits, OptionQuery>; | ||||||
|
||||||
pub struct CleanMigrate; | ||||||
|
||||||
impl OnRuntimeUpgrade for CleanMigrate { | ||||||
#[cfg(feature = "try-runtime")] | ||||||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::DispatchError> { | ||||||
use parity_scale_codec::Encode; | ||||||
let migration_should_start = AutoLimits::<Runtime>::get().is_none() && | ||||||
MigrationProcess::<Runtime>::get() == Default::default(); | ||||||
Ok(migration_should_start.encode()) | ||||||
Ok(Default::default()) | ||||||
} | ||||||
|
||||||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||||||
if AutoLimits::<Runtime>::get().is_some() { | ||||||
log::warn!("Automatic trie migration already started, not proceeding."); | ||||||
return <Runtime as frame_system::Config>::DbWeight::get().reads(1) | ||||||
}; | ||||||
|
||||||
if MigrationProcess::<Runtime>::get() != Default::default() { | ||||||
log::warn!("MigrationProcess is not Default. Not proceeding."); | ||||||
return <Runtime as frame_system::Config>::DbWeight::get().reads(2) | ||||||
}; | ||||||
|
||||||
// Migration is not already running and `MigraitonProcess` is Default. Ready to run | ||||||
// migrations. | ||||||
// | ||||||
// We use limits to target 600ko proofs per block and | ||||||
// avg 800_000_000_000 of weight per block. | ||||||
// See spreadsheet 4800_400 in | ||||||
// https://raw.githubusercontent.com/cheme/substrate/try-runtime-mig/ksm.ods | ||||||
AutoLimits::<Runtime>::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 })); | ||||||
log::info!("Automatic trie migration started."); | ||||||
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, 1) | ||||||
MigrationProcess::kill(); | ||||||
AutoLimits::kill(); | ||||||
SignedMigrationMaxLimits::kill(); | ||||||
<Runtime as frame_system::Config>::DbWeight::get().writes(3) | ||||||
} | ||||||
|
||||||
#[cfg(feature = "try-runtime")] | ||||||
fn post_upgrade( | ||||||
migration_should_start_bytes: Vec<u8>, | ||||||
) -> Result<(), sp_runtime::DispatchError> { | ||||||
use parity_scale_codec::Decode; | ||||||
let migration_should_start: bool = | ||||||
Decode::decode(&mut migration_should_start_bytes.as_slice()) | ||||||
.expect("failed to decode migration should start"); | ||||||
|
||||||
if migration_should_start { | ||||||
frame_support::ensure!( | ||||||
AutoLimits::<Runtime>::get().is_some(), | ||||||
sp_runtime::DispatchError::Other("Automigration did not start as expected.") | ||||||
); | ||||||
} | ||||||
|
||||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> { | ||||||
frame_support::ensure!( | ||||||
!AutoLimits::exists() && !SignedMigrationMaxLimits::exists(), | ||||||
"State migration clean.", | ||||||
); | ||||||
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.
We probably need to write some migration to remove all the old pallet storage items? There already exists the
RemovePallet
migration that we can use for this.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.
yes I will try to use the code we ran on westend