-
Notifications
You must be signed in to change notification settings - Fork 1.6k
scheduler: update storage migration #6963
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,29 +16,14 @@ | |
|
||
//! A module that is responsible for migration of storage. | ||
|
||
use crate::scheduler::{self, AssignmentKind, Config, Pallet, Scheduled}; | ||
use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight}; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use frame_support::traits::StorageVersion; | ||
|
||
/// The current storage version. | ||
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); | ||
|
||
/// Call this during the next runtime upgrade for this module. | ||
pub fn on_runtime_upgrade<T: Config>() -> Weight { | ||
let mut weight: Weight = Weight::zero(); | ||
|
||
if StorageVersion::get::<Pallet<T>>() == 0 { | ||
weight = weight | ||
.saturating_add(v1::migrate::<T>()) | ||
.saturating_add(T::DbWeight::get().writes(1)); | ||
StorageVersion::new(1).put::<Pallet<T>>(); | ||
} | ||
|
||
weight | ||
} | ||
|
||
mod v0 { | ||
use super::*; | ||
use crate::scheduler::{self, AssignmentKind}; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use primitives::{CoreIndex, GroupIndex, Id as ParaId}; | ||
|
||
#[derive(Encode, Decode)] | ||
|
@@ -58,11 +43,35 @@ mod v0 { | |
|
||
/// V1: Group index is dropped from the core assignment, it's explicitly computed during | ||
/// candidates processing. | ||
mod v1 { | ||
pub mod v1 { | ||
use super::*; | ||
use crate::scheduler::{self, Config, Pallet, Scheduled}; | ||
use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade, weights::Weight}; | ||
use sp_std::vec::Vec; | ||
|
||
pub fn migrate<T: Config>() -> Weight { | ||
pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>); | ||
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { | ||
fn on_runtime_upgrade() -> Weight { | ||
let mut weight: Weight = T::DbWeight::get().reads(1); | ||
|
||
if StorageVersion::get::<Pallet<T>>() < STORAGE_VERSION { | ||
log::info!(target: scheduler::LOG_TARGET, "Migrating scheduler storage to v1"); | ||
weight = weight | ||
.saturating_add(migrate::<T>()) | ||
.saturating_add(T::DbWeight::get().writes(1)); | ||
STORAGE_VERSION.put::<Pallet<T>>(); | ||
} else { | ||
log::info!( | ||
target: scheduler::LOG_TARGET, | ||
"Scheduler storage up to date - no need for migration" | ||
); | ||
} | ||
|
||
weight | ||
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. Should we account for the 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. Could also just initialise the weight to 1 read, since it needs to be accounted for regardless of what happens in the conditional |
||
} | ||
} | ||
|
||
fn migrate<T: Config>() -> Weight { | ||
let _ = Scheduled::<T>::translate(|scheduled: Option<Vec<v0::CoreAssignment>>| { | ||
scheduled.map(|scheduled| { | ||
scheduled.into_iter().map(|old| scheduler::CoreAssignment::from(old)).collect() | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1427,6 +1427,8 @@ pub type Migrations = ( | |||||||||||||||||||||||||
// Unreleased - add new migrations here: | ||||||||||||||||||||||||||
pallet_nomination_pools::migration::v5::MigrateToV5<Runtime>, | ||||||||||||||||||||||||||
parachains_configuration::migration::v5::MigrateToV5<Runtime>, | ||||||||||||||||||||||||||
/* Asynchronous backing mirgration */ | ||||||||||||||||||||||||||
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. nit: consistent comment syntax
Suggested change
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. This is intentional. Similar to polkadot/primitives/src/runtime_api.rs Lines 222 to 231 in fa0ad9a
Note that this PR targets feature branch, not master. Our migrations shouldn't be dropped unless applied on all networks, unlike migrations coming from master. |
||||||||||||||||||||||||||
parachains_scheduler::migration::v1::MigrateToV1<Runtime>, | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/// Unchecked extrinsic type as expected by this runtime. | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1495,7 +1495,11 @@ pub type UncheckedExtrinsic = | |||||
/// | ||||||
/// This contains the combined migrations of the last 10 releases. It allows to skip runtime | ||||||
/// upgrades in case governance decides to do so. | ||||||
pub type Migrations = parachains_configuration::migration::v5::MigrateToV5<Runtime>; | ||||||
pub type Migrations = ( | ||||||
parachains_configuration::migration::v5::MigrateToV5<Runtime>, | ||||||
/* Asynchronous backing mirgration */ | ||||||
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
|
||||||
parachains_scheduler::migration::v1::MigrateToV1<Runtime>, | ||||||
); | ||||||
|
||||||
/// Executive: handles dispatch to the various modules. | ||||||
pub type Executive = frame_executive::Executive< | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1224,6 +1224,8 @@ pub type Migrations = ( | |||||
// Unreleased - add new migrations here: | ||||||
pallet_nomination_pools::migration::v5::MigrateToV5<Runtime>, | ||||||
parachains_configuration::migration::v5::MigrateToV5<Runtime>, | ||||||
/* Asynchronous backing mirgration */ | ||||||
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
|
||||||
parachains_scheduler::migration::v1::MigrateToV1<Runtime>, | ||||||
); | ||||||
|
||||||
/// Unchecked extrinsic type as expected by this runtime. | ||||||
|
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.
nit: I think we should prefer consistent comment syntax?