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
extern crate alloc;
38

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

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

            
83
pub struct MigrateConfigurationAddFullRotationMode<T>(pub PhantomData<T>);
84
impl<T> Migration for MigrateConfigurationAddFullRotationMode<T>
85
where
86
    T: pallet_configuration::Config,
87
{
88
691
    fn friendly_name(&self) -> &str {
89
691
        "TM_MigrateConfigurationAddFullRotationMode"
90
691
    }
91

            
92
3
    fn migrate(&self, _available_weight: Weight) -> Weight {
93
3
        let default_config = HostConfiguration::default();
94
3

            
95
3
        // Modify active config
96
3
        let old_config: HostConfigurationV3 = frame_support::storage::unhashed::get(
97
3
            &pallet_configuration::ActiveConfig::<T>::hashed_key(),
98
3
        )
99
3
        .expect("configuration.activeConfig should have value");
100
3
        let new_config = HostConfiguration {
101
3
            max_collators: old_config.max_collators,
102
3
            min_orchestrator_collators: old_config.min_orchestrator_collators,
103
3
            max_orchestrator_collators: old_config.max_orchestrator_collators,
104
3
            collators_per_container: old_config.collators_per_container,
105
3
            full_rotation_period: old_config.full_rotation_period,
106
3
            collators_per_parathread: old_config.collators_per_parathread,
107
3
            parathreads_per_collator: old_config.parathreads_per_collator,
108
3
            target_container_chain_fullness: old_config.target_container_chain_fullness,
109
3
            max_parachain_cores_percentage: old_config.max_parachain_cores_percentage,
110
3
            full_rotation_mode: default_config.full_rotation_mode.clone(),
111
3
        };
112
3
        frame_support::storage::unhashed::put(
113
3
            &pallet_configuration::ActiveConfig::<T>::hashed_key(),
114
3
            &new_config,
115
3
        );
116
3

            
117
3
        // Modify pending configs, if any
118
3
        let old_pending_configs: Vec<(u32, HostConfigurationV3)> =
119
3
            frame_support::storage::unhashed::get(
120
3
                &pallet_configuration::PendingConfigs::<T>::hashed_key(),
121
3
            )
122
3
            .unwrap_or_default();
123
3
        let mut new_pending_configs: Vec<(u32, HostConfiguration)> = vec![];
124

            
125
9
        for (session_index, old_config) in old_pending_configs {
126
6
            let new_config = HostConfiguration {
127
6
                max_collators: old_config.max_collators,
128
6
                min_orchestrator_collators: old_config.min_orchestrator_collators,
129
6
                max_orchestrator_collators: old_config.max_orchestrator_collators,
130
6
                collators_per_container: old_config.collators_per_container,
131
6
                full_rotation_period: old_config.full_rotation_period,
132
6
                collators_per_parathread: old_config.collators_per_parathread,
133
6
                parathreads_per_collator: old_config.parathreads_per_collator,
134
6
                target_container_chain_fullness: old_config.target_container_chain_fullness,
135
6
                max_parachain_cores_percentage: old_config.max_parachain_cores_percentage,
136
6
                full_rotation_mode: default_config.full_rotation_mode.clone(),
137
6
            };
138
6
            new_pending_configs.push((session_index, new_config));
139
6
        }
140

            
141
3
        if !new_pending_configs.is_empty() {
142
3
            frame_support::storage::unhashed::put(
143
3
                &pallet_configuration::PendingConfigs::<T>::hashed_key(),
144
3
                &new_pending_configs,
145
3
            );
146
3
        }
147

            
148
3
        <T as pallet_configuration::Config>::WeightInfo::set_config_with_u32()
149
3
    }
150

            
151
    /// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
152
    #[cfg(feature = "try-runtime")]
153
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
154
        log::info!(
155
            "hashed key {:?}",
156
            pallet_configuration::ActiveConfig::<T>::hashed_key()
157
        );
158
        let old_config_bytes = frame_support::storage::unhashed::get_raw(
159
            &pallet_configuration::ActiveConfig::<T>::hashed_key(),
160
        )
161
        .unwrap();
162
        let old_config: Result<HostConfigurationV3, _> =
163
            DecodeAll::decode_all(&mut old_config_bytes.as_ref());
164
        let new_config: Result<HostConfiguration, _> =
165
            DecodeAll::decode_all(&mut old_config_bytes.as_ref());
166

            
167
        assert!(old_config.is_ok());
168
        assert!(new_config.is_err());
169

            
170
        Ok(vec![])
171
    }
172

            
173
    /// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
174
    #[cfg(feature = "try-runtime")]
175
    fn post_upgrade(
176
        &self,
177
        _number_of_invulnerables: Vec<u8>,
178
    ) -> Result<(), sp_runtime::DispatchError> {
179
        let new_config_bytes = frame_support::storage::unhashed::get_raw(
180
            &pallet_configuration::ActiveConfig::<T>::hashed_key(),
181
        )
182
        .unwrap();
183
        let old_config: Result<HostConfigurationV3, _> =
184
            DecodeAll::decode_all(&mut new_config_bytes.as_ref());
185
        let new_config: Result<HostConfiguration, _> =
186
            DecodeAll::decode_all(&mut new_config_bytes.as_ref());
187

            
188
        assert!(old_config.is_err());
189
        assert!(new_config.is_ok());
190

            
191
        let new_config = pallet_configuration::Pallet::<T>::config();
192
        let default_config = HostConfiguration::default();
193
        assert_eq!(
194
            new_config.full_rotation_mode,
195
            default_config.full_rotation_mode
196
        );
197
        Ok(())
198
    }
199
}
200

            
201
pub struct MigrateServicesPaymentAddCollatorAssignmentCredits<T>(pub PhantomData<T>);
202
impl<T> Migration for MigrateServicesPaymentAddCollatorAssignmentCredits<T>
203
where
204
    T: pallet_services_payment::Config + pallet_registrar::Config,
205
{
206
    fn friendly_name(&self) -> &str {
207
        "TM_MigrateServicesPaymentAddCollatorAssignmentCredits"
208
    }
209

            
210
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
211
2
        // For each parachain in pallet_registrar (active, pending or pending_verification),
212
2
        // insert `MaxCreditsStored` to pallet_services_payment,
213
2
        // and mark that parachain as "given_free_credits".
214
2
        let mut para_ids = BTreeSet::new();
215
2
        let active = pallet_registrar::RegisteredParaIds::<T>::get();
216
2
        let pending = pallet_registrar::PendingParaIds::<T>::get();
217
2

            
218
2
        let paused = pallet_registrar::Paused::<T>::get();
219
2
        para_ids.extend(active);
220
2
        para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
221
2
        para_ids.extend(paused);
222
2

            
223
2
        let reads = 3 + 2 * para_ids.len() as u64;
224
2
        let writes = 2 * para_ids.len() as u64;
225

            
226
6
        for para_id in para_ids {
227
4
            // 2 reads 2 writes
228
4
            pallet_services_payment::Pallet::<T>::set_free_collator_assignment_credits(
229
4
                &para_id,
230
4
                T::FreeCollatorAssignmentCredits::get(),
231
4
            );
232
4
        }
233

            
234
2
        let db_weights = T::DbWeight::get();
235
2
        db_weights.reads_writes(reads, writes)
236
2
    }
237
    /// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
238
    #[cfg(feature = "try-runtime")]
239
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
240
        let mut para_ids = BTreeSet::new();
241
        let active = pallet_registrar::RegisteredParaIds::<T>::get();
242
        let pending = pallet_registrar::PendingParaIds::<T>::get();
243
        let paused = pallet_registrar::Paused::<T>::get();
244
        para_ids.extend(active);
245
        para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
246
        para_ids.extend(paused);
247

            
248
        for para_id in para_ids {
249
            assert!(
250
                pallet_services_payment::CollatorAssignmentCredits::<T>::get(para_id).is_none()
251
            );
252
        }
253

            
254
        Ok(vec![])
255
    }
256

            
257
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
258
    #[cfg(feature = "try-runtime")]
259
    fn post_upgrade(&self, _result: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
260
        let mut para_ids = BTreeSet::new();
261
        let active = pallet_registrar::RegisteredParaIds::<T>::get();
262
        let pending = pallet_registrar::PendingParaIds::<T>::get();
263
        let paused = pallet_registrar::Paused::<T>::get();
264
        para_ids.extend(active);
265
        para_ids.extend(pending.into_iter().flat_map(|(_session, active)| active));
266
        para_ids.extend(paused);
267

            
268
        for para_id in para_ids {
269
            assert_eq!(
270
                pallet_services_payment::CollatorAssignmentCredits::<T>::get(para_id),
271
                Some(T::FreeCollatorAssignmentCredits::get())
272
            );
273
        }
274

            
275
        Ok(())
276
    }
277
}
278

            
279
pub struct PolkadotXcmMigrationFixVersion<T, PolkadotXcm>(pub PhantomData<(T, PolkadotXcm)>);
280
impl<T, PolkadotXcm> Migration for PolkadotXcmMigrationFixVersion<T, PolkadotXcm>
281
where
282
    PolkadotXcm: GetStorageVersion + PalletInfoAccess,
283
    T: cumulus_pallet_xcmp_queue::Config,
284
{
285
    fn friendly_name(&self) -> &str {
286
        "MM_PolkadotXcmMigrationFixVersion"
287
    }
288

            
289
    fn migrate(&self, _available_weight: Weight) -> Weight {
290
        if <PolkadotXcm as GetStorageVersion>::on_chain_storage_version() == 0 {
291
            StorageVersion::new(1).put::<PolkadotXcm>();
292
            return T::DbWeight::get().writes(1);
293
        }
294
        Weight::default()
295
    }
296

            
297
    #[cfg(feature = "try-runtime")]
298
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
299
        ensure!(
300
            <PolkadotXcm as GetStorageVersion>::on_chain_storage_version() == 0,
301
            "PolkadotXcm storage version should be 0"
302
        );
303
        Ok(vec![])
304
    }
305

            
306
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
307
    #[cfg(feature = "try-runtime")]
308
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
309
        ensure!(
310
            <PolkadotXcm as GetStorageVersion>::on_chain_storage_version() == 1,
311
            "PolkadotXcm storage version should be 1"
312
        );
313
        Ok(())
314
    }
315
}
316

            
317
pub struct XcmpQueueMigrationFixVersion<T, XcmpQueue>(pub PhantomData<(T, XcmpQueue)>);
318
impl<T, XcmpQueue> Migration for XcmpQueueMigrationFixVersion<T, XcmpQueue>
319
where
320
    XcmpQueue: GetStorageVersion + PalletInfoAccess,
321
    T: cumulus_pallet_xcmp_queue::Config,
322
{
323
    fn friendly_name(&self) -> &str {
324
        "MM_XcmpQueueMigrationFixVersion"
325
    }
326

            
327
    fn migrate(&self, _available_weight: Weight) -> Weight {
328
        if <XcmpQueue as GetStorageVersion>::on_chain_storage_version() == 0 {
329
            StorageVersion::new(2).put::<XcmpQueue>();
330
            return T::DbWeight::get().writes(1);
331
        }
332
        Weight::default()
333
    }
334

            
335
    #[cfg(feature = "try-runtime")]
336
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
337
        ensure!(
338
            <XcmpQueue as GetStorageVersion>::on_chain_storage_version() == 0,
339
            "XcmpQueue storage version should be 0"
340
        );
341
        Ok(vec![])
342
    }
343

            
344
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
345
    #[cfg(feature = "try-runtime")]
346
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
347
        // Greater than because the post_upgrade is run after all the migrations, so
348
        // it can be greater if the following XcmpQueue migrations are applied in the
349
        // same runtime
350
        ensure!(
351
            <XcmpQueue as GetStorageVersion>::on_chain_storage_version() >= 2,
352
            "XcmpQueue storage version should be at least 2"
353
        );
354
        Ok(())
355
    }
356
}
357

            
358
pub struct XcmpQueueMigrationV3<T>(pub PhantomData<T>);
359
impl<T> Migration for XcmpQueueMigrationV3<T>
360
where
361
    T: cumulus_pallet_xcmp_queue::Config,
362
{
363
    fn friendly_name(&self) -> &str {
364
        "MM_XcmpQueueMigrationV3"
365
    }
366

            
367
    fn migrate(&self, _available_weight: Weight) -> Weight {
368
        cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3::<T>::on_runtime_upgrade()
369
    }
370

            
371
    // #[cfg(feature = "try-runtime")]
372
    // let mut pre_upgrade_result: Vec<u8>;
373

            
374
    #[cfg(feature = "try-runtime")]
375
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
376
        cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3::<T>::pre_upgrade()
377
    }
378

            
379
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
380
    #[cfg(feature = "try-runtime")]
381
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
382
        cumulus_pallet_xcmp_queue::migration::v3::MigrationToV3::<T>::post_upgrade(state)
383
    }
384
}
385

            
386
pub struct XcmpQueueMigrationV4<T>(pub PhantomData<T>);
387
impl<T> Migration for XcmpQueueMigrationV4<T>
388
where
389
    T: cumulus_pallet_xcmp_queue::Config,
390
{
391
    fn friendly_name(&self) -> &str {
392
        "MM_XcmpQueueMigrationV4"
393
    }
394

            
395
    fn migrate(&self, _available_weight: Weight) -> Weight {
396
        cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::<T>::on_runtime_upgrade()
397
    }
398

            
399
    #[cfg(feature = "try-runtime")]
400
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
401
        cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::<T>::pre_upgrade()
402
    }
403

            
404
    // Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
405
    #[cfg(feature = "try-runtime")]
406
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
407
        cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4::<T>::post_upgrade(state)
408
    }
409
}
410

            
411
pub struct RegistrarPendingVerificationValueToMap<T>(pub PhantomData<T>);
412
impl<T> Migration for RegistrarPendingVerificationValueToMap<T>
413
where
414
    T: pallet_registrar::Config,
415
{
416
    fn friendly_name(&self) -> &str {
417
        "TM_RegistrarPendingVerificationValueToMap"
418
    }
419

            
420
1
    fn migrate(&self, _available_weight: Weight) -> Weight {
421
1
        let para_ids: Vec<ParaId> = frame_support::storage::unhashed::take(
422
1
            &frame_support::storage::storage_prefix(b"Registrar", b"PendingVerification"),
423
1
        )
424
1
        .unwrap_or_default();
425
1

            
426
1
        let total_weight = T::DbWeight::get()
427
1
            .reads(1)
428
1
            .saturating_add(T::DbWeight::get().writes(1));
429

            
430
5
        for para_id in para_ids {
431
4
            total_weight.saturating_add(T::DbWeight::get().writes(1));
432
4
            pallet_registrar::PendingVerification::<T>::insert(para_id, ());
433
4
        }
434

            
435
1
        total_weight
436
1
    }
437

            
438
    #[cfg(feature = "try-runtime")]
439
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
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
        Ok(())
447
    }
448
}
449

            
450
pub struct RegistrarParaManagerMigration<T>(pub PhantomData<T>);
451
impl<T> Migration for RegistrarParaManagerMigration<T>
452
where
453
    T: pallet_registrar::Config,
454
{
455
    fn friendly_name(&self) -> &str {
456
        "TM_RegistrarParaManagerMigration"
457
    }
458

            
459
    fn migrate(&self, _available_weight: Weight) -> Weight {
460
        let mut total_weight = Weight::default();
461
        for (para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
462
            pallet_registrar::ParaManager::<T>::insert(para_id, deposit.creator);
463
            total_weight = total_weight.saturating_add(
464
                T::DbWeight::get()
465
                    .reads(1)
466
                    .saturating_add(T::DbWeight::get().writes(1)),
467
            );
468
        }
469

            
470
        total_weight
471
    }
472

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

            
478
    #[cfg(feature = "try-runtime")]
479
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
480
        Ok(())
481
    }
482
}
483

            
484
pub struct RegistrarReserveToHoldMigration<T>(pub PhantomData<T>);
485
impl<T> Migration for RegistrarReserveToHoldMigration<T>
486
where
487
    T: pallet_registrar::Config,
488
    T: pallet_balances::Config,
489
    <T as pallet_balances::Config>::RuntimeHoldReason: From<pallet_registrar::HoldReason>,
490
    <T as pallet_balances::Config>::Balance: From<
491
        <<T as pallet_registrar::Config>::Currency as frame_support::traits::fungible::Inspect<
492
            T::AccountId,
493
        >>::Balance,
494
    >,
495
    <T as pallet_balances::Config>::Balance: From<u128>,
496
{
497
    fn friendly_name(&self) -> &str {
498
        "TM_RegistrarReserveToHoldMigration"
499
    }
500

            
501
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
502
2
        let mut total_weight = Weight::default();
503
4
        for (_para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
504
2
            pallet_balances::Pallet::<T>::unreserve(&deposit.creator, deposit.deposit.into());
505
2
            let _ = pallet_balances::Pallet::<T>::hold(
506
2
                &HoldReason::RegistrarDeposit.into(),
507
2
                &deposit.creator,
508
2
                deposit.deposit.into(),
509
2
            );
510
2
            total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(2, 2));
511
2
        }
512

            
513
2
        total_weight
514
2
    }
515

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

            
520
        for (_para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
521
            ensure!(
522
                pallet_balances::Pallet::<T>::reserved_balance(&deposit.creator)
523
                    >= deposit.deposit.into(),
524
                "Reserved balanced cannot be less than deposit amount"
525
            );
526

            
527
            ensure!(
528
                pallet_balances::Pallet::<T>::balance_on_hold(
529
                    &HoldReason::RegistrarDeposit.into(),
530
                    &deposit.creator
531
                ) == 0u128.into(),
532
                "Balance on hold for RegistrarDeposit should be 0"
533
            );
534
        }
535
        Ok(vec![])
536
    }
537

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

            
542
        for (_para_id, deposit) in pallet_registrar::RegistrarDeposit::<T>::iter() {
543
            ensure!(
544
                pallet_balances::Pallet::<T>::balance_on_hold(
545
                    &HoldReason::RegistrarDeposit.into(),
546
                    &deposit.creator
547
                ) >= deposit.deposit.into(),
548
                "Balance on hold for RegistrarDeposit should be deposit"
549
            );
550
        }
551

            
552
        Ok(())
553
    }
554
}
555
pub struct MigrateToLatestXcmVersion<Runtime>(PhantomData<Runtime>);
556
impl<Runtime> Migration for MigrateToLatestXcmVersion<Runtime>
557
where
558
    pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>:
559
        frame_support::traits::OnRuntimeUpgrade,
560
{
561
690
    fn friendly_name(&self) -> &str {
562
690
        "MM_MigrateToLatestXcmVersion5"
563
690
    }
564

            
565
    fn migrate(&self, _available_weight: Weight) -> Weight {
566
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::on_runtime_upgrade()
567
    }
568

            
569
    #[cfg(feature = "try-runtime")]
570
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
571
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::pre_upgrade()
572
    }
573

            
574
    #[cfg(feature = "try-runtime")]
575
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
576
        pallet_xcm::migration::MigrateToLatestXcmVersion::<Runtime>::post_upgrade(state)
577
    }
578
}
579

            
580
pub struct DataPreserversAssignmentsMigration<T>(pub PhantomData<T>);
581
impl<T> Migration for DataPreserversAssignmentsMigration<T>
582
where
583
    T: pallet_data_preservers::Config + pallet_registrar::Config,
584
    T::AccountId: From<[u8; 32]>,
585
{
586
    fn friendly_name(&self) -> &str {
587
        "TM_DataPreserversAssignmentsMigration"
588
    }
589

            
590
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
591
        use {
592
            frame_support::BoundedBTreeSet,
593
            frame_system::RawOrigin,
594
            pallet_data_preservers::{AssignmentProcessor, ParaIdsFilter, Profile, ProfileMode},
595
        };
596

            
597
2
        let mut total_weight = Weight::default();
598
2

            
599
2
        let (request, _extra, witness) = T::AssignmentProcessor::free_variant_values()
600
2
            .expect("free variant values are necessary to perform migration");
601
2

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

            
604
2
        let pallet_prefix: &[u8] = b"DataPreservers";
605
2
        let storage_item_prefix: &[u8] = b"BootNodes";
606
2
        let bootnodes_storage: Vec<_> = storage_key_iter::<
607
2
            ParaId,
608
2
            BoundedVec<BoundedVec<u8, T::MaxNodeUrlLen>, T::MaxAssignmentsPerParaId>,
609
2
            Blake2_128Concat,
610
2
        >(pallet_prefix, storage_item_prefix)
611
2
        .collect();
612
2

            
613
2
        total_weight = total_weight.saturating_add(
614
2
            T::DbWeight::get()
615
2
                .reads(bootnodes_storage.len() as u64)
616
2
                .saturating_add(T::DbWeight::get().writes(bootnodes_storage.len() as u64)),
617
2
        );
618

            
619
6
        for (para_id, bootnodes) in bootnodes_storage {
620
12
            for bootnode_url in bootnodes {
621
8
                let profile = Profile {
622
8
                    url: bootnode_url,
623
8
                    para_ids: ParaIdsFilter::Whitelist({
624
8
                        let mut set = BoundedBTreeSet::new();
625
8
                        set.try_insert(para_id).expect("to be in bound");
626
8
                        set
627
8
                    }),
628
8
                    mode: ProfileMode::Bootnode,
629
8
                    assignment_request: request.clone(),
630
8
                };
631
8

            
632
8
                let profile_id = pallet_data_preservers::NextProfileId::<T>::get();
633

            
634
8
                if let Some(weight) = pallet_data_preservers::Pallet::<T>::force_create_profile(
635
8
                    RawOrigin::Root.into(),
636
8
                    profile,
637
8
                    dummy_profile_owner.clone(),
638
8
                )
639
8
                .expect("to create profile")
640
8
                .actual_weight
641
                {
642
                    total_weight = total_weight.saturating_add(weight);
643
8
                }
644

            
645
8
                if let Some(weight) = pallet_data_preservers::Pallet::<T>::force_start_assignment(
646
8
                    RawOrigin::Root.into(),
647
8
                    profile_id,
648
8
                    para_id,
649
8
                    witness.clone(),
650
8
                )
651
8
                .expect("to start assignment")
652
8
                .actual_weight
653
                {
654
                    total_weight = total_weight.saturating_add(weight);
655
8
                }
656
            }
657
        }
658

            
659
2
        let _ = clear_storage_prefix(pallet_prefix, storage_item_prefix, &[], None, None);
660
2

            
661
2
        total_weight
662
2
    }
663

            
664
    #[cfg(feature = "try-runtime")]
665
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
666
        use parity_scale_codec::Encode;
667

            
668
        let pallet_prefix: &[u8] = b"DataPreservers";
669
        let storage_item_prefix: &[u8] = b"BootNodes";
670
        let state: Vec<_> = storage_key_iter::<
671
            ParaId,
672
            BoundedVec<BoundedVec<u8, T::MaxNodeUrlLen>, T::MaxAssignmentsPerParaId>,
673
            Blake2_128Concat,
674
        >(pallet_prefix, storage_item_prefix)
675
        .collect();
676

            
677
        Ok(state.encode())
678
    }
679

            
680
    #[cfg(feature = "try-runtime")]
681
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
682
        use parity_scale_codec::Decode;
683

            
684
        let pallet_prefix: &[u8] = b"DataPreservers";
685
        let storage_item_prefix: &[u8] = b"BootNodes";
686

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

            
690
        for (para_id, bootnodes) in pre_state {
691
            let assignments = pallet_data_preservers::Assignments::<T>::get(para_id);
692
            assert_eq!(assignments.len(), bootnodes.len());
693

            
694
            let profiles: Vec<_> =
695
                pallet_data_preservers::Pallet::<T>::assignments_profiles(para_id).collect();
696

            
697
            for bootnode in bootnodes {
698
                assert_eq!(
699
                    profiles
700
                        .iter()
701
                        .filter(|profile| profile.url == bootnode)
702
                        .count(),
703
                    1
704
                );
705
            }
706
        }
707

            
708
        assert_eq!(
709
            storage_key_iter::<
710
                ParaId,
711
                BoundedVec<BoundedVec<u8, T::MaxNodeUrlLen>, T::MaxAssignmentsPerParaId>,
712
                Blake2_128Concat,
713
            >(pallet_prefix, storage_item_prefix)
714
            .count(),
715
            0
716
        );
717

            
718
        Ok(())
719
    }
720
}
721

            
722
pub struct ForeignAssetCreatorMigration<Runtime>(pub PhantomData<Runtime>);
723

            
724
impl<Runtime> Migration for ForeignAssetCreatorMigration<Runtime>
725
where
726
    Runtime: pallet_foreign_asset_creator::Config,
727
    <Runtime as pallet_foreign_asset_creator::Config>::ForeignAsset:
728
        TryFrom<xcm::v3::MultiLocation>,
729
{
730
    fn friendly_name(&self) -> &str {
731
        "TM_ForeignAssetCreatorMigration"
732
    }
733

            
734
    fn migrate(&self, _available_weight: Weight) -> Weight {
735
        use frame_support::pallet_prelude::*;
736

            
737
        use xcm::v3::MultiLocation as OldLocation;
738

            
739
        let pallet_prefix = AssetIdToForeignAsset::<Runtime>::pallet_prefix();
740
        let asset_id_to_foreign_asset_storage_prefix =
741
            AssetIdToForeignAsset::<Runtime>::storage_prefix();
742
        let foreign_asset_to_asset_id_prefix = ForeignAssetToAssetId::<Runtime>::storage_prefix();
743

            
744
        // Data required to migrate ForeignAsset values
745
        // Read all the data into memory.
746
        let asset_id_to_foreign_asset_data: Vec<_> =
747
            storage_key_iter::<AssetId<Runtime>, OldLocation, Blake2_128Concat>(
748
                pallet_prefix,
749
                asset_id_to_foreign_asset_storage_prefix,
750
            )
751
            .drain()
752
            .collect();
753

            
754
        // Data required to migrate ForeignAsset keys
755
        let foreign_asset_to_asset_id_data: Vec<_> =
756
            storage_key_iter::<OldLocation, AssetId<Runtime>, Blake2_128Concat>(
757
                pallet_prefix,
758
                foreign_asset_to_asset_id_prefix,
759
            )
760
            .drain()
761
            .collect();
762

            
763
        let migrated_count = asset_id_to_foreign_asset_data
764
            .len()
765
            .saturating_add(foreign_asset_to_asset_id_data.len());
766

            
767
        log::info!("Migrating {:?} elements", migrated_count);
768

            
769
        // Write to the new storage with removed and added fields
770
        for (asset_id, old_location) in asset_id_to_foreign_asset_data {
771
            if let Ok(new_location) = Runtime::ForeignAsset::try_from(old_location) {
772
                AssetIdToForeignAsset::<Runtime>::insert(asset_id, new_location);
773
            } else {
774
                log::warn!("Location could not be converted safely to xcmV4")
775
            }
776
        }
777

            
778
        for (old_location, asset_id) in foreign_asset_to_asset_id_data {
779
            if let Ok(new_location) = Runtime::ForeignAsset::try_from(old_location) {
780
                ForeignAssetToAssetId::<Runtime>::insert(new_location, asset_id);
781
            } else {
782
                log::warn!("Location could not be converted safely to xcmV4")
783
            }
784
        }
785

            
786
        // One db read and one db write per element, plus the on-chain storage
787
        Runtime::DbWeight::get().reads_writes(migrated_count as u64, 2 * migrated_count as u64)
788
    }
789

            
790
    #[cfg(feature = "try-runtime")]
791
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
792
        Ok(vec![])
793
    }
794

            
795
    #[cfg(feature = "try-runtime")]
796
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
797
        Ok(())
798
    }
799
}
800

            
801
pub struct ExternalValidatorsInitialMigration<Runtime>(pub PhantomData<Runtime>);
802

            
803
impl<Runtime> Migration for ExternalValidatorsInitialMigration<Runtime>
804
where
805
    Runtime: pallet_external_validators::Config,
806
    Runtime: pallet_session::Config<
807
        ValidatorId = <Runtime as pallet_external_validators::Config>::ValidatorId,
808
    >,
809
{
810
    fn friendly_name(&self) -> &str {
811
        "TM_ExternalValidatorsInitialMigration"
812
    }
813

            
814
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
815
        use frame_support::pallet_prelude::*;
816

            
817
        // Set initial WhitelistedValidators to current validators from pallet session
818
2
        let session_keys = pallet_session::QueuedKeys::<Runtime>::get();
819
2
        let session_validators = BoundedVec::truncate_from(
820
2
            session_keys
821
2
                .into_iter()
822
4
                .map(|(validator, _keys)| validator)
823
2
                .collect(),
824
2
        );
825
2
        pallet_external_validators::WhitelistedValidators::<Runtime>::put(session_validators);
826
2

            
827
2
        // Kill storage of ValidatorManager pallet
828
2
        let pallet_prefix: &[u8] = b"ValidatorManager";
829
2
        let _ = clear_storage_prefix(pallet_prefix, b"", b"", None, None);
830
2

            
831
2
        // One db read and one db write per element, plus the on-chain storage
832
2
        Runtime::DbWeight::get().reads_writes(1, 1)
833
2
    }
834

            
835
    #[cfg(feature = "try-runtime")]
836
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
837
        Ok(vec![])
838
    }
839

            
840
    #[cfg(feature = "try-runtime")]
841
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
842
        Ok(())
843
    }
844
}
845

            
846
pub struct MigrateMMRLeafPallet<T>(pub PhantomData<T>);
847

            
848
impl<T: frame_system::Config> Migration for MigrateMMRLeafPallet<T> {
849
    fn friendly_name(&self) -> &str {
850
        "SM_MigrateMMRLeafPallet"
851
    }
852

            
853
2
    fn migrate(&self, available_weight: Weight) -> Weight {
854
2
        let new_name =
855
2
            <<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
856
2
                pallet_beefy_mmr::Pallet<T>,
857
2
            >()
858
2
            .expect("pallet_beefy_mmr must be part of dancelight before this migration");
859
2
        move_pallet(Self::old_pallet_name().as_bytes(), new_name.as_bytes());
860
2
        available_weight
861
2
    }
862

            
863
    #[cfg(feature = "try-runtime")]
864
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
865
        Ok(vec![])
866
    }
867

            
868
    #[cfg(feature = "try-runtime")]
869
    fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
870
        Ok(())
871
    }
872
}
873

            
874
impl<T> MigrateMMRLeafPallet<T> {
875
4
    pub fn old_pallet_name() -> &'static str {
876
4
        "MMRLeaf"
877
4
    }
878
}
879

            
880
pub struct BondedErasTimestampMigration<Runtime>(pub PhantomData<Runtime>);
881

            
882
impl<Runtime> Migration for BondedErasTimestampMigration<Runtime>
883
where
884
    Runtime: pallet_external_validator_slashes::Config,
885
{
886
73
    fn friendly_name(&self) -> &str {
887
73
        "TM_ExternalValidatorSlashesBondedErasTimestampMigration"
888
73
    }
889

            
890
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
891
        use frame_support::pallet_prelude::*;
892

            
893
2
        let bonded_eras: Vec<(sp_staking::EraIndex, sp_staking::SessionIndex)> =
894
2
            frame_support::storage::unhashed::get(
895
2
                &pallet_external_validator_slashes::BondedEras::<Runtime>::hashed_key(),
896
2
            )
897
2
            .unwrap_or_default();
898
2
        let new_eras = bonded_eras
899
2
            .iter()
900
6
            .map(|(era, session)| (*era, *session, 0u64))
901
2
            .collect();
902
2
        pallet_external_validator_slashes::BondedEras::<Runtime>::set(new_eras);
903
2

            
904
2
        // One db read and one db write per element, plus the on-chain storage
905
2
        Runtime::DbWeight::get().reads_writes(1, 1)
906
2
    }
907

            
908
    #[cfg(feature = "try-runtime")]
909
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
910
        use frame_support::pallet_prelude::*;
911

            
912
        let previous_bonded_eras: Vec<(sp_staking::EraIndex, sp_staking::SessionIndex)> =
913
            frame_support::storage::unhashed::get(
914
                &pallet_external_validator_slashes::BondedEras::<Runtime>::hashed_key(),
915
            )
916
            .unwrap_or_default();
917

            
918
        Ok(previous_bonded_eras.encode())
919
    }
920

            
921
    #[cfg(feature = "try-runtime")]
922
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
923
        use parity_scale_codec::Decode;
924
        let previous_bonded_eras: Vec<(sp_staking::EraIndex, sp_staking::SessionIndex)> =
925
            Decode::decode(&mut &state[..]).expect("state to be decoded properly");
926
        let new_eras = pallet_external_validator_slashes::BondedEras::<Runtime>::get();
927
        for (i, bonded) in new_eras.iter().enumerate() {
928
            assert_eq!(previous_bonded_eras[i].0, bonded.0);
929
            assert_eq!(previous_bonded_eras[i].1, bonded.1);
930
            assert_eq!(bonded.2, 0u64);
931
        }
932
        Ok(())
933
    }
934
}
935

            
936
// Copied from
937
// cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs
938
// Changed westend => rococo
939
pub mod snowbridge_system_migration {
940
    use super::*;
941
    use alloc::vec::Vec;
942
    use frame_support::pallet_prelude::*;
943
    use snowbridge_core::TokenId;
944
    use xcm;
945

            
946
    // Important: this cannot be called OldNativeToForeignId because that will be a different storage
947
    // item. Polkadot has a bug here.
948
8
    #[frame_support::storage_alias]
949
    pub type NativeToForeignId<T: snowbridge_pallet_system::Config> = StorageMap<
950
        snowbridge_pallet_system::Pallet<T>,
951
        Blake2_128Concat,
952
        xcm::v4::Location,
953
        TokenId,
954
        OptionQuery,
955
    >;
956

            
957
    /// One shot migration for NetworkId::Westend to NetworkId::ByGenesis(WESTEND_GENESIS_HASH)
958
    pub struct MigrationForXcmV5<T: snowbridge_pallet_system::Config>(core::marker::PhantomData<T>);
959
    impl<T: snowbridge_pallet_system::Config> frame_support::traits::OnRuntimeUpgrade
960
        for MigrationForXcmV5<T>
961
    {
962
2
        fn on_runtime_upgrade() -> Weight {
963
2
            let mut weight = T::DbWeight::get().reads(1);
964
2
            let mut len_map1 = 0;
965
2
            let mut len_map2 = 0;
966
2

            
967
2
            let translate_westend = |pre: xcm::v4::Location| -> Option<xcm::v5::Location> {
968
2
                weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
969
2
                len_map1 += 1;
970
2
                Some(xcm::v5::Location::try_from(pre).expect("valid location"))
971
2
            };
972
2
            snowbridge_pallet_system::ForeignToNativeId::<T>::translate_values(translate_westend);
973
2

            
974
2
            let old_keys = NativeToForeignId::<T>::iter_keys().collect::<Vec<_>>();
975

            
976
4
            for old_key in old_keys {
977
2
                if let Some(old_val) = NativeToForeignId::<T>::get(&old_key) {
978
2
                    snowbridge_pallet_system::NativeToForeignId::<T>::insert(
979
2
                        &xcm::v5::Location::try_from(old_key.clone()).expect("valid location"),
980
2
                        old_val,
981
2
                    );
982
2
                }
983
2
                NativeToForeignId::<T>::remove(old_key);
984
2
                weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
985
2
                len_map2 += 1;
986
            }
987

            
988
            // Additional sanity check that both mappings have the same number of elements
989
2
            assert_eq!(len_map1, len_map2);
990

            
991
2
            weight
992
2
        }
993
    }
994
}
995

            
996
pub struct SnowbridgeEthereumSystemXcmV5<Runtime>(pub PhantomData<Runtime>);
997

            
998
impl<Runtime> Migration for SnowbridgeEthereumSystemXcmV5<Runtime>
999
where
    Runtime: snowbridge_pallet_system::Config,
{
73
    fn friendly_name(&self) -> &str {
73
        "TM_SnowbridgeEthereumSystemXCMv5"
73
    }
2
    fn migrate(&self, _available_weight: Weight) -> Weight {
2
        snowbridge_system_migration::MigrationForXcmV5::<Runtime>::on_runtime_upgrade()
2
    }
    #[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(())
    }
}
pub struct MigrateParaSchedulerToV3<Runtime>(pub PhantomData<Runtime>);
impl<Runtime> Migration for MigrateParaSchedulerToV3<Runtime>
where
    Runtime: runtime_parachains::scheduler::Config,
{
73
    fn friendly_name(&self) -> &str {
73
        "TM_MigrateParaSchedulerToV3"
73
    }
    fn migrate(&self, _available_weight: Weight) -> Weight {
        runtime_parachains::scheduler::migration::MigrateV2ToV3::<Runtime>::on_runtime_upgrade()
    }
    #[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(())
    }
}
pub struct MigrateParaSharedToV1<Runtime>(pub PhantomData<Runtime>);
impl<Runtime> Migration for MigrateParaSharedToV1<Runtime>
where
    Runtime: runtime_parachains::shared::Config,
{
73
    fn friendly_name(&self) -> &str {
73
        "TM_MigrateParaSharedToV1"
73
    }
    fn migrate(&self, _available_weight: Weight) -> Weight {
        runtime_parachains::shared::migration::MigrateToV1::<Runtime>::on_runtime_upgrade()
    }
    #[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(())
    }
}
pub struct MigrateStreamPaymentNewConfigFields<Runtime>(pub PhantomData<Runtime>);
impl<Runtime> Migration for MigrateStreamPaymentNewConfigFields<Runtime>
where
    Runtime: pallet_stream_payment::Config,
{
618
    fn friendly_name(&self) -> &str {
618
        "TM_MigrateStreamPaymentNewConfigFields"
618
    }
2
    fn migrate(&self, available_weight: Weight) -> Weight {
2
        pallet_stream_payment::migrations::migrate_stream_payment_new_config_fields::<Runtime>(
2
            available_weight,
2
        )
2
    }
    #[cfg(feature = "try-runtime")]
    fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
        use pallet_stream_payment::migrations::OldStreamOf;
        use parity_scale_codec::Encode;
        let Some(stream_id) = pallet_stream_payment::Streams::<Runtime>::iter_keys().next() else {
            return Ok(vec![]);
        };
        let old_stream: OldStreamOf<Runtime> = frame_support::storage::unhashed::get(
            &pallet_stream_payment::Streams::<Runtime>::hashed_key_for(stream_id),
        )
        .expect("key was found so entry must exist");
        Ok((stream_id, old_stream).encode())
    }
    #[cfg(feature = "try-runtime")]
    fn post_upgrade(&self, state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
        use pallet_stream_payment::{migrations::OldStreamOf, ChangeRequest, Stream, StreamConfig};
        use parity_scale_codec::Decode;
        if state.is_empty() {
            // there were no streams
            return Ok(());
        }
        let (stream_id, old_stream) =
            <(Runtime::StreamId, OldStreamOf<Runtime>)>::decode(&mut &state[..])
                .expect("to decode properly");
        let new_stream = pallet_stream_payment::Streams::<Runtime>::get(stream_id)
            .expect("entry should still exist");
        let mut expected = Stream {
            source: old_stream.source,
            target: old_stream.target,
            deposit: old_stream.deposit,
            last_time_updated: old_stream.last_time_updated,
            request_nonce: old_stream.request_nonce,
            pending_request: None, // will be replaced below
            opening_deposit: old_stream.opening_deposit,
            config: StreamConfig {
                time_unit: old_stream.config.time_unit,
                asset_id: old_stream.config.asset_id,
                rate: old_stream.config.rate,
                minimum_request_deadline_delay: 0u32.into(),
                soft_minimum_deposit: 0u32.into(),
            },
        };
        if let Some(pending_request) = old_stream.pending_request {
            expected.pending_request = Some(ChangeRequest {
                requester: pending_request.requester,
                kind: pending_request.kind,
                deposit_change: pending_request.deposit_change,
                new_config: StreamConfig {
                    time_unit: pending_request.new_config.time_unit,
                    asset_id: pending_request.new_config.asset_id,
                    rate: pending_request.new_config.rate,
                    minimum_request_deadline_delay: 0u32.into(),
                    soft_minimum_deposit: 0u32.into(),
                },
            });
        }
        assert_eq!(
            new_stream, expected,
            "Migrated stream don't match expected value"
        );
        Ok(())
    }
}
pub struct FlashboxMigrations<Runtime>(PhantomData<Runtime>);
impl<Runtime> GetMigrations for FlashboxMigrations<Runtime>
where
    Runtime: pallet_balances::Config,
    Runtime: pallet_configuration::Config,
    Runtime: pallet_registrar::Config,
    Runtime: pallet_services_payment::Config,
    Runtime: pallet_data_preservers::Config,
    Runtime: pallet_stream_payment::Config,
    Runtime::AccountId: From<[u8; 32]>,
    <Runtime as pallet_balances::Config>::RuntimeHoldReason: From<pallet_registrar::HoldReason>,
    <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_services_payment =
1
        //    MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
1
        //let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());
1
        //let migrate_config_parathread_params =
1
        //    MigrateConfigurationParathreads::<Runtime>(Default::default());
1

            
1
        //let migrate_add_collator_assignment_credits =
1
        //    MigrateServicesPaymentAddCollatorAssignmentCredits::<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
        //let migrate_registrar_reserves = RegistrarReserveToHoldMigration::<Runtime>(Default::default());
1
        //let migrate_config_max_parachain_percentage = MigrateConfigurationAddParachainPercentage::<Runtime>(Default::default());
1
        let migrate_config_full_rotation_mode = MigrateConfigurationAddFullRotationMode::<Runtime>(Default::default());
1
        let migrate_stream_payment_new_config_items = MigrateStreamPaymentNewConfigFields::<Runtime>(Default::default());
1

            
1
        vec![
1
            // Applied in runtime 400
1
            //Box::new(migrate_services_payment),
1
            // Applied in runtime 400
1
            //Box::new(migrate_boot_nodes),
1
            // Applied in runtime 400
1
            //Box::new(migrate_config_parathread_params),
1
            // Applied in runtime 500
1
            //Box::new(migrate_add_collator_assignment_credits),
1
            // Applied in runtime 700
1
            //Box::new(migrate_registrar_pending_verification),
1
            // Applied in runtime 700
1
            //Box::new(migrate_registrar_manager),
1
            // Applied in runtime 700
1
            //Box::new(migrate_data_preservers_assignments),
1
            // Applied in runtime 800
1
            //Box::new(migrate_registrar_reserves),
1
            // Applied in runtime 900
1
            //Box::new(migrate_config_max_parachain_percentage),
1
            Box::new(migrate_config_full_rotation_mode),
1
            Box::new(migrate_stream_payment_new_config_items),
1
        ]
1
    }
}
pub struct DanceboxMigrations<Runtime>(PhantomData<Runtime>);
impl<Runtime> GetMigrations for DanceboxMigrations<Runtime>
where
    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: pallet_stream_payment::Config,
    <Runtime as pallet_balances::Config>::RuntimeHoldReason:
        From<pallet_pooled_staking::HoldReason>,
    Runtime: pallet_foreign_asset_creator::Config,
    <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>,
{
617
    fn get_migrations() -> Vec<Box<dyn Migration>> {
617
        // let migrate_invulnerables = MigrateInvulnerables::<Runtime>(Default::default());
617
        // let migrate_holds = MigrateHoldReason::<Runtime>(Default::default());
617
        // let migrate_config = MigrateConfigurationFullRotationPeriod::<Runtime>(Default::default());
617
        // let migrate_xcm = PolkadotXcmMigration::<Runtime>(Default::default());
617
        // let migrate_xcmp_queue = XcmpQueueMigration::<Runtime>(Default::default());
617
        // let migrate_services_payment =
617
        //     MigrateServicesPaymentAddCredits::<Runtime>(Default::default());
617
        // let migrate_boot_nodes = MigrateBootNodes::<Runtime>(Default::default());
617
        // let migrate_hold_reason_runtime_enum =
617
        //     MigrateHoldReasonRuntimeEnum::<Runtime>(Default::default());
617

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

            
617
        //let migrate_pallet_xcm_v4 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
617
        //let foreign_asset_creator_migration =
617
        //    ForeignAssetCreatorMigration::<Runtime>(Default::default());
617
        //let migrate_registrar_reserves = RegistrarReserveToHoldMigration::<Runtime>(Default::default());
617
        let migrate_config_full_rotation_mode = MigrateConfigurationAddFullRotationMode::<Runtime>(Default::default());
617
        let migrate_stream_payment_new_config_items = MigrateStreamPaymentNewConfigFields::<Runtime>(Default::default());
617
        let migrate_pallet_xcm_v5 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
617

            
617
        vec![
617
            // Applied in runtime 200
617
            //Box::new(migrate_invulnerables),
617
            // Applied in runtime 200
617
            //Box::new(migrate_holds),
617
            // Applied in runtime 300
617
            //Box::new(migrate_config),
617
            // Applied in runtime 300
617
            //Box::new(migrate_xcm),
617
            // Applied in runtime 300
617
            //Box::new(migrate_xcmp_queue),
617
            // Applied in runtime 400
617
            //Box::new(migrate_services_payment),
617
            // Applied in runtime 400
617
            //Box::new(migrate_hold_reason_runtime_enum),
617
            // Applied in runtime 400
617
            //Box::new(migrate_boot_nodes),
617
            // Applied in runtime 500
617
            //Box::new(migrate_config_parathread_params),
617
            // Applied in runtime 500
617
            //Box::new(migrate_add_collator_assignment_credits),
617
            // Applied in runtime 500
617
            //Box::new(migrate_xcmp_queue_v4),
617
            // Applied in runtime 700
617
            //Box::new(migrate_registrar_pending_verification),
617
            // Applied in runtime 700
617
            //Box::new(migrate_registrar_manager),
617
            // Applied in runtime 700
617
            //Box::new(migrate_pallet_xcm_v4),
617
            // Applied in runtime 700
617
            //Box::new(foreign_asset_creator_migration),
617
            // Applied in runtime 700
617
            //Box::new(migrate_data_preservers_assignments),
617
            // Applied in runtime 800
617
            //Box::new(migrate_registrar_reserves),
617
            // Applied in runtime 900
617
            //Box::new(migrate_config_max_parachain_percentage),
617
            Box::new(migrate_config_full_rotation_mode),
617
            Box::new(migrate_stream_payment_new_config_items),
617
            Box::new(migrate_pallet_xcm_v5),
617
        ]
617
    }
}
pub struct DancelightMigrations<Runtime>(PhantomData<Runtime>);
impl<Runtime> GetMigrations for DancelightMigrations<Runtime>
where
    Runtime: frame_system::Config,
    Runtime: pallet_external_validators::Config,
    Runtime: pallet_configuration::Config,
    Runtime: pallet_session::Config<
        ValidatorId = <Runtime as pallet_external_validators::Config>::ValidatorId,
    >,
    Runtime: pallet_external_validator_slashes::Config,
    Runtime: snowbridge_pallet_system::Config,
    Runtime: runtime_parachains::scheduler::Config,
    Runtime: runtime_parachains::shared::Config,
    Runtime: pallet_xcm::Config,
{
73
    fn get_migrations() -> Vec<Box<dyn Migration>> {
73
        let migrate_config_full_rotation_mode =
73
            MigrateConfigurationAddFullRotationMode::<Runtime>(Default::default());
73

            
73
        let external_validator_slashes_bonded_eras_timestamp =
73
            BondedErasTimestampMigration::<Runtime>(Default::default());
73
        let snowbridge_ethereum_system_xcm_v5 =
73
            SnowbridgeEthereumSystemXcmV5::<Runtime>(Default::default());
73
        let migrate_pallet_xcm_v5 = MigrateToLatestXcmVersion::<Runtime>(Default::default());
73
        let para_shared_v1_migration = MigrateParaSharedToV1::<Runtime>(Default::default());
73
        let para_scheduler_v3_migration = MigrateParaSchedulerToV3::<Runtime>(Default::default());
73
        vec![
73
            // Applied in runtime 1000
73
            //Box::new(migrate_mmr_leaf_pallet),
73
            // Applied in runtime 900
73
            //Box::new(migrate_external_validators),
73
            Box::new(migrate_config_full_rotation_mode),
73
            Box::new(external_validator_slashes_bonded_eras_timestamp),
73
            Box::new(snowbridge_ethereum_system_xcm_v5),
73
            Box::new(migrate_pallet_xcm_v5),
73
            Box::new(para_shared_v1_migration),
73
            Box::new(para_scheduler_v3_migration),
73
        ]
73
    }
}
pub struct StarlightMigrations<Runtime>(PhantomData<Runtime>);
impl<Runtime> GetMigrations for StarlightMigrations<Runtime>
where
    Runtime: frame_system::Config,
{
81
    fn get_migrations() -> Vec<Box<dyn Migration>> {
81
        vec![]
81
    }
}