mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 03:35:43 +00:00
migrations: prevent accidentally using unversioned migrations instead of VersionedMigration (#3835)
closes #1324 #### Problem Currently, it is possible to accidentally use inner unversioned migration instead of `VersionedMigration` since both implement `OnRuntimeUpgrade`. #### Solution With this change, we make it clear that value of `Inner` is not intended to be used directly. It is achieved by bounding `Inner` to new trait `UncheckedOnRuntimeUpgrade`, which has the same interface (except `unchecked_` prefix) as `OnRuntimeUpgrade`. #### `try-runtime` functions Since developers can implement `try-runtime` for `Inner` value in `VersionedMigration` and have custom logic for it, I added the same `try-runtime` functions to `UncheckedOnRuntimeUpgrade`. I looked for a ways to not duplicate functions, but couldn't find anything that doesn't significantly change the codebase. So I would appreciate If you have any suggestions to improve this cc @liamaharon @xlc polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
This commit is contained in:
@@ -17,7 +17,11 @@
|
||||
//! A module that is responsible for migration of storage.
|
||||
|
||||
use crate::configuration::{Config, Pallet};
|
||||
use frame_support::{pallet_prelude::*, traits::Defensive, weights::Weight};
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{Defensive, UncheckedOnRuntimeUpgrade},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{
|
||||
AsyncBackingParams, Balance, ExecutorParams, NodeFeatures, SessionIndex,
|
||||
@@ -26,8 +30,6 @@ use primitives::{
|
||||
use sp_runtime::Perbill;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
|
||||
use super::v9::V9HostConfiguration;
|
||||
// All configuration of the runtime with respect to paras.
|
||||
#[derive(Clone, Encode, PartialEq, Decode, Debug)]
|
||||
@@ -163,7 +165,7 @@ mod v10 {
|
||||
}
|
||||
|
||||
pub struct VersionUncheckedMigrateToV10<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for VersionUncheckedMigrateToV10<T> {
|
||||
impl<T: Config> UncheckedOnRuntimeUpgrade for VersionUncheckedMigrateToV10<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade() for HostConfiguration MigrateToV10");
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
|
||||
use crate::configuration::{self, Config, Pallet};
|
||||
use frame_support::{
|
||||
migrations::VersionedMigration, pallet_prelude::*, traits::Defensive, weights::Weight,
|
||||
migrations::VersionedMigration,
|
||||
pallet_prelude::*,
|
||||
traits::{Defensive, UncheckedOnRuntimeUpgrade},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{
|
||||
@@ -27,7 +30,6 @@ use primitives::{
|
||||
};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
use polkadot_core_primitives::Balance;
|
||||
use sp_arithmetic::Perbill;
|
||||
|
||||
@@ -176,7 +178,7 @@ pub type MigrateToV11<T> = VersionedMigration<
|
||||
>;
|
||||
|
||||
pub struct UncheckedMigrateToV11<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for UncheckedMigrateToV11<T> {
|
||||
impl<T: Config> UncheckedOnRuntimeUpgrade for UncheckedMigrateToV11<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade() for HostConfiguration MigrateToV11");
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::configuration::{self, migration::v11::V11HostConfiguration, Config, P
|
||||
use frame_support::{
|
||||
migrations::VersionedMigration,
|
||||
pallet_prelude::*,
|
||||
traits::{Defensive, OnRuntimeUpgrade},
|
||||
traits::{Defensive, UncheckedOnRuntimeUpgrade},
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::vstaging::SchedulerParams;
|
||||
@@ -70,7 +70,7 @@ pub type MigrateToV12<T> = VersionedMigration<
|
||||
|
||||
pub struct UncheckedMigrateToV12<T>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config> OnRuntimeUpgrade for UncheckedMigrateToV12<T> {
|
||||
impl<T: Config> UncheckedOnRuntimeUpgrade for UncheckedMigrateToV12<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
|
||||
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade() for HostConfiguration MigrateToV12");
|
||||
|
||||
Reference in New Issue
Block a user