mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +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,7 @@
|
||||
|
||||
use super::*;
|
||||
use crate::log;
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
use frame_support::traits::{OnRuntimeUpgrade, UncheckedOnRuntimeUpgrade};
|
||||
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
@@ -132,7 +132,7 @@ pub mod v8 {
|
||||
}
|
||||
|
||||
pub struct VersionUncheckedMigrateV7ToV8<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for VersionUncheckedMigrateV7ToV8<T> {
|
||||
impl<T: Config> UncheckedOnRuntimeUpgrade for VersionUncheckedMigrateV7ToV8<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
Ok(Vec::new())
|
||||
@@ -211,7 +211,7 @@ pub(crate) mod v7 {
|
||||
CountedStorageMap<Pallet<T>, Twox64Concat, PoolId, V7BondedPoolInner<T>>;
|
||||
|
||||
pub struct VersionUncheckedMigrateV6ToV7<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for VersionUncheckedMigrateV6ToV7<T> {
|
||||
impl<T: Config> UncheckedOnRuntimeUpgrade for VersionUncheckedMigrateV6ToV7<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let migrated = BondedPools::<T>::count();
|
||||
// The TVL should be the sum of all the funds that are actively staked and in the
|
||||
@@ -282,7 +282,7 @@ mod v6 {
|
||||
})
|
||||
}
|
||||
}
|
||||
impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> {
|
||||
impl<T: Config> UncheckedOnRuntimeUpgrade for MigrateToV6<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let mut success = 0u64;
|
||||
let mut fail = 0u64;
|
||||
|
||||
Reference in New Issue
Block a user