use super::*; use frame_support::{ pallet_prelude::{Identity, OptionQuery}, storage_alias, traits::Get, weights::Weight, }; use sp_std::vec::Vec; use subtensor_runtime_common::NetUid; // TODO (camfairchild): TEST MIGRATION /// Module containing deprecated storage format for LoadedEmission pub mod deprecated_loaded_emission_format { use super::*; #[storage_alias] pub(super) type LoadedEmission = StorageMap, Identity, u16, Vec<(AccountIdOf, u64)>, OptionQuery>; } /// Migrates the storage to create the root network /// /// This function performs the following steps: /// 1. Checks if the root network already exists /// 2. If not, creates the root network with default settings /// 3. Removes all existing senate members /// /// # Arguments /// /// * `T` - The Config trait of the pallet /// /// # Returns /// /// * `Weight` - The computational weight of this operation /// /// # Example /// /// ```ignore /// let weight = migrate_create_root_network::(); /// ``` pub fn migrate_create_root_network() -> Weight { // Initialize weight counter let mut weight = T::DbWeight::get().reads(1); // Check if root network already exists if NetworksAdded::::get(NetUid::ROOT) { // Return early if root network already exists return weight; } // Set the root network as added NetworksAdded::::insert(NetUid::ROOT, true); // Increment the total number of networks TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); // Set the maximum number of UIDs to the number of senate members MaxAllowedUids::::insert(NetUid::ROOT, 64); // Set the maximum number of validators to all members MaxAllowedValidators::::insert(NetUid::ROOT, 64); // Set the minimum allowed weights to zero (no weight restrictions) MinAllowedWeights::::insert(NetUid::ROOT, 0); // Set default root tempo Tempo::::insert(NetUid::ROOT, 100); // Set the root network as open for registration NetworkRegistrationAllowed::::insert(NetUid::ROOT, true); // Set target registrations for validators as 1 per block TargetRegistrationsPerInterval::::insert(NetUid::ROOT, 1); // TODO: Consider if WeightsSetRateLimit should be set // WeightsSetRateLimit::::insert(NetUid::ROOT, 7200); // Accrue weight for database writes weight.saturating_accrue(T::DbWeight::get().writes(7)); // Remove all existing triumvirate votes and senate members remove_prefix::("Triumvirate", "Votes", &mut weight); remove_prefix::("SenateMembers", "Members", &mut weight); log::info!("Migrated create root network"); weight }