-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update release version on runtime upgrade (#4281)
* fix: update release version on runtime upgrade * fix: use explicit VersionUpdate migration
- Loading branch information
Showing
7 changed files
with
38 additions
and
169 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,12 +1,35 @@ | ||
pub mod v3; | ||
pub mod v4; | ||
pub mod v5; | ||
pub mod v6; | ||
|
||
use cf_runtime_upgrade_utilities::VersionedMigration; | ||
|
||
pub type PalletMigration<T> = ( | ||
VersionedMigration<crate::Pallet<T>, v4::Migration<T>, 3, 4>, | ||
VersionedMigration<crate::Pallet<T>, v5::Migration<T>, 4, 5>, | ||
VersionedMigration<crate::Pallet<T>, v6::Migration<T>, 5, 6>, | ||
); | ||
use crate::{Config, Pallet}; | ||
use frame_support::traits::OnRuntimeUpgrade; | ||
#[cfg(feature = "try-runtime")] | ||
use frame_support::{sp_runtime, sp_runtime::traits::Get}; | ||
#[cfg(feature = "try-runtime")] | ||
use sp_std::prelude::*; | ||
|
||
pub struct VersionUpdate<T: Config>(sp_std::marker::PhantomData<T>); | ||
|
||
impl<T: Config> OnRuntimeUpgrade for VersionUpdate<T> { | ||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
Pallet::<T>::update_current_release_version(); | ||
frame_support::weights::Weight::zero() | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> { | ||
frame_support::ensure!( | ||
crate::CurrentReleaseVersion::<T>::get() < <T as Config>::CurrentReleaseVersion::get(), | ||
"Expected the release version to increase." | ||
); | ||
Ok(Default::default()) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> { | ||
frame_support::ensure!( | ||
crate::CurrentReleaseVersion::<T>::get() == <T as Config>::CurrentReleaseVersion::get(), | ||
"Expected the release version to be updated." | ||
); | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub type PalletMigration = (); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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