pallet_domains/
migrations.rs

1//! Migration module for pallet-domains
2//!
3//! TODO: remove this module after it has been deployed to Taurus.
4
5#[cfg(not(feature = "std"))]
6extern crate alloc;
7use crate::{Config, Pallet};
8#[cfg(not(feature = "std"))]
9use alloc::collections::BTreeSet;
10use frame_support::migrations::VersionedMigration;
11use frame_support::traits::UncheckedOnRuntimeUpgrade;
12use frame_support::weights::Weight;
13#[cfg(feature = "std")]
14use std::collections::BTreeSet;
15
16pub type VersionCheckedMigrateDomainsV3ToV4<T> = VersionedMigration<
17    3,
18    4,
19    VersionUncheckedMigrateV3ToV4<T>,
20    Pallet<T>,
21    <T as frame_system::Config>::DbWeight,
22>;
23
24pub struct VersionUncheckedMigrateV3ToV4<T>(sp_std::marker::PhantomData<T>);
25impl<T: Config> UncheckedOnRuntimeUpgrade for VersionUncheckedMigrateV3ToV4<T> {
26    fn on_runtime_upgrade() -> Weight {
27        domain_balance_check_migration_migration::migrate_domain_balance_check::<T>()
28            .saturating_add(
29                domain_balance_check_migration_migration::migrate_domain_share_price_check::<T>(),
30            )
31    }
32}
33
34mod domain_balance_check_migration_migration {
35    use super::{BTreeSet, Config};
36    use crate::staking::DomainEpoch;
37    use crate::{AllowedDefaultSharePriceEpoch, DomainStakingSummary, SkipBalanceChecks};
38    use frame_support::pallet_prelude::Weight;
39    use sp_core::Get;
40    use sp_domains::DomainId;
41
42    pub(super) fn migrate_domain_balance_check<T: Config>() -> Weight {
43        // 0 read and 1 write
44        let list = BTreeSet::from([DomainId::new(0)]);
45        SkipBalanceChecks::<T>::put(list);
46        T::DbWeight::get().reads_writes(0, 1)
47    }
48
49    pub(super) fn migrate_domain_share_price_check<T: Config>() -> Weight {
50        // 1 read and 1 write
51        let domain_id = DomainId::new(0);
52        if let Some(staking_summary) = DomainStakingSummary::<T>::get(domain_id) {
53            AllowedDefaultSharePriceEpoch::<T>::put(DomainEpoch::from((
54                domain_id,
55                staking_summary.current_epoch_index,
56            )));
57        }
58        T::DbWeight::get().reads_writes(1, 1)
59    }
60}