1
// Copyright 2019-2022 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_MigrateToLatestXcmVersion"
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
	Runtime::AccountId: Default,
57
	BlockNumberFor<Runtime>: Into<u64>,
58
{
59
3
	fn get_migrations() -> Vec<Box<dyn Migration>> {
60
3
		// let migration_author_mapping_twox_to_blake = AuthorMappingTwoXToBlake::<Runtime> {
61
3
		// 	0: Default::default(),
62
3
		// };
63
3

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

            
75
3
		// let migration_scheduler_v3 = SchedulerMigrationV3::<Runtime>(Default::default());
76
3

            
77
3
		// let migration_base_fee = MigrateBaseFeePerGas::<Runtime>(Default::default());
78
3

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

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

            
93
3
		// let xcm_transactor_max_weight =
94
3
		// 	XcmTransactorMaxTransactWeight::<Runtime>(Default::default());
95
3

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

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

            
102
3
		// let asset_manager_change_statemine_prefixes = AssetManagerChangeStateminePrefixes::<
103
3
		// 	Runtime,
104
3
		// 	StatemineParaIdInfo,
105
3
		// 	StatemineAssetsInstanceInfo,
106
3
		// >(Default::default());
107
3

            
108
3
		// let xcm_supported_assets = XcmPaymentSupportedAssets::<Runtime>(Default::default());
109
3

            
110
3
		// let migration_elasticity = MigrateBaseFeeElasticity::<Runtime>(Default::default());
111
3
		//let staking_at_stake_auto_compound =
112
3
		//	ParachainStakingMigrateAtStakeAutoCompound::<Runtime>(Default::default());
113
3

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

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