Skip to content

Commit

Permalink
set correct pallets storage version via migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs committed Nov 7, 2023
1 parent 19ce6b3 commit 5a182a7
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions runtime/vara/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use core::marker::PhantomData;

use crate::*;
use frame_support::{
pallet_prelude::StorageVersion,
traits::{GetStorageVersion, OnRuntimeUpgrade},
};
use sp_runtime::traits::Get;

pub struct NominationPoolsMigrationV4OldPallet;
Expand All @@ -26,15 +32,45 @@ impl Get<Perbill> for NominationPoolsMigrationV4OldPallet {
}
}

pub struct UpdatePalletsVersions<T>(PhantomData<T>);

impl<T: pallet_multisig::Config + pallet_nomination_pools::Config + pallet_bounties::Config>
OnRuntimeUpgrade for UpdatePalletsVersions<T>
{
fn on_runtime_upgrade() -> Weight {
// pallet_multisig
let onchain = pallet_multisig::Pallet::<T>::on_chain_storage_version();
if onchain == 0 {
log::info!("pallet_multisig onchain: {:?}", onchain);
StorageVersion::new(1).put::<pallet_multisig::Pallet<T>>();
}

let onchain = pallet_multisig::Pallet::<T>::on_chain_storage_version();
log::info!("pallet_multisig onchain: {:?}", onchain);

// pallet_nomination_pools
let onchain = pallet_nomination_pools::Pallet::<T>::on_chain_storage_version();
if onchain == 0 {
log::info!("pallet_nomination_pools onchain: {:?}", onchain);
StorageVersion::new(5).put::<pallet_nomination_pools::Pallet<T>>();
}

let onchain = pallet_nomination_pools::Pallet::<T>::on_chain_storage_version();
log::info!("pallet_nomination_pools onchain: {:?}", onchain);

// pallet_bounties
StorageVersion::new(4).put::<pallet_bounties::Pallet<T>>();

Weight::zero()
}
}

/// All migrations that will run on the next runtime upgrade.
///
/// Should be cleared after every release.
pub type Migrations = (
// unreleased
pallet_nomination_pools::migration::v4::MigrateV3ToV5<
Runtime,
NominationPoolsMigrationV4OldPallet,
>,
UpdatePalletsVersions<Runtime>,
pallet_offences::migration::v1::MigrateToV1<Runtime>,
pallet_gear_program::migrations::MigrateToV3<Runtime>,
);

0 comments on commit 5a182a7

Please sign in to comment.