1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! # Migrations
18
//!
19
//! This module acts as a registry where each migration is defined. Each migration should implement
20
//! the "Migration" trait declared in the pallet-migrations crate.
21

            
22
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
23
use frame_system::pallet_prelude::BlockNumberFor;
24
use pallet_migrations::{GetMigrations, Migration};
25
use sp_std::{marker::PhantomData, prelude::*, vec};
26

            
27
pub struct MigrateToLatestXcmVersion<Runtime>(PhantomData<Runtime>);
28
impl<Runtime> Migration for MigrateToLatestXcmVersion<Runtime>
29
where
30
	pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>: OnRuntimeUpgrade,
31
{
32
3
	fn friendly_name(&self) -> &str {
33
3
		"MM_MigrateToV5XcmVersion"
34
3
	}
35

            
36
	fn migrate(&self, _available_weight: Weight) -> Weight {
37
		pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::on_runtime_upgrade()
38
	}
39

            
40
	#[cfg(feature = "try-runtime")]
41
	fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
42
		pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::pre_upgrade()
43
	}
44

            
45
	#[cfg(feature = "try-runtime")]
46
	fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
47
		pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::post_upgrade(state)
48
	}
49
}
50

            
51
pub struct CommonMigrations<Runtime>(PhantomData<Runtime>);
52

            
53
impl<Runtime> GetMigrations for CommonMigrations<Runtime>
54
where
55
	Runtime: pallet_xcm::Config
56
		+ pallet_transaction_payment::Config
57
		+ pallet_xcm_weight_trader::Config
58
		+ pallet_parachain_staking::Config,
59
	Runtime::AccountId: Default,
60
	BlockNumberFor<Runtime>: Into<u64>,
61
{
62
3
	fn get_migrations() -> Vec<Box<dyn Migration>> {
63
3
		// let migration_author_mapping_twox_to_blake = AuthorMappingTwoXToBlake::<Runtime> {
64
3
		// 	0: Default::default(),
65
3
		// };
66
3

            
67
3
		// let migration_parachain_staking_purge_stale_storage =
68
3
		// 	ParachainStakingPurgeStaleStorage::<Runtime>(Default::default());
69
3
		// let migration_parachain_staking_manual_exits =
70
3
		// 	ParachainStakingManualExits::<Runtime>(Default::default());
71
3
		// let migration_parachain_staking_increase_max_delegations_per_candidate =
72
3
		// 	ParachainStakingIncreaseMaxDelegationsPerCandidate::<Runtime>(Default::default());
73
3
		// let migration_parachain_staking_split_candidate_state =
74
3
		// 	ParachainStakingSplitCandidateState::<Runtime>(Default::default());
75
3
		// let migration_parachain_staking_patch_incorrect_delegation_sums =
76
3
		//	ParachainStakingPatchIncorrectDelegationSums::<Runtime>(Default::default());
77
3

            
78
3
		// let migration_scheduler_v3 = SchedulerMigrationV3::<Runtime>(Default::default());
79
3

            
80
3
		// let migration_base_fee = MigrateBaseFeePerGas::<Runtime>(Default::default());
81
3

            
82
3
		// TODO: this is a lot of allocation to do upon every get() call. this *should* be avoided
83
3
		// except when pallet_migrations undergoes a runtime upgrade -- but TODO: review
84
3

            
85
3
		// let migration_author_slot_filter_eligible_ratio_to_eligibility_count =
86
3
		// 	AuthorSlotFilterEligibleRatioToEligiblityCount::<Runtime>(Default::default());
87
3
		// let migration_author_mapping_add_keys_to_registration_info =
88
3
		// 	AuthorMappingAddKeysToRegistrationInfo::<Runtime>(Default::default());
89
3
		// let staking_delegator_state_requests =
90
3
		// 	ParachainStakingSplitDelegatorStateIntoDelegationScheduledRequests::<Runtime>(
91
3
		// 		Default::default(),
92
3
		// 	);
93
3
		// let migration_author_mapping_add_account_id_to_nimbus_lookup =
94
3
		//	AuthorMappingAddAccountIdToNimbusLookup::<Runtime>(Default::default());
95
3

            
96
3
		// let xcm_transactor_max_weight =
97
3
		// 	XcmTransactorMaxTransactWeight::<Runtime>(Default::default());
98
3

            
99
3
		// let asset_manager_units_with_asset_type =
100
3
		// 	AssetManagerUnitsWithAssetType::<Runtime>(Default::default());
101
3

            
102
3
		// let asset_manager_populate_asset_type_id_storage =
103
3
		// 	AssetManagerPopulateAssetTypeIdStorage::<Runtime>(Default::default());
104
3

            
105
3
		// let asset_manager_change_statemine_prefixes = AssetManagerChangeStateminePrefixes::<
106
3
		// 	Runtime,
107
3
		// 	StatemineParaIdInfo,
108
3
		// 	StatemineAssetsInstanceInfo,
109
3
		// >(Default::default());
110
3

            
111
3
		// let xcm_supported_assets = XcmPaymentSupportedAssets::<Runtime>(Default::default());
112
3

            
113
3
		// let migration_elasticity = MigrateBaseFeeElasticity::<Runtime>(Default::default());
114
3
		//let staking_at_stake_auto_compound =
115
3
		//	ParachainStakingMigrateAtStakeAutoCompound::<Runtime>(Default::default());
116
3

            
117
3
		//let scheduler_to_v4 = SchedulerMigrationV4::<Runtime>(Default::default());
118
3
		//let democracy_migration_hash_to_bounded_call =
119
3
		//	DemocracryMigrationHashToBoundedCall::<Runtime>(Default::default());
120
3
		//let preimage_migration_hash_to_bounded_call =
121
3
		//	PreimageMigrationHashToBoundedCall::<Runtime>(Default::default());
122
3
		//let asset_manager_to_xcm_v3 =
123
3
		//	PalletAssetManagerMigrateXcmV2ToV3::<Runtime>(Default::default());
124
3
		//let xcm_transactor_to_xcm_v3 =
125
3
		//	PalletXcmTransactorMigrateXcmV2ToV3::<Runtime>(Default::default());
126
3
		//let remove_min_bond_for_old_orbiter_collators =
127
3
		//	RemoveMinBondForOrbiterCollators::<Runtime>(Default::default());
128
3
		// let missing_balances_migrations = MissingBalancesMigrations::<Runtime>(Default::default());
129
3
		// let fix_pallet_versions =
130
3
		// 	FixIncorrectPalletVersions::<Runtime, Treasury, OpenTech>(Default::default());
131
3
		// let pallet_referenda_migrate_v0_to_v1 =
132
3
		// 	PalletReferendaMigrateV0ToV1::<Runtime>(Default::default());
133
3
		//let pallet_collective_drop_gov_v1_collectives =
134
3
		//	PalletCollectiveDropGovV1Collectives::<Runtime>(Default::default());
135
3
		//let pallet_staking_round = PalletStakingRoundMigration::<Runtime>(Default::default());
136
3

            
137
3
		vec![
138
3
			// completed in runtime 800
139
3
			// Box::new(migration_author_mapping_twox_to_blake),
140
3
			// completed in runtime 900
141
3
			// completed in runtime 1000
142
3
			// Box::new(migration_parachain_staking_purge_stale_storage),
143
3
			// completed in runtime 1000
144
3
			// Box::new(migration_parachain_staking_manual_exits),
145
3
			// completed in runtime 1101
146
3
			// Box::new(migration_parachain_staking_increase_max_delegations_per_candidate),
147
3
			// completed in runtime 1201
148
3
			// Box::new(migration_parachain_staking_split_candidate_state),
149
3
			// completed in runtime 1201
150
3
			// Box::new(xcm_transactor_max_weight),
151
3
			// completed in runtime 1201
152
3
			// Box::new(asset_manager_units_with_asset_type),
153
3
			// completed in runtime 1201
154
3
			// Box::new(asset_manager_change_statemine_prefixes),
155
3
			// completed in runtime 1201
156
3
			// Box::new(asset_manager_populate_asset_type_id_storage),
157
3
			// completed in runtime 1300
158
3
			// Box::new(migration_scheduler_v3),
159
3
			// completed in runtime 1300
160
3
			// Box::new(migration_parachain_staking_patch_incorrect_delegation_sums),
161
3
			// completed in runtime 1300
162
3
			// Box::new(migration_base_fee),
163
3
			// completed in runtime 1300
164
3
			// Box::new(xcm_supported_assets),
165
3
			// completed in runtime 1500
166
3
			// Box::new(migration_author_slot_filter_eligible_ratio_to_eligibility_count),
167
3
			// Box::new(migration_author_mapping_add_keys_to_registration_info),
168
3
			// Box::new(staking_delegator_state_requests),
169
3
			// completed in runtime 1600
170
3
			// Box::new(migration_author_mapping_add_account_id_to_nimbus_lookup),
171
3
			// completed in runtime 1600
172
3
			// Box::new(xcm_transactor_transact_signed),
173
3
			// completed in runtime 1700
174
3
			//Box::new(migration_elasticity),
175
3
			// completed in runtime 1900
176
3
			//Box::new(staking_at_stake_auto_compound),
177
3
			// completed in runtime 2000
178
3
			//Box::new(scheduler_to_v4),
179
3
			//Box::new(democracy_migration_hash_to_bounded_call),
180
3
			//Box::new(preimage_migration_hash_to_bounded_call),
181
3
			// completed in runtime 2100
182
3
			//Box::new(asset_manager_to_xcm_v3),
183
3
			//Box::new(xcm_transactor_to_xcm_v3),
184
3
			// completed in runtime 2600
185
3
			//Box::new(remove_min_bond_for_old_orbiter_collators),
186
3
			// completed in runtime 2700
187
3
			// Box::new(missing_balances_migrations),
188
3
			// Box::new(fix_pallet_versions),
189
3
			// Box::new(pallet_referenda_migrate_v0_to_v1),
190
3
			// completed in runtime 2800
191
3
			//Box::new(pallet_collective_drop_gov_v1_collectives),
192
3
			// completed in runtime 2801
193
3
			// Box::new(pallet_staking_round),
194
3
			// Box::new(pallet_collective_drop_gov_v1_collectives),
195
3
			// completed in runtime 2900
196
3
			// Box::new(remove_pallet_democracy),
197
3
			// Box::new(remove_collectives_addresses
198
3
			// completed in runtime 3200
199
3
			// Box::new(MigrateXcmFeesAssetsMeatdata::<Runtime>(Default::default())),
200
3
			// complete in runtime 3300
201
3
			// Box::new(MigrateCodeToStateTrieV1::<Runtime>(Default::default())),
202
3
			// Box::new(MigrateStakingParachainBondConfig::<Runtime>(Default::default())),
203
3

            
204
3
			// permanent migrations
205
3
			Box::new(MigrateToLatestXcmVersion::<Runtime>(Default::default())),
206
3
		]
207
3
	}
208
}