use super::*; use frame_support::{traits::Get, weights::Weight}; use log; use scale_info::prelude::string::String; use sp_std::vec::Vec; // --------------- Migration ------------------------------------------ /// Moves every (netuid, epoch) queue from `CRV3WeightCommitsV2` into /// `TimelockedWeightCommits`. Identical key/value layout → pure move. pub fn migrate_crv3_v2_to_timelocked() -> Weight { let mig_name: Vec = b"crv3_v2_to_timelocked_v1".to_vec(); let mut total_weight = T::DbWeight::get().reads(1); if HasMigrationRun::::get(&mig_name) { log::info!( "Migration '{}' already executed - skipping", String::from_utf8_lossy(&mig_name) ); return total_weight; } log::info!("Running migration '{}'", String::from_utf8_lossy(&mig_name)); for (netuid, epoch, old_q) in CRV3WeightCommitsV2::::drain() { total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); TimelockedWeightCommits::::insert(netuid, epoch, old_q); } HasMigrationRun::::insert(&mig_name, true); total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1)); log::info!( "Migration '{}' completed", String::from_utf8_lossy(&mig_name) ); total_weight }