1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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
// Tanssi 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 Tanssi.  If not, see <http://www.gnu.org/licenses/>
16
// Copyright (C) Moondance Labs Ltd.
17
// This file is part of Tanssi.
18

            
19
// Tanssi is free software: you can redistribute it and/or modify
20
// it under the terms of the GNU General Public License as published by
21
// the Free Software Foundation, either version 3 of the License, or
22
// (at your option) any later version.
23

            
24
// Tanssi is distributed in the hope that it will be useful,
25
// but WITHOUT ANY WARRANTY; without even the implied warranty of
26
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
// GNU General Public License for more details.
28

            
29
// You should have received a copy of the GNU General Public License
30
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
31

            
32
//! # Migrations
33
//!
34
//! This module acts as a registry where each migration is defined. Each migration should implement
35
//! the "Migration" trait declared in the pallet-migrations crate.
36

            
37
#[cfg(feature = "try-runtime")]
38
use frame_support::ensure;
39
use frame_support::migration::move_pallet;
40
use {
41
    cumulus_primitives_core::ParaId,
42
    frame_support::{
43
        migration::{clear_storage_prefix, storage_key_iter},
44
        pallet_prelude::GetStorageVersion,
45
        traits::{
46
            fungible::MutateHold, OnRuntimeUpgrade, PalletInfoAccess, ReservableCurrency,
47
            StorageVersion,
48
        },
49
        weights::Weight,
50
        Blake2_128Concat, BoundedVec, StoragePrefixedMap,
51
    },
52
    pallet_configuration::{weights::WeightInfo as _, HostConfiguration},
53
    pallet_foreign_asset_creator::{AssetId, AssetIdToForeignAsset, ForeignAssetToAssetId},
54
    pallet_migrations::{GetMigrations, Migration},
55
    pallet_registrar::HoldReason,
56
    sp_core::Get,
57
    sp_runtime::Perbill,
58
    sp_std::{collections::btree_set::BTreeSet, marker::PhantomData, prelude::*},
59
};
60

            
61
#[derive(
62
    Default,
63
    Clone,
64
    parity_scale_codec::Encode,
65
    parity_scale_codec::Decode,
66
    PartialEq,
67
    sp_core::RuntimeDebug,
68
    scale_info::TypeInfo,
69
)]
70
pub struct HostConfigurationV2 {
71
    pub max_collators: u32,
72
    pub min_orchestrator_collators: u32,
73
    pub max_orchestrator_collators: u32,
74
    pub collators_per_container: u32,
75
    pub full_rotation_period: u32,
76
    pub collators_per_parathread: u32,
77
    pub parathreads_per_collator: u32,
78
    pub target_container_chain_fullness: Perbill,
79
}
80

            
81
pub struct MigrateConfigurationAddParachainPercentage<T>(pub PhantomData<T>);
82
impl<T> Migration for MigrateConfigurationAddParachainPercentage<T>
83
where
84
    T: pallet_configuration::Config,
85
{
86
2
    fn friendly_name(&self) -> &str {
87
2
        "TM_MigrateConfigurationAddParachainPercentage"
88
2
    }
89

            
90
1
    fn migrate(&self, _available_weight: Weight) -> Weight {
91
        const CONFIGURATION_ACTIVE_CONFIG_KEY: &[u8] =
92
            &hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385");
93
        const CONFIGURATION_PENDING_CONFIGS_KEY: &[u8] =
94
            &hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22d53b4123b2e186e07fb7bad5dda5f55c0");
95
1
        let default_config = HostConfiguration::default();
96
1

            
97
1
        // Modify active config
98
1
        let old_config: HostConfigurationV2 =
99
1
            frame_support::storage::unhashed::get(CONFIGURATION_ACTIVE_CONFIG_KEY)
100
1
                .expect("configuration.activeConfig should have value");
101
1
        let new_config = HostConfiguration {
102
1
            max_collators: old_config.max_collators,
103
1
            min_orchestrator_collators: old_config.min_orchestrator_collators,
104
1
            max_orchestrator_collators: old_config.max_orchestrator_collators,
105
1
            collators_per_container: old_config.collators_per_container,
106
1
            full_rotation_period: old_config.full_rotation_period,
107
1
            collators_per_parathread: old_config.collators_per_parathread,
108
1
            parathreads_per_collator: old_config.parathreads_per_collator,
109
1
            target_container_chain_fullness: old_config.target_container_chain_fullness,
110
1
            max_parachain_cores_percentage: default_config.max_parachain_cores_percentage,
111
1
        };
112
1
        frame_support::storage::unhashed::put(CONFIGURATION_ACTIVE_CONFIG_KEY, &new_config);
113
1

            
114
1
        // Modify pending configs, if any
115
1
        let old_pending_configs: Vec<(u32, HostConfigurationV2)> =
116
1
            frame_support::storage::unhashed::get(CONFIGURATION_PENDING_CONFIGS_KEY)
117
1
                .unwrap_or_default();
118
1
        let mut new_pending_configs: Vec<(u32, HostConfiguration)> = vec![];
119

            
120
3
        for (session_index, old_config) in old_pending_configs {
121
2
            let new_config = HostConfiguration {
122
2
                max_collators: old_config.max_collators,
123
2
                min_orchestrator_collators: old_config.min_orchestrator_collators,
124
2
                max_orchestrator_collators: old_config.max_orchestrator_collators,
125
2
                collators_per_container: old_config.collators_per_container,
126
2
                full_rotation_period: old_config.full_rotation_period,
127
2
                collators_per_parathread: old_config.collators_per_parathread,
128
2
                parathreads_per_collator: old_config.parathreads_per_collator,
129
2
                target_container_chain_fullness: old_config.target_container_chain_fullness,
130
2
                max_parachain_cores_percentage: default_config.max_parachain_cores_percentage,
131
2
            };
132
2
            new_pending_configs.push((session_index, new_config));
133
2
        }
134

            
135
1
        if !new_pending_configs.is_empty() {
136
1
            frame_support::storage::unhashed::put(
137
1
                CONFIGURATION_PENDING_CONFIGS_KEY,
138
1
                &new_pending_configs,
139
1
            );
140
1
        }
141

            
142
1
        <T as pallet_configuration::Config>::WeightInfo::set_config_with_u32()
143
1
    }
144

            
145
    /// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
146
    #[cfg(feature = "try-runtime")]
147
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
148
        const CONFIGURATION_ACTIVE_CONFIG_KEY: &[u8] =
149
            &hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385");
150

            
151
        let old_config_bytes =
152
            frame_support::storage::unhashed::get_raw(CONFIGURATION_ACTIVE_CONFIG_KEY)
153
                .expect("configuration.activeConfig should have value");
154
        // This works because there is no enum in the v2
155
        assert_eq!(
156
            old_config_bytes.len(),
157
            HostConfigurationV2::default().encoded_size()
158
        );
159

            
160
        use parity_scale_codec::Encode;
161
        Ok((old_config_bytes).encode())
162
    }
163

            
164
    /// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
165
    #[cfg(feature = "try-runtime")]
166
    fn post_upgrade(
167
        &self,
168
        _number_of_invulnerables: Vec<u8>,
169
    ) -> Result<(), sp_runtime::DispatchError> {
170
        let new_config = pallet_configuration::Pallet::<T>::config();
171
        let default_config = HostConfiguration::default();
172
        assert_eq!(
173
            new_config.max_parachain_cores_percentage,
174
            default_config.max_parachain_cores_percentage
175
        );
176
        Ok(())
177
    }
178
}
179

            
180
#[derive(
181
    Clone,
182
    parity_scale_codec::Encode,
183
    parity_scale_codec::Decode,
184
    PartialEq,
185
    sp_core::RuntimeDebug,
186
    scale_info::TypeInfo,
187
)]
188
struct HostConfigurationV1 {
189
    pub max_collators: u32,
190
    pub min_orchestrator_collators: u32,
191
    pub max_orchestrator_collators: u32,
192
    pub collators_per_container: u32,
193
    pub full_rotation_period: u32,
194
}
195

            
196
pub struct MigrateConfigurationParathreads<T>(pub PhantomData<T>);
197
impl<T> Migration for MigrateConfigurationParathreads<T>
198
where
199
    T: pallet_configuration::Config,
200
{
201
2
    fn friendly_name(&self) -> &str {
202
2
        "TM_MigrateConfigurationParathreads"
203
2
    }
204

            
205
1
    fn migrate(&self, _available_weight: Weight) -> Weight {
206
        const CONFIGURATION_ACTIVE_CONFIG_KEY: &[u8] =
207
            &hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385");
208
        const CONFIGURATION_PENDING_CONFIGS_KEY: &[u8] =
209
            &hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22d53b4123b2e186e07fb7bad5dda5f55c0");
210
1
        let default_config = HostConfiguration::default();
211
1

            
212
1
        // Modify active config
213
1
        let old_config: HostConfigurationV1 =
214
1
            frame_support::storage::unhashed::get(CONFIGURATION_ACTIVE_CONFIG_KEY)
215
1
                .expect("configuration.activeConfig should have value");
216
1
        let new_config = HostConfiguration {
217
1
            max_collators: old_config.max_collators,
218
1
            min_orchestrator_collators: old_config.min_orchestrator_collators,
219
1
            max_orchestrator_collators: old_config.max_orchestrator_collators,
220
1
            collators_per_container: old_config.collators_per_container,
221
1
            full_rotation_period: old_config.full_rotation_period,
222
1
            collators_per_parathread: default_config.collators_per_parathread,
223
1
            parathreads_per_collator: default_config.parathreads_per_collator,
224
1
            target_container_chain_fullness: default_config.target_container_chain_fullness,
225
1
            max_parachain_cores_percentage: default_config.max_parachain_cores_percentage,
226
1
        };
227
1
        frame_support::storage::unhashed::put(CONFIGURATION_ACTIVE_CONFIG_KEY, &new_config);
228
1

            
229
1
        // Modify pending configs, if any
230
1
        let old_pending_configs: Vec<(u32, HostConfigurationV1)> =
231
1
            frame_support::storage::unhashed::get(CONFIGURATION_PENDING_CONFIGS_KEY)
232
1
                .unwrap_or_default();
233
1
        let mut new_pending_configs: Vec<(u32, HostConfiguration)> = vec![];
234

            
235
3
        for (session_index, old_config) in old_pending_configs {
236
2
            let new_config = HostConfiguration {
237
2
                max_collators: old_config.max_collators,
238
2
                min_orchestrator_collators: old_config.min_orchestrator_collators,
239
2
                max_orchestrator_collators: old_config.max_orchestrator_collators,
240
2
                collators_per_container: old_config.collators_per_container,
241
2
                full_rotation_period: old_config.full_rotation_period,
242
2
                collators_per_parathread: default_config.collators_per_parathread,
243
2
                parathreads_per_collator: default_config.parathreads_per_collator,
244
2
                target_container_chain_fullness: default_config.target_container_chain_fullness,
245
2
                max_parachain_cores_percentage: default_config.max_parachain_cores_percentage,
246
2
            };
247
2
            new_pending_configs.push((session_index, new_config));
248
2
        }
249

            
250
1
        if !new_pending_configs.is_empty() {
251
1
            frame_support::storage::unhashed::put(
252
1
                CONFIGURATION_PENDING_CONFIGS_KEY,
253
1
                &new_pending_configs,
254
1
            );
255
1
        }
256

            
257
1
        <T as pallet_configuration::Config>::WeightInfo::set_config_with_u32()
258
1
    }
259

            
260
    /// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
261
    #[cfg(feature = "try-runtime")]
262
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
263
        const CONFIGURATION_ACTIVE_CONFIG_KEY: &[u8] =
264
            &hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385");
265

            
266
        let old_config_bytes =
267
            frame_support::storage::unhashed::get_raw(CONFIGURATION_ACTIVE_CONFIG_KEY)
268
                .expect("configuration.activeConfig should have value");
269
        assert_eq!(old_config_bytes.len(), 20);
270

            
271
        use parity_scale_codec::Encode;
272
        Ok((old_config_bytes).encode())
273
    }
274

            
275
    /// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
276
    #[cfg(feature = "try-runtime")]
277
    fn post_upgrade(
278
        &self,
279
        _number_of_invulnerables: Vec<u8>,
280
    ) -> Result<(), sp_runtime::DispatchError> {
281
        let new_config = pallet_configuration::Pallet::<T>::config();
282
        let default_config = HostConfiguration::default();
283
        assert_eq!(
284
            new_config.collators_per_parathread,
285
            default_config.collators_per_parathread
286
        );
287
        assert_eq!(
288
            new_config.parathreads_per_collator,
289
            default_config.collators_per_parathread
290
        );
291
        assert_eq!(
292
            new_config.target_container_chain_fullness,
293
            default_config.target_container_chain_fullness
294
        );
295

            
296
        Ok(())
297
    }
298
}
299

            
300
pub struct MigrateServicesPaymentAddCollatorAssignmentCredits<T>(pub PhantomData<T>);
301
impl<T> Migration for MigrateServicesPaymentAddCollatorAssignmentCredits<T>
302
where
303
    T: pallet_services_payment::Config + pallet_registrar::Config,
304
{
305
2
    fn friendly_name(&self) -> &str {
306
2
        "TM_MigrateServicesPaymentAddCollatorAssignmentCredits"
307
2
    }
308

            
309
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
310
2
        // For each parachain in pallet_registrar (active, pending or pending_verification),
311
2
        // insert `MaxCreditsStored` to pallet_services_payment,
312
2
        // and mark that parachain as "given_free_credits".
313
2
        let mut para_ids = BTreeSet::new();
314
2
        let active = pallet_registrar::RegisteredParaIds::<T>::get();
315
2
        let pending = pallet_registrar::PendingParaIds::<T>::get();
316
2

            
317
2
        let paused = pallet_registrar::Paused::<T>::get();
318
2
        para_ids.extend(active);
319
2
        para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
320
2
        para_ids.extend(paused);
321
2

            
322
2
        let reads = 3 + 2 * para_ids.len() as u64;
323
2
        let writes = 2 * para_ids.len() as u64;
324

            
325
6
        for para_id in para_ids {
326
4
            // 2 reads 2 writes
327
4
            pallet_services_payment::Pallet::<T>::set_free_collator_assignment_credits(
328
4
                &para_id,
329
4
                T::FreeCollatorAssignmentCredits::get(),
330
4
            );
331
4
        }
332

            
333
2
        let db_weights = T::DbWeight::get();
334
2
        db_weights.reads_writes(reads, writes)
335
2
    }
336
    /// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
337
    #[cfg(feature = "try-runtime")]
338
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
339
        let mut para_ids = BTreeSet::new();
340
        let active = pallet_registrar::RegisteredParaIds::<T>::get();
341
        let pending = pallet_registrar::PendingParaIds::<T>::get();
342
        let paused = pallet_registrar::Paused::<T>::get();
343
        para_ids.extend(active);
344
        para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
345
        para_ids.extend(paused);
346

            
347
        for para_id in para_ids {
348
            assert!(
349
                pallet_services_payment::CollatorAssignmentCredits::<T>::get(para_id).is_none()
350
            );
351
        }
352

            
353
        Ok(vec![])
354
    }
355

            
356
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
357
    #[cfg(feature = "try-runtime")]
358
    fn post_upgrade(&self, _result: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
359
        let mut para_ids = BTreeSet::new();
360
        let active = pallet_registrar::RegisteredParaIds::<T>::get();
361
        let pending = pallet_registrar::PendingParaIds::<T>::get();
362
        let paused = pallet_registrar::Paused::<T>::get();
363
        para_ids.extend(active);
364
        para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
365
        para_ids.extend(paused);
366

            
367
        for para_id in para_ids {
368
            assert_eq!(
369
                pallet_services_payment::CollatorAssignmentCredits::<T>::get(para_id),
370
                Some(T::FreeCollatorAssignmentCredits::get())
371
            );
372
        }
373

            
374
        Ok(())
375
    }
376
}
377

            
378
pub struct PolkadotXcmMigrationFixVersion<T, PolkadotXcm>(pub PhantomData<(T, PolkadotXcm)>);
379
impl<T, PolkadotXcm> Migration for PolkadotXcmMigrationFixVersion<T, PolkadotXcm>
380
where
381
    PolkadotXcm: GetStorageVersion + PalletInfoAccess,
382
    T: cumulus_pallet_xcmp_queue::Config,
383
{
384
266
    fn friendly_name(&self) -> &str {
385
266
        "MM_PolkadotXcmMigrationFixVersion"
386
266
    }
387

            
388
    fn migrate(&self, _available_weight: Weight) -> Weight {
389
        if <PolkadotXcm as GetStorageVersion>::on_chain_storage_version() == 0 {
390
            StorageVersion::new(1).put::<PolkadotXcm>();
391
            return T::DbWeight::get().writes(1);
392
        }
393
        Weight::default()
394
    }
395

            
396
    #[cfg(feature = "try-runtime")]
397
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
398
        ensure!(
399
            <PolkadotXcm as GetStorageVersion>::on_chain_storage_version() == 0,
400
            "PolkadotXcm storage version should be 0"
401
        );
402
        Ok(vec![])
403
    }
404

            
405
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
406
    #[cfg(feature = "try-runtime")]
407
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
408
        ensure!(
409
            <PolkadotXcm as GetStorageVersion>::on_chain_storage_version() == 1,
410
            "PolkadotXcm storage version should be 1"
411
        );
412
        Ok(())
413
    }
414
}
415

            
416
pub struct XcmpQueueMigrationFixVersion<T, XcmpQueue>(pub PhantomData<(T, XcmpQueue)>);
417
impl<T, XcmpQueue> Migration for XcmpQueueMigrationFixVersion<T, XcmpQueue>
418
where
419
    XcmpQueue: GetStorageVersion + PalletInfoAccess,
420
    T: cumulus_pallet_xcmp_queue::Config,
421
{
422
266
    fn friendly_name(&self) -> &str {
423
266
        "MM_XcmpQueueMigrationFixVersion"
424
266
    }
425

            
426
    fn migrate(&self, _available_weight: Weight) -> Weight {
427
        if <XcmpQueue as GetStorageVersion>::on_chain_storage_version() == 0 {
428
            StorageVersion::new(2).put::<XcmpQueue>();
429
            return T::DbWeight::get().writes(1);
430
        }
431
        Weight::default()
432
    }
433

            
434
    #[cfg(feature = "try-runtime")]
435
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
436
        ensure!(
437
            <XcmpQueue as GetStorageVersion>::on_chain_storage_version() == 0,
438
            "XcmpQueue storage version should be 0"
439
        );
440
        Ok(vec![])
441
    }
442

            
443
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
444
    #[cfg(feature = "try-runtime")]
445
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
446
        // Greater than because the post_upgrade is run after all the migrations, so
447
        // it can be greater if the following XcmpQueue migrations are applied in the
448
        // same runtime
449
        ensure!(
450
            <XcmpQueue as GetStorageVersion>::on_chain_storage_version() >= 2,
451
            "XcmpQueue storage version should be at least 2"
452
        );
453
        Ok(())
454
    }
455
}
456

            
457
pub struct XcmpQueueMigrationV3<T>(pub PhantomData<T>);
458
impl<T> Migration for XcmpQueueMigrationV3<T>
459
where
460
    T: cumulus_pallet_xcmp_queue::Config,
461
{
462
266
    fn friendly_name(&self) -> &str {
463
266
        "MM_XcmpQueueMigrationV3"
464
266
    }
465

            
466
    fn migrate(&self, _available_weight: Weight) -> Weight {
467
        cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3::<T>::on_runtime_upgrade()
468
    }
469

            
470
    // #[cfg(feature = "try-runtime")]
471
    // let mut pre_upgrade_result: Vec<u8>;
472

            
473
    #[cfg(feature = "try-runtime")]
474
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
475
        cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3::<T>::pre_upgrade()
476
    }
477

            
478
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
479
    #[cfg(feature = "try-runtime")]
480
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
481
        cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3::<T>::post_upgrade(state)
482
    }
483
}
484

            
485
pub struct XcmpQueueMigrationV4<T>(pub PhantomData<T>);
486
impl<T> Migration for XcmpQueueMigrationV4<T>
487
where
488
    T: cumulus_pallet_xcmp_queue::Config,
489
{
490
267
    fn friendly_name(&self) -> &str {
491
267
        "MM_XcmpQueueMigrationV4"
492
267
    }
493

            
494
    fn migrate(&self, _available_weight: Weight) -> Weight {
495
        cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::<T>::on_runtime_upgrade()
496
    }
497

            
498
    #[cfg(feature = "try-runtime")]
499
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
500
        cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::<T>::pre_upgrade()
501
    }
502

            
503
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
504
    #[cfg(feature = "try-runtime")]
505
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
506
        cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::<T>::post_upgrade(state)
507
    }
508
}
509

            
510
pub struct RegistrarPendingVerificationValueToMap<T>(pub PhantomData<T>);
511
impl<T> Migration for RegistrarPendingVerificationValueToMap<T>
512
where
513
    T: pallet_registrar::Config,
514
{
515
2
    fn friendly_name(&self) -> &str {
516
2
        "TM_RegistrarPendingVerificationValueToMap"
517
2
    }
518

            
519
1
    fn migrate(&self, _available_weight: Weight) -> Weight {
520
1
        let para_ids: Vec<ParaId> = frame_support::storage::unhashed::take(
521
1
            &frame_support::storage::storage_prefix(b"Registrar", b"PendingVerification"),
522
1
        )
523
1
        .unwrap_or_default();
524
1

            
525
1
        let total_weight = T::DbWeight::get()
526
1
            .reads(1)
527
1
            .saturating_add(T::DbWeight::get().writes(1));
528

            
529
5
        for para_id in para_ids {
530
4
            total_weight.saturating_add(T::DbWeight::get().writes(1));
531
4
            pallet_registrar::PendingVerification::<T>::insert(para_id, ());
532
4
        }
533

            
534
1
        total_weight
535
1
    }
536

            
537
    #[cfg(feature = "try-runtime")]
538
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
539
        Ok(vec![])
540
    }
541

            
542
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
543
    #[cfg(feature = "try-runtime")]
544
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
545
        Ok(())
546
    }
547
}
548

            
549
pub struct RegistrarParaManagerMigration<T>(pub PhantomData<T>);
550
impl<T> Migration for RegistrarParaManagerMigration<T>
551
where
552
    T: pallet_registrar::Config,
553
{
554
2
    fn friendly_name(&self) -> &str {
555
2
        "TM_RegistrarParaManagerMigration"
556
2
    }
557

            
558
    fn migrate(&self, _available_weight: Weight) -> Weight {
559
        let mut total_weight = Weight::default();
560
        for (para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
561
            pallet_registrar::ParaManager::<T>::insert(para_id, deposit.creator);
562
            total_weight = total_weight.saturating_add(
563
                T::DbWeight::get()
564
                    .reads(1)
565
                    .saturating_add(T::DbWeight::get().writes(1)),
566
            );
567
        }
568

            
569
        total_weight
570
    }
571

            
572
    #[cfg(feature = "try-runtime")]
573
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
574
        Ok(vec![])
575
    }
576

            
577
    #[cfg(feature = "try-runtime")]
578
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
579
        Ok(())
580
    }
581
}
582

            
583
pub struct RegistrarReserveToHoldMigration<T>(pub PhantomData<T>);
584
impl<T> Migration for RegistrarReserveToHoldMigration<T>
585
where
586
    T: pallet_registrar::Config,
587
    T: pallet_balances::Config,
588
    <T as pallet_balances::Config>::RuntimeHoldReason: From<pallet_registrar::HoldReason>,
589
    <T as pallet_balances::Config>::Balance: From<
590
        <<T as pallet_registrar::Config>::Currency as frame_support::traits::fungible::Inspect<
591
            T::AccountId,
592
        >>::Balance,
593
    >,
594
    <T as pallet_balances::Config>::Balance: From<u128>,
595
{
596
2
    fn friendly_name(&self) -> &str {
597
2
        "TM_RegistrarReserveToHoldMigration"
598
2
    }
599

            
600
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
601
2
        let mut total_weight = Weight::default();
602
4
        for (_para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
603
2
            pallet_balances::Pallet::<T>::unreserve(&deposit.creator, deposit.deposit.into());
604
2
            let _ = pallet_balances::Pallet::<T>::hold(
605
2
                &HoldReason::RegistrarDeposit.into(),
606
2
                &deposit.creator,
607
2
                deposit.deposit.into(),
608
2
            );
609
2
            total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(2, 2));
610
2
        }
611

            
612
2
        total_weight
613
2
    }
614

            
615
    #[cfg(feature = "try-runtime")]
616
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
617
        use frame_support::traits::fungible::InspectHold;
618

            
619
        for (_para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
620
            ensure!(
621
                pallet_balances::Pallet::<T>::reserved_balance(&deposit.creator)
622
                    >= deposit.deposit.into(),
623
                "Reserved balanced cannot be less than deposit amount"
624
            );
625

            
626
            ensure!(
627
                pallet_balances::Pallet::<T>::balance_on_hold(
628
                    &HoldReason::RegistrarDeposit.into(),
629
                    &deposit.creator
630
                ) == 0u128.into(),
631
                "Balance on hold for RegistrarDeposit should be 0"
632
            );
633
        }
634
        Ok(vec![])
635
    }
636

            
637
    #[cfg(feature = "try-runtime")]
638
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
639
        use frame_support::traits::fungible::InspectHold;
640

            
641
        for (_para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
642
            ensure!(
643
                pallet_balances::Pallet::<T>::balance_on_hold(
644
                    &HoldReason::RegistrarDeposit.into(),
645
                    &deposit.creator
646
                ) >= deposit.deposit.into(),
647
                "Balance on hold for RegistrarDeposit should be deposit"
648
            );
649
        }
650

            
651
        Ok(())
652
    }
653
}
654
pub struct MigrateToLatestXcmVersion<Runtime>(PhantomData<Runtime>);
655
impl<Runtime> Migration for MigrateToLatestXcmVersion<Runtime>
656
where
657
    pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>:
658
        frame_support::traits::OnRuntimeUpgrade,
659
{
660
1
    fn friendly_name(&self) -> &str {
661
1
        "MM_MigrateToLatestXcmVersion"
662
1
    }
663

            
664
    fn migrate(&self, _available_weight: Weight) -> Weight {
665
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::on_runtime_upgrade()
666
    }
667

            
668
    #[cfg(feature = "try-runtime")]
669
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
670
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::pre_upgrade()
671
    }
672

            
673
    #[cfg(feature = "try-runtime")]
674
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
675
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::post_upgrade(state)
676
    }
677
}
678

            
679
pub struct DataPreserversAssignmentsMigration<T>(pub PhantomData<T>);
680
impl<T> Migration for DataPreserversAssignmentsMigration<T>
681
where
682
    T: pallet_data_preservers::Config + pallet_registrar::Config,
683
    T::AccountId: From<[u8; 32]>,
684
{
685
2
    fn friendly_name(&self) -> &str {
686
2
        "TM_DataPreserversAssignmentsMigration"
687
2
    }
688

            
689
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
690
        use {
691
            frame_support::BoundedBTreeSet,
692
            frame_system::RawOrigin,
693
            pallet_data_preservers::{AssignmentPayment, ParaIdsFilter, Profile, ProfileMode},
694
        };
695

            
696
2
        let mut total_weight = Weight::default();
697
2

            
698
2
        let (request, _extra, witness) = T::AssignmentPayment::free_variant_values()
699
2
            .expect("free variant values are necessary to perform migration");
700
2

            
701
2
        let dummy_profile_owner = T::AccountId::from([0u8; 32]);
702
2

            
703
2
        let pallet_prefix: &[u8] = b"DataPreservers";
704
2
        let storage_item_prefix: &[u8] = b"BootNodes";
705
2
        let bootnodes_storage: Vec<_> = storage_key_iter::<
706
2
            ParaId,
707
2
            BoundedVec<BoundedVec<u8, T::MaxNodeUrlLen>, T::MaxAssignmentsPerParaId>,
708
2
            Blake2_128Concat,
709
2
        >(pallet_prefix, storage_item_prefix)
710
2
        .collect();
711
2

            
712
2
        total_weight = total_weight.saturating_add(
713
2
            T::DbWeight::get()
714
2
                .reads(bootnodes_storage.len() as u64)
715
2
                .saturating_add(T::DbWeight::get().writes(bootnodes_storage.len() as u64)),
716
2
        );
717

            
718
6
        for (para_id, bootnodes) in bootnodes_storage {
719
12
            for bootnode_url in bootnodes {
720
8
                let profile = Profile {
721
8
                    url: bootnode_url,
722
8
                    para_ids: ParaIdsFilter::Whitelist({
723
8
                        let mut set = BoundedBTreeSet::new();
724
8
                        set.try_insert(para_id).expect("to be in bound");
725
8
                        set
726
8
                    }),
727
8
                    mode: ProfileMode::Bootnode,
728
8
                    assignment_request: request.clone(),
729
8
                };
730
8

            
731
8
                let profile_id = pallet_data_preservers::NextProfileId::<T>::get();
732

            
733
8
                if let Some(weight) = pallet_data_preservers::Pallet::<T>::force_create_profile(
734
8
                    RawOrigin::Root.into(),
735
8
                    profile,
736
8
                    dummy_profile_owner.clone(),
737
8
                )
738
8
                .expect("to create profile")
739
8
                .actual_weight
740
                {
741
                    total_weight = total_weight.saturating_add(weight);
742
8
                }
743

            
744
8
                if let Some(weight) = pallet_data_preservers::Pallet::<T>::force_start_assignment(
745
8
                    RawOrigin::Root.into(),
746
8
                    profile_id,
747
8
                    para_id,
748
8
                    witness.clone(),
749
8
                )
750
8
                .expect("to start assignment")
751
8
                .actual_weight
752
                {
753
                    total_weight = total_weight.saturating_add(weight);
754
8
                }
755
            }
756
        }
757

            
758
2
        let _ = clear_storage_prefix(pallet_prefix, storage_item_prefix, &[], None, None);
759
2

            
760
2
        total_weight
761
2
    }
762

            
763
    #[cfg(feature = "try-runtime")]
764
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
765
        use parity_scale_codec::Encode;
766

            
767
        let pallet_prefix: &[u8] = b"DataPreservers";
768
        let storage_item_prefix: &[u8] = b"BootNodes";
769
        let state: Vec<_> = storage_key_iter::<
770
            ParaId,
771
            BoundedVec<BoundedVec<u8, T::MaxNodeUrlLen>, T::MaxAssignmentsPerParaId>,
772
            Blake2_128Concat,
773
        >(pallet_prefix, storage_item_prefix)
774
        .collect();
775

            
776
        Ok(state.encode())
777
    }
778

            
779
    #[cfg(feature = "try-runtime")]
780
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
781
        use parity_scale_codec::Decode;
782

            
783
        let pallet_prefix: &[u8] = b"DataPreservers";
784
        let storage_item_prefix: &[u8] = b"BootNodes";
785

            
786
        let pre_state: Vec<(ParaId, Vec<Vec<u8>>)> =
787
            Decode::decode(&mut &state[..]).expect("state to be decoded properly");
788

            
789
        for (para_id, bootnodes) in pre_state {
790
            let assignments = pallet_data_preservers::Assignments::<T>::get(para_id);
791
            assert_eq!(assignments.len(), bootnodes.len());
792

            
793
            let profiles: Vec<_> =
794
                pallet_data_preservers::Pallet::<T>::assignments_profiles(para_id).collect();
795

            
796
            for bootnode in bootnodes {
797
                assert_eq!(
798
                    profiles
799
                        .iter()
800
                        .filter(|profile| profile.url == bootnode)
801
                        .count(),
802
                    1
803
                );
804
            }
805
        }
806

            
807
        assert_eq!(
808
            storage_key_iter::<
809
                ParaId,
810
                BoundedVec<BoundedVec<u8, T::MaxNodeUrlLen>, T::MaxAssignmentsPerParaId>,
811
                Blake2_128Concat,
812
            >(pallet_prefix, storage_item_prefix)
813
            .count(),
814
            0
815
        );
816

            
817
        Ok(())
818
    }
819
}
820

            
821
pub struct ForeignAssetCreatorMigration<Runtime>(pub PhantomData<Runtime>);
822

            
823
impl<Runtime> Migration for ForeignAssetCreatorMigration<Runtime>
824
where
825
    Runtime: pallet_foreign_asset_creator::Config,
826
    <Runtime as pallet_foreign_asset_creator::Config>::ForeignAsset:
827
        TryFrom<staging_xcm::v3::MultiLocation>,
828
{
829
90
    fn friendly_name(&self) -> &str {
830
90
        "TM_ForeignAssetCreatorMigration"
831
90
    }
832

            
833
1
    fn migrate(&self, _available_weight: Weight) -> Weight {
834
        use frame_support::pallet_prelude::*;
835

            
836
        use staging_xcm::v3::MultiLocation as OldLocation;
837

            
838
1
        let pallet_prefix = AssetIdToForeignAsset::<Runtime>::pallet_prefix();
839
1
        let asset_id_to_foreign_asset_storage_prefix =
840
1
            AssetIdToForeignAsset::<Runtime>::storage_prefix();
841
1
        let foreign_asset_to_asset_id_prefix = ForeignAssetToAssetId::<Runtime>::storage_prefix();
842
1

            
843
1
        // Data required to migrate ForeignAsset values
844
1
        // Read all the data into memory.
845
1
        let asset_id_to_foreign_asset_data: Vec<_> =
846
1
            storage_key_iter::<AssetId<Runtime>, OldLocation, Blake2_128Concat>(
847
1
                pallet_prefix,
848
1
                asset_id_to_foreign_asset_storage_prefix,
849
1
            )
850
1
            .drain()
851
1
            .collect();
852
1

            
853
1
        // Data required to migrate ForeignAsset keys
854
1
        let foreign_asset_to_asset_id_data: Vec<_> =
855
1
            storage_key_iter::<OldLocation, AssetId<Runtime>, Blake2_128Concat>(
856
1
                pallet_prefix,
857
1
                foreign_asset_to_asset_id_prefix,
858
1
            )
859
1
            .drain()
860
1
            .collect();
861
1

            
862
1
        let migrated_count = asset_id_to_foreign_asset_data
863
1
            .len()
864
1
            .saturating_add(foreign_asset_to_asset_id_data.len());
865
1

            
866
1
        log::info!("Migrating {:?} elements", migrated_count);
867

            
868
        // Write to the new storage with removed and added fields
869
3
        for (asset_id, old_location) in asset_id_to_foreign_asset_data {
870
2
            if let Ok(new_location) = Runtime::ForeignAsset::try_from(old_location) {
871
2
                AssetIdToForeignAsset::<Runtime>::insert(asset_id, new_location);
872
2
            } else {
873
                log::warn!("Location could not be converted safely to xcmV4")
874
            }
875
        }
876

            
877
3
        for (old_location, asset_id) in foreign_asset_to_asset_id_data {
878
2
            if let Ok(new_location) = Runtime::ForeignAsset::try_from(old_location) {
879
2
                ForeignAssetToAssetId::<Runtime>::insert(new_location, asset_id);
880
2
            } else {
881
                log::warn!("Location could not be converted safely to xcmV4")
882
            }
883
        }
884

            
885
        // One db read and one db write per element, plus the on-chain storage
886
1
        Runtime::DbWeight::get().reads_writes(migrated_count as u64, 2 * migrated_count as u64)
887
1
    }
888

            
889
    #[cfg(feature = "try-runtime")]
890
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
891
        Ok(vec![])
892
    }
893

            
894
    #[cfg(feature = "try-runtime")]
895
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
896
        Ok(())
897
    }
898
}
899

            
900
pub struct ExternalValidatorsInitialMigration<Runtime>(pub PhantomData<Runtime>);
901

            
902
impl<Runtime> Migration for ExternalValidatorsInitialMigration<Runtime>
903
where
904
    Runtime: pallet_external_validators::Config,
905
    Runtime: pallet_session::Config<
906
        ValidatorId = <Runtime as pallet_external_validators::Config>::ValidatorId,
907
    >,
908
{
909
1
    fn friendly_name(&self) -> &str {
910
1
        "TM_ExternalValidatorsInitialMigration"
911
1
    }
912

            
913
1
    fn migrate(&self, _available_weight: Weight) -> Weight {
914
        use frame_support::pallet_prelude::*;
915

            
916
        // Set initial WhitelistedValidators to current validators from pallet session
917
1
        let session_keys = pallet_session::QueuedKeys::<Runtime>::get();
918
1
        let session_validators = BoundedVec::truncate_from(
919
1
            session_keys
920
1
                .into_iter()
921
2
                .map(|(validator, _keys)| validator)
922
1
                .collect(),
923
1
        );
924
1
        pallet_external_validators::WhitelistedValidators::<Runtime>::put(session_validators);
925
1

            
926
1
        // Kill storage of ValidatorManager pallet
927
1
        let pallet_prefix: &[u8] = b"ValidatorManager";
928
1
        let _ = clear_storage_prefix(pallet_prefix, b"", b"", None, None);
929
1

            
930
1
        // One db read and one db write per element, plus the on-chain storage
931
1
        Runtime::DbWeight::get().reads_writes(1, 1)
932
1
    }
933

            
934
    #[cfg(feature = "try-runtime")]
935
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
936
        Ok(vec![])
937
    }
938

            
939
    #[cfg(feature = "try-runtime")]
940
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
941
        Ok(())
942
    }
943
}
944

            
945
pub struct FlashboxMigrations<Runtime>(PhantomData<Runtime>);
946

            
947
impl<Runtime> GetMigrations for FlashboxMigrations<Runtime>
948
where
949
    Runtime: pallet_balances::Config,
950
    Runtime: pallet_configuration::Config,
951
    Runtime: pallet_registrar::Config,
952
    Runtime: pallet_data_preservers::Config,
953
    Runtime: pallet_services_payment::Config,
954
    Runtime: pallet_data_preservers::Config,
955
    Runtime::AccountId: From<[u8; 32]>,
956
    <Runtime as pallet_balances::Config>::RuntimeHoldReason: From<pallet_registrar::HoldReason>,
957
    <Runtime as pallet_balances::Config>::Balance: From<<<Runtime as pallet_registrar::Config>::Currency as frame_support::traits::fungible::Inspect<Runtime::AccountId>>::Balance>,
958
    <Runtime as pallet_balances::Config>::Balance: From<u128>,
959
{
960
1
    fn get_migrations() -> Vec<Box<dyn Migration>> {
961
1
        //let migrate_services_payment =
962
1
        //    MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
963
1
        //let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());
964
1
        let migrate_config_parathread_params =
965
1
            MigrateConfigurationParathreads::<Runtime>(Default::default());
966
1

            
967
1
        let migrate_add_collator_assignment_credits =
968
1
            MigrateServicesPaymentAddCollatorAssignmentCredits::<Runtime>(Default::default());
969
1
        let migrate_registrar_pending_verification =
970
1
            RegistrarPendingVerificationValueToMap::<Runtime>(Default::default());
971
1
        let migrate_registrar_manager =
972
1
            RegistrarParaManagerMigration::<Runtime>(Default::default());
973
1
        let migrate_data_preservers_assignments =
974
1
            DataPreserversAssignmentsMigration::<Runtime>(Default::default());
975
1
        let migrate_registrar_reserves = RegistrarReserveToHoldMigration::<Runtime>(Default::default());
976
1
        let migrate_config_max_parachain_percentage = MigrateConfigurationAddParachainPercentage::<Runtime>(Default::default());
977
1

            
978
1
        vec![
979
1
            // Applied in runtime 400
980
1
            //Box::new(migrate_services_payment),
981
1
            // Applied in runtime 400
982
1
            //Box::new(migrate_boot_nodes),
983
1
            // Applied in runtime 400
984
1
            Box::new(migrate_config_parathread_params),
985
1
            Box::new(migrate_add_collator_assignment_credits),
986
1
            Box::new(migrate_registrar_pending_verification),
987
1
            Box::new(migrate_registrar_manager),
988
1
            Box::new(migrate_data_preservers_assignments),
989
1
            Box::new(migrate_registrar_reserves),
990
1
            Box::new(migrate_config_max_parachain_percentage),
991
1
        ]
992
1
    }
993
}
994

            
995
pub struct DanceboxMigrations<Runtime>(PhantomData<Runtime>);
996

            
997
impl<Runtime> GetMigrations for DanceboxMigrations<Runtime>
998
where
999
    Runtime: pallet_pooled_staking::Config,
    Runtime: pallet_registrar::Config,
    Runtime: pallet_balances::Config,
    Runtime: pallet_configuration::Config,
    Runtime: pallet_services_payment::Config,
    Runtime: cumulus_pallet_xcmp_queue::Config,
    Runtime: pallet_data_preservers::Config,
    Runtime: pallet_xcm::Config,
    <Runtime as pallet_balances::Config>::RuntimeHoldReason:
        From<pallet_pooled_staking::HoldReason>,
    Runtime: pallet_foreign_asset_creator::Config,
    <Runtime as pallet_foreign_asset_creator::Config>::ForeignAsset:
        TryFrom<staging_xcm::v3::MultiLocation>,
    <Runtime as pallet_balances::Config>::RuntimeHoldReason:
        From<pallet_registrar::HoldReason>,
    Runtime::AccountId: From<[u8; 32]>,
    <Runtime as pallet_balances::Config>::Balance: From<<<Runtime as pallet_registrar::Config>::Currency as frame_support::traits::fungible::Inspect<Runtime::AccountId>>::Balance>,
    <Runtime as pallet_balances::Config>::Balance: From<u128>,
{
1
    fn get_migrations() -> Vec<Box<dyn Migration>> {
1
        // let migrate_invulnerables = MigrateInvulnerables::<Runtime>(Default::default());
1
        // let migrate_holds = MigrateHoldReason::<Runtime>(Default::default());
1
        // let migrate_config = MigrateConfigurationFullRotationPeriod::<Runtime>(Default::default());
1
        // let migrate_xcm = PolkadotXcmMigration::<Runtime>(Default::default());
1
        // let migrate_xcmp_queue = XcmpQueueMigration::<Runtime>(Default::default());
1
        // let migrate_services_payment =
1
        //     MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
1
        // let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());
1
        // let migrate_hold_reason_runtime_enum =
1
        //     MigrateHoldReasonRuntimeEnum::<Runtime>(Default::default());
1

            
1
        let migrate_config_parathread_params =
1
            MigrateConfigurationParathreads::<Runtime>(Default::default());
1
        let migrate_add_collator_assignment_credits =
1
            MigrateServicesPaymentAddCollatorAssignmentCredits::<Runtime>(Default::default());
1
        let migrate_xcmp_queue_v4 = XcmpQueueMigrationV4::<Runtime>(Default::default());
1
        let migrate_registrar_pending_verification =
1
            RegistrarPendingVerificationValueToMap::<Runtime>(Default::default());
1
        let migrate_registrar_manager =
1
            RegistrarParaManagerMigration::<Runtime>(Default::default());
1
        let migrate_data_preservers_assignments =
1
            DataPreserversAssignmentsMigration::<Runtime>(Default::default());
1

            
1
        let migrate_pallet_xcm_v4 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
1
        let foreign_asset_creator_migration =
1
            ForeignAssetCreatorMigration::<Runtime>(Default::default());
1
        let migrate_registrar_reserves = RegistrarReserveToHoldMigration::<Runtime>(Default::default());
1
        let migrate_config_max_parachain_percentage = MigrateConfigurationAddParachainPercentage::<Runtime>(Default::default());
1

            
1
        vec![
1
            // Applied in runtime 200
1
            //Box::new(migrate_invulnerables),
1
            // Applied in runtime 200
1
            //Box::new(migrate_holds),
1
            // Applied in runtime 300
1
            //Box::new(migrate_config),
1
            // Applied in runtime 300
1
            //Box::new(migrate_xcm),
1
            // Applied in runtime 300
1
            //Box::new(migrate_xcmp_queue),
1
            // Applied in runtime 400
1
            //Box::new(migrate_services_payment),
1
            // Applied in runtime 400
1
            //Box::new(migrate_hold_reason_runtime_enum),
1
            // Applied in runtime 400
1
            //Box::new(migrate_boot_nodes),
1
            Box::new(migrate_config_parathread_params),
1
            Box::new(migrate_add_collator_assignment_credits),
1
            Box::new(migrate_xcmp_queue_v4),
1
            Box::new(migrate_registrar_pending_verification),
1
            Box::new(migrate_registrar_manager),
1
            Box::new(migrate_pallet_xcm_v4),
1
            Box::new(foreign_asset_creator_migration),
1
            Box::new(migrate_data_preservers_assignments),
1
            Box::new(migrate_registrar_reserves),
1
            Box::new(migrate_config_max_parachain_percentage)
1
        ]
1
    }
}
pub struct MigrateMMRLeafPallet<T>(pub PhantomData<T>);
impl<T: frame_system::Config> Migration for MigrateMMRLeafPallet<T> {
1
    fn friendly_name(&self) -> &str {
1
        "SM_MigrateMMRLeafPallet"
1
    }
1
    fn migrate(&self, available_weight: Weight) -> Weight {
1
        let new_name =
1
            <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
1
                pallet_beefy_mmr::Pallet<T>,
1
            >()
1
            .expect("pallet_beefy_mmr must be part of dancelight before this migration");
1
        move_pallet(Self::old_pallet_name().as_bytes(), new_name.as_bytes());
1
        available_weight
1
    }
    #[cfg(feature = "try-runtime")]
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
        Ok(vec![])
    }
    #[cfg(feature = "try-runtime")]
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
        Ok(())
    }
}
impl<T> MigrateMMRLeafPallet<T> {
2
    pub fn old_pallet_name() -> &'static str {
2
        "MMRLeaf"
2
    }
}
pub struct DancelightMigrations<Runtime>(PhantomData<Runtime>);
impl<Runtime> GetMigrations for DancelightMigrations<Runtime>
where
    Runtime: frame_system::Config,
    Runtime: pallet_external_validators::Config,
    Runtime: pallet_session::Config<
        ValidatorId = <Runtime as pallet_external_validators::Config>::ValidatorId,
    >,
{
1
    fn get_migrations() -> Vec<Box<dyn Migration>> {
1
        let migrate_mmr_leaf_pallet = MigrateMMRLeafPallet::<Runtime>(Default::default());
1
        let migrate_external_validators =
1
            ExternalValidatorsInitialMigration::<Runtime>(Default::default());
1

            
1
        vec![
1
            Box::new(migrate_mmr_leaf_pallet),
1
            Box::new(migrate_external_validators),
1
        ]
1
    }
}