|
| 1 | +use super::*; |
| 2 | + |
| 3 | +pub struct RemoveCollectiveFlip; |
| 4 | +impl frame_support::traits::OnRuntimeUpgrade for RemoveCollectiveFlip { |
| 5 | + fn on_runtime_upgrade() -> Weight { |
| 6 | + use frame_support::storage::migration; |
| 7 | + // Remove the storage value `RandomMaterial` from removed pallet `RandomnessCollectiveFlip` |
| 8 | + migration::remove_storage_prefix(b"RandomnessCollectiveFlip", b"RandomMaterial", b""); |
| 9 | + <Runtime as frame_system::Config>::DbWeight::get().writes(1) |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +/// Migrate from `PalletVersion` to the new `StorageVersion` |
| 14 | +pub struct MigratePalletVersionToStorageVersion; |
| 15 | +impl frame_support::traits::OnRuntimeUpgrade for MigratePalletVersionToStorageVersion { |
| 16 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 17 | + frame_support::migrations::migrate_from_pallet_version_to_storage_version::< |
| 18 | + AllPalletsWithSystem, |
| 19 | + >(&RocksDbWeight::get()) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +impl frame_system::migrations::V2ToV3 for Runtime { |
| 24 | + type Pallet = System; |
| 25 | + type AccountId = AccountId; |
| 26 | + type Index = Index; |
| 27 | + type AccountData = pallet_balances::AccountData<Balance>; |
| 28 | +} |
| 29 | + |
| 30 | +pub struct SystemToTripleRefCount; |
| 31 | +impl frame_support::traits::OnRuntimeUpgrade for SystemToTripleRefCount { |
| 32 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 33 | + frame_system::migrations::migrate_from_dual_to_triple_ref_count::<Runtime, Runtime>() |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +pub struct GrandpaStoragePrefixMigration; |
| 38 | +impl frame_support::traits::OnRuntimeUpgrade for GrandpaStoragePrefixMigration { |
| 39 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 40 | + use frame_support::traits::PalletInfo; |
| 41 | + let name = <Runtime as frame_system::Config>::PalletInfo::name::<Grandpa>() |
| 42 | + .expect("grandpa is part of pallets in construct_runtime, so it has a name; qed"); |
| 43 | + pallet_grandpa::migrations::v4::migrate::<Runtime, &str>(name) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +const COUNCIL_OLD_PREFIX: &str = "Instance1Collective"; |
| 48 | +/// Migrate from `Instance1Collective` to the new pallet prefix `Council` |
| 49 | +pub struct CouncilStoragePrefixMigration; |
| 50 | +impl frame_support::traits::OnRuntimeUpgrade for CouncilStoragePrefixMigration { |
| 51 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 52 | + pallet_collective::migrations::v4::migrate::<Runtime, Council, _>(COUNCIL_OLD_PREFIX) |
| 53 | + } |
| 54 | + |
| 55 | + #[cfg(feature = "try-runtime")] |
| 56 | + fn pre_upgrade() -> Result<(), &'static str> { |
| 57 | + pallet_collective::migrations::v4::pre_migrate::<Council, _>(COUNCIL_OLD_PREFIX); |
| 58 | + Ok(()) |
| 59 | + } |
| 60 | + |
| 61 | + #[cfg(feature = "try-runtime")] |
| 62 | + fn post_upgrade() -> Result<(), &'static str> { |
| 63 | + pallet_collective::migrations::v4::post_migrate::<Council, _>(COUNCIL_OLD_PREFIX); |
| 64 | + Ok(()) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +const COUNCIL_MEMBERSHIP_OLD_PREFIX: &str = "Instance1Membership"; |
| 69 | +/// Migrate from `Instance1Membership` to the new pallet prefix `TechnicalMembership` |
| 70 | +pub struct CouncilMembershipStoragePrefixMigration; |
| 71 | +impl frame_support::traits::OnRuntimeUpgrade for CouncilMembershipStoragePrefixMigration { |
| 72 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 73 | + use frame_support::traits::PalletInfo; |
| 74 | + let name = <Runtime as frame_system::Config>::PalletInfo::name::<CouncilMembership>() |
| 75 | + .expect("CouncilMembership is part of runtime, so it has a name; qed"); |
| 76 | + pallet_membership::migrations::v4::migrate::<Runtime, CouncilMembership, _>( |
| 77 | + COUNCIL_MEMBERSHIP_OLD_PREFIX, |
| 78 | + name, |
| 79 | + ) |
| 80 | + } |
| 81 | + |
| 82 | + #[cfg(feature = "try-runtime")] |
| 83 | + fn pre_upgrade() -> Result<(), &'static str> { |
| 84 | + use frame_support::traits::PalletInfo; |
| 85 | + let name = <Runtime as frame_system::Config>::PalletInfo::name::<CouncilMembership>() |
| 86 | + .expect("CouncilMembership is part of runtime, so it has a name; qed"); |
| 87 | + pallet_membership::migrations::v4::pre_migrate::<CouncilMembership, _>( |
| 88 | + COUNCIL_MEMBERSHIP_OLD_PREFIX, |
| 89 | + name, |
| 90 | + ); |
| 91 | + Ok(()) |
| 92 | + } |
| 93 | + |
| 94 | + #[cfg(feature = "try-runtime")] |
| 95 | + fn post_upgrade() -> Result<(), &'static str> { |
| 96 | + use frame_support::traits::PalletInfo; |
| 97 | + let name = <Runtime as frame_system::Config>::PalletInfo::name::<CouncilMembership>() |
| 98 | + .expect("CouncilMembership is part of runtime, so it has a name; qed"); |
| 99 | + pallet_membership::migrations::v4::post_migrate::<CouncilMembership, _>( |
| 100 | + COUNCIL_MEMBERSHIP_OLD_PREFIX, |
| 101 | + name, |
| 102 | + ); |
| 103 | + Ok(()) |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +pub struct PalletTftPriceStoragePrefixMigration; |
| 108 | +impl frame_support::traits::OnRuntimeUpgrade for PalletTftPriceStoragePrefixMigration { |
| 109 | + fn on_runtime_upgrade() -> frame_support::weights::Weight { |
| 110 | + use frame_support::storage::migration; |
| 111 | + |
| 112 | + // Remove storage prefixes and all related items |
| 113 | + // The storage for pallet tft price has changed from U64F64 to u32 |
| 114 | + migration::remove_storage_prefix(b"TftPriceModule", b"TftPrice", b""); |
| 115 | + migration::remove_storage_prefix(b"TftPriceModule", b"AverageTftPrice", b""); |
| 116 | + pallet_tft_price::TftPriceHistory::<Runtime>::remove_all(None); |
| 117 | + pallet_tft_price::BufferRange::<Runtime>::put((0, 0)); |
| 118 | + |
| 119 | + // Reinsert some default values |
| 120 | + pallet_tft_price::TftPrice::<Runtime>::put(45); |
| 121 | + pallet_tft_price::AverageTftPrice::<Runtime>::put(45); |
| 122 | + |
| 123 | + <Runtime as frame_system::Config>::DbWeight::get().writes(2) |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; |
| 128 | +pub struct CustomOnRuntimeUpgrades; |
| 129 | +impl OnRuntimeUpgrade for CustomOnRuntimeUpgrades { |
| 130 | + fn on_runtime_upgrade() -> Weight { |
| 131 | + let mut weight = 0; |
| 132 | + |
| 133 | + // 1. RemoveCollectiveFlip |
| 134 | + frame_support::log::info!("ποΈ RemoveCollectiveFlip start"); |
| 135 | + weight += <RemoveCollectiveFlip as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 136 | + frame_support::log::info!("π RemoveCollectiveFlip end"); |
| 137 | + |
| 138 | + // 2. MigratePalletVersionToStorageVersion |
| 139 | + frame_support::log::info!("ποΈ MigratePalletVersionToStorageVersion start"); |
| 140 | + weight += <MigratePalletVersionToStorageVersion as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 141 | + frame_support::log::info!("π MigratePalletVersionToStorageVersion end"); |
| 142 | + |
| 143 | + // 3. GrandpaStoragePrefixMigration |
| 144 | + frame_support::log::info!("ποΈ GrandpaStoragePrefixMigration start"); |
| 145 | + frame_support::traits::StorageVersion::new(0).put::<Grandpa>(); |
| 146 | + weight += <GrandpaStoragePrefixMigration as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 147 | + frame_support::log::info!("π GrandpaStoragePrefixMigration end"); |
| 148 | + |
| 149 | + // 4. SystemToTripleRefCount |
| 150 | + frame_support::log::info!("ποΈ SystemToTripleRefCount start"); |
| 151 | + weight += <SystemToTripleRefCount as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 152 | + frame_support::log::info!("π SystemToTripleRefCount end"); |
| 153 | + |
| 154 | + // 5. CouncilStoragePrefixMigration |
| 155 | + frame_support::log::info!("ποΈ CouncilStoragePrefixMigration start"); |
| 156 | + frame_support::traits::StorageVersion::new(0).put::<Council>(); |
| 157 | + weight += <CouncilStoragePrefixMigration as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 158 | + frame_support::log::info!("π CouncilStoragePrefixMigration end"); |
| 159 | + |
| 160 | + // 6. CouncilMembershipStoragePrefixMigration |
| 161 | + frame_support::log::info!("ποΈ CouncilMembershipStoragePrefixMigration start"); |
| 162 | + frame_support::traits::StorageVersion::new(0).put::<CouncilMembership>(); |
| 163 | + weight += |
| 164 | + <CouncilMembershipStoragePrefixMigration as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 165 | + frame_support::log::info!("π CouncilMembershipStoragePrefixMigration end"); |
| 166 | + |
| 167 | + // 7. PalletTftPriceStoragePrefixMigration |
| 168 | + frame_support::log::info!("ποΈ PalletTftPriceStoragePrefixMigration start"); |
| 169 | + weight += <PalletTftPriceStoragePrefixMigration as OnRuntimeUpgrade>::on_runtime_upgrade(); |
| 170 | + frame_support::log::info!("π PalletTftPriceStoragePrefixMigration end"); |
| 171 | + |
| 172 | + weight |
| 173 | + } |
| 174 | +} |
0 commit comments