Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update release version on runtime upgrade #4281

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions state-chain/pallets/cf-environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use cf_chains::{
};
use cf_primitives::{chains::assets::eth::Asset as EthAsset, NetworkEnvironment, SemVer};
use cf_traits::{CompatibleCfeVersions, GetBitcoinFeeInfo, NetworkEnvironmentProvider, SafeMode};
use frame_support::{
pallet_prelude::*,
traits::{OnRuntimeUpgrade, StorageVersion},
};
use frame_support::{pallet_prelude::*, traits::StorageVersion};
use frame_system::pallet_prelude::*;
pub use pallet::*;
use sp_std::{vec, vec::Vec};
Expand Down
47 changes: 35 additions & 12 deletions state-chain/pallets/cf-environment/src/migrations.rs
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>);
kylezs marked this conversation as resolved.
Show resolved Hide resolved

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 = ();
70 changes: 0 additions & 70 deletions state-chain/pallets/cf-environment/src/migrations/v3.rs

This file was deleted.

44 changes: 0 additions & 44 deletions state-chain/pallets/cf-environment/src/migrations/v4.rs

This file was deleted.

23 changes: 0 additions & 23 deletions state-chain/pallets/cf-environment/src/migrations/v5.rs

This file was deleted.

15 changes: 0 additions & 15 deletions state-chain/pallets/cf-environment/src/migrations/v6.rs

This file was deleted.

3 changes: 2 additions & 1 deletion state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ pub type Executive = frame_executive::Executive<
// We use the executive pallet because the `pre_upgrade` and `post_upgrade` hooks are noops
// for tuple migrations (like these).
type PalletMigrations = (
pallet_cf_environment::migrations::PalletMigration<Runtime>,
pallet_cf_environment::migrations::VersionUpdate<Runtime>,
pallet_cf_environment::migrations::PalletMigration,
pallet_cf_funding::migrations::PalletMigration<Runtime>,
pallet_cf_validator::migrations::PalletMigration<Runtime>,
pallet_cf_governance::migrations::PalletMigration<Runtime>,
Expand Down