-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix, rename and activate migration
- Loading branch information
Showing
5 changed files
with
56 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
pub mod add_initiated_at; | ||
pub mod v1; | ||
pub mod v2; | ||
|
||
use cf_runtime_upgrade_utilities::VersionedMigration; | ||
|
||
pub type PalletMigration<T, I> = | ||
(VersionedMigration<crate::Pallet<T, I>, add_initiated_at::Migration<T, I>, 0, 1>,); | ||
(VersionedMigration<crate::Pallet<T, I>, v2::Migration<T, I>, 1, 2>,); |
53 changes: 0 additions & 53 deletions
53
state-chain/pallets/cf-broadcast/src/migrations/add_initiated_at.rs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::*; | ||
use frame_support::{ | ||
migration, | ||
pallet_prelude::Weight, | ||
traits::{OnRuntimeUpgrade, PalletInfoAccess}, | ||
StoragePrefixedMap, | ||
}; | ||
use sp_std::marker::PhantomData; | ||
|
||
mod old { | ||
use super::*; | ||
use frame_support::{pallet_prelude::OptionQuery, Twox64Concat}; | ||
|
||
#[frame_support::storage_alias] | ||
pub type RequestCallbacks<T: Config<I>, I: 'static> = StorageMap< | ||
Pallet<T, I>, | ||
Twox64Concat, | ||
BroadcastId, | ||
<T as Config<I>>::BroadcastCallable, | ||
OptionQuery, | ||
>; | ||
} | ||
|
||
pub struct Migration<T: Config<I>, I: 'static>(PhantomData<(T, I)>); | ||
|
||
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> { | ||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
migration::move_prefix( | ||
&frame_support::storage::storage_prefix( | ||
Pallet::<T, I>::name().as_bytes(), | ||
b"RequestCallbacks", | ||
)[..], | ||
RequestSuccessCallbacks::<T, I>::storage_prefix(), | ||
); | ||
Weight::zero() | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<Vec<u8>, frame_support::sp_runtime::TryRuntimeError> { | ||
let count = old::RequestCallbacks::<T, I>::iter().count() as u32; | ||
Ok(count.encode()) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(state: Vec<u8>) -> Result<(), frame_support::sp_runtime::TryRuntimeError> { | ||
let old_count = u32::decode(&mut &*state).expect("Invalid data passed from pre_upgrade"); | ||
frame_support::ensure!( | ||
old_count == RequestSuccessCallbacks::<T, I>::iter().count() as u32, | ||
"Count mismatch" | ||
); | ||
Ok(()) | ||
} | ||
} |