Skip to content

Commit

Permalink
fix: update release version on runtime upgrade (#4281)
Browse files Browse the repository at this point in the history
* fix: update release version on runtime upgrade

* fix: use explicit VersionUpdate migration
  • Loading branch information
dandanlen authored Dec 5, 2023
1 parent a07d51f commit ecad751
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 169 deletions.
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>);

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 @@ -830,7 +830,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

0 comments on commit ecad751

Please sign in to comment.