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
    fn friendly_name(&self) -> &str {
87
        "TM_MigrateConfigurationAddParachainPercentage"
88
    }
89

            
90
    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
        let default_config = HostConfiguration::default();
96

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

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

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

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

            
142
        <T as pallet_configuration::Config>::WeightInfo::set_config_with_u32()
143
    }
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
    fn friendly_name(&self) -> &str {
202
        "TM_MigrateConfigurationParathreads"
203
    }
204

            
205
    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
        let default_config = HostConfiguration::default();
211

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

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

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

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

            
257
        <T as pallet_configuration::Config>::WeightInfo::set_config_with_u32()
258
    }
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
    fn friendly_name(&self) -> &str {
306
        "TM_MigrateServicesPaymentAddCollatorAssignmentCredits"
307
    }
308

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

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

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

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

            
333
        let db_weights = T::DbWeight::get();
334
        db_weights.reads_writes(reads, writes)
335
    }
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
    fn friendly_name(&self) -> &str {
385
        "MM_PolkadotXcmMigrationFixVersion"
386
    }
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
    fn friendly_name(&self) -> &str {
423
        "MM_XcmpQueueMigrationFixVersion"
424
    }
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
    fn friendly_name(&self) -> &str {
463
        "MM_XcmpQueueMigrationV3"
464
    }
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
    fn friendly_name(&self) -> &str {
491
        "MM_XcmpQueueMigrationV4"
492
    }
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
    fn friendly_name(&self) -> &str {
516
        "TM_RegistrarPendingVerificationValueToMap"
517
    }
518

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

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

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

            
534
        total_weight
535
    }
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
    fn friendly_name(&self) -> &str {
555
        "TM_RegistrarParaManagerMigration"
556
    }
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
    fn friendly_name(&self) -> &str {
597
        "TM_RegistrarReserveToHoldMigration"
598
    }
599

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

            
612
        total_weight
613
    }
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
    fn friendly_name(&self) -> &str {
661
        "MM_MigrateToLatestXcmVersion"
662
    }
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
    fn friendly_name(&self) -> &str {
686
        "TM_DataPreserversAssignmentsMigration"
687
    }
688

            
689
    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
        let mut total_weight = Weight::default();
697

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

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

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

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

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

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

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

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

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

            
760
        total_weight
761
    }
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
    fn friendly_name(&self) -> &str {
830
        "TM_ForeignAssetCreatorMigration"
831
    }
832

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

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

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

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

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

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

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

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

            
877
        for (old_location, asset_id) in foreign_asset_to_asset_id_data {
878
            if let Ok(new_location) = Runtime::ForeignAsset::try_from(old_location) {
879
                ForeignAssetToAssetId::<Runtime>::insert(new_location, asset_id);
880
            } 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
        Runtime::DbWeight::get().reads_writes(migrated_count as u64, 2 * migrated_count as u64)
887
    }
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
3
    fn friendly_name(&self) -> &str {
910
3
        "TM_ExternalValidatorsInitialMigration"
911
3
    }
912

            
913
    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
        let session_keys = pallet_session::QueuedKeys::<Runtime>::get();
918
        let session_validators = BoundedVec::truncate_from(
919
            session_keys
920
                .into_iter()
921
                .map(|(validator, _keys)| validator)
922
                .collect(),
923
        );
924
        pallet_external_validators::WhitelistedValidators::<Runtime>::put(session_validators);
925

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

            
930
        // One db read and one db write per element, plus the on-chain storage
931
        Runtime::DbWeight::get().reads_writes(1, 1)
932
    }
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
    fn get_migrations() -> Vec<Box<dyn Migration>> {
961
        //let migrate_services_payment =
962
        //    MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
963
        //let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());
964
        let migrate_config_parathread_params =
965
            MigrateConfigurationParathreads::<Runtime>(Default::default());
966

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

            
978
        vec![
979
            // Applied in runtime 400
980
            //Box::new(migrate_services_payment),
981
            // Applied in runtime 400
982
            //Box::new(migrate_boot_nodes),
983
            // Applied in runtime 400
984
            Box::new(migrate_config_parathread_params),
985
            Box::new(migrate_add_collator_assignment_credits),
986
            Box::new(migrate_registrar_pending_verification),
987
            Box::new(migrate_registrar_manager),
988
            Box::new(migrate_data_preservers_assignments),
989
            Box::new(migrate_registrar_reserves),
990
            Box::new(migrate_config_max_parachain_percentage),
991
        ]
992
    }
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>,
{
    fn get_migrations() -> Vec<Box<dyn Migration>> {
        // let migrate_invulnerables = MigrateInvulnerables::<Runtime>(Default::default());
        // let migrate_holds = MigrateHoldReason::<Runtime>(Default::default());
        // let migrate_config = MigrateConfigurationFullRotationPeriod::<Runtime>(Default::default());
        // let migrate_xcm = PolkadotXcmMigration::<Runtime>(Default::default());
        // let migrate_xcmp_queue = XcmpQueueMigration::<Runtime>(Default::default());
        // let migrate_services_payment =
        //     MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
        // let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());
        // let migrate_hold_reason_runtime_enum =
        //     MigrateHoldReasonRuntimeEnum::<Runtime>(Default::default());
        let migrate_config_parathread_params =
            MigrateConfigurationParathreads::<Runtime>(Default::default());
        let migrate_add_collator_assignment_credits =
            MigrateServicesPaymentAddCollatorAssignmentCredits::<Runtime>(Default::default());
        let migrate_xcmp_queue_v4 = XcmpQueueMigrationV4::<Runtime>(Default::default());
        let migrate_registrar_pending_verification =
            RegistrarPendingVerificationValueToMap::<Runtime>(Default::default());
        let migrate_registrar_manager =
            RegistrarParaManagerMigration::<Runtime>(Default::default());
        let migrate_data_preservers_assignments =
            DataPreserversAssignmentsMigration::<Runtime>(Default::default());
        let migrate_pallet_xcm_v4 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
        let foreign_asset_creator_migration =
            ForeignAssetCreatorMigration::<Runtime>(Default::default());
        let migrate_registrar_reserves = RegistrarReserveToHoldMigration::<Runtime>(Default::default());
        let migrate_config_max_parachain_percentage = MigrateConfigurationAddParachainPercentage::<Runtime>(Default::default());
        vec![
            // Applied in runtime 200
            //Box::new(migrate_invulnerables),
            // Applied in runtime 200
            //Box::new(migrate_holds),
            // Applied in runtime 300
            //Box::new(migrate_config),
            // Applied in runtime 300
            //Box::new(migrate_xcm),
            // Applied in runtime 300
            //Box::new(migrate_xcmp_queue),
            // Applied in runtime 400
            //Box::new(migrate_services_payment),
            // Applied in runtime 400
            //Box::new(migrate_hold_reason_runtime_enum),
            // Applied in runtime 400
            //Box::new(migrate_boot_nodes),
            Box::new(migrate_config_parathread_params),
            Box::new(migrate_add_collator_assignment_credits),
            Box::new(migrate_xcmp_queue_v4),
            Box::new(migrate_registrar_pending_verification),
            Box::new(migrate_registrar_manager),
            Box::new(migrate_pallet_xcm_v4),
            Box::new(foreign_asset_creator_migration),
            Box::new(migrate_data_preservers_assignments),
            Box::new(migrate_registrar_reserves),
            Box::new(migrate_config_max_parachain_percentage)
        ]
    }
}
pub struct MigrateMMRLeafPallet<T>(pub PhantomData<T>);
impl<T: frame_system::Config> Migration for MigrateMMRLeafPallet<T> {
3
    fn friendly_name(&self) -> &str {
3
        "SM_MigrateMMRLeafPallet"
3
    }
    fn migrate(&self, available_weight: Weight) -> Weight {
        let new_name =
            <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
                pallet_beefy_mmr::Pallet<T>,
            >()
            .expect("pallet_beefy_mmr must be part of dancelight before this migration");
        move_pallet(Self::old_pallet_name().as_bytes(), new_name.as_bytes());
        available_weight
    }
    #[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> {
    pub fn old_pallet_name() -> &'static str {
        "MMRLeaf"
    }
}
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,
    >,
{
3
    fn get_migrations() -> Vec<Box<dyn Migration>> {
3
        let migrate_mmr_leaf_pallet = MigrateMMRLeafPallet::<Runtime>(Default::default());
3
        let migrate_external_validators =
3
            ExternalValidatorsInitialMigration::<Runtime>(Default::default());
3

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