From dea3a03d91284085e5e76b047bf2c0b91c755167 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Mon, 24 Nov 2025 16:52:03 -0800 Subject: [PATCH 01/11] chore: clean up old identity storage items --- pallets/subtensor/src/lib.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index bbec3ce934..bc4c72a614 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2049,26 +2049,11 @@ pub mod pallet { OptionQuery, >; - /// --- MAP ( coldkey ) --> identity. (DEPRECATED for V2) - #[pallet::storage] - pub type Identities = - StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOf, OptionQuery>; - /// --- MAP ( coldkey ) --> identity #[pallet::storage] pub type IdentitiesV2 = StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOfV2, OptionQuery>; - /// --- MAP ( netuid ) --> identity. (DEPRECATED for V2) - #[pallet::storage] - pub type SubnetIdentities = - StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOf, OptionQuery>; - - /// --- MAP ( netuid ) --> identityV2 (DEPRECATED for V3) - #[pallet::storage] - pub type SubnetIdentitiesV2 = - StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOfV2, OptionQuery>; - /// --- MAP ( netuid ) --> SubnetIdentityOfV3 #[pallet::storage] pub type SubnetIdentitiesV3 = From 1a0f8cc7ea03050ab25b5b1baa59d3fa9cdf0e6b Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 17:53:32 -0800 Subject: [PATCH 02/11] feat: migration for removing storage items --- .../migrate_remove_old_identity_maps.rs | 44 +++++++++++++++++++ pallets/subtensor/src/migrations/mod.rs | 1 + 2 files changed, 45 insertions(+) create mode 100644 pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs diff --git a/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs new file mode 100644 index 0000000000..a26d73eb5d --- /dev/null +++ b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs @@ -0,0 +1,44 @@ +use super::*; +use crate::HasMigrationRun; +use frame_support::{traits::Get, weights::Weight}; +use scale_info::prelude::string::String; +use sp_io::{KillStorageResult, hashing::twox_128, storage::clear_prefix}; + +pub fn migrate_remove_old_identity_maps() -> Weight { + let migration_name = b"migrate_remove_old_identity_maps".to_vec(); + let mut weight = T::DbWeight::get().reads(1); + + if HasMigrationRun::::get(&migration_name) { + log::info!( + "Migration '{:?}' has already run. Skipping.", + String::from_utf8_lossy(&migration_name); + ); + return weight; + } + + log::info( + "Running migration '{}'", + String::from_utf8_lossy(&migration_name), + ); + + // ------------------------------ + // Step 1: Remove Map entries + // ------------------------------ + remove_prefix::("SubtensorModule", "Identities", &mut weight); + remove_prefix::("SubtensorModule", "SubnetIdentities", &mut weight); + remove_prefix::("SubtensorModule", "SubnetIdentitiesV2", &mut weight); + + // ------------------------------ + // Step 2: Mark Migration as Completed + // ------------------------------ + + HasMigrationRun::::insert(&migration_name, true); + weight = weight.saturating_add(T::DbWeight::get().writes(1)); + + log::info!( + "Migration '{:?}' completed successfully.", + String::from_utf8_lossy(&migration_name); + ); + + weight +} diff --git a/pallets/subtensor/src/migrations/mod.rs b/pallets/subtensor/src/migrations/mod.rs index 41c1333a89..9309decc0e 100644 --- a/pallets/subtensor/src/migrations/mod.rs +++ b/pallets/subtensor/src/migrations/mod.rs @@ -34,6 +34,7 @@ pub mod migrate_rate_limit_keys; pub mod migrate_rate_limiting_last_blocks; pub mod migrate_remove_commitments_rate_limit; pub mod migrate_remove_network_modality; +pub mod migrate_remove_old_identity_maps; pub mod migrate_remove_stake_map; pub mod migrate_remove_tao_dividends; pub mod migrate_remove_total_hotkey_coldkey_stakes_this_interval; From 6a674d7da36ffd11f8c7d7b7c459893c0a7b3f44 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 18:08:51 -0800 Subject: [PATCH 03/11] fix rust --- pallets/subtensor/src/coinbase/root.rs | 2 -- .../src/migrations/migrate_remove_old_identity_maps.rs | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 893f855f3e..d508a0162b 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -391,8 +391,6 @@ impl Pallet { let _ = LastHotkeySwapOnNetuid::::clear_prefix(netuid, u32::MAX, None); // --- 20. Identity maps across versions (netuid-scoped). - SubnetIdentities::::remove(netuid); - SubnetIdentitiesV2::::remove(netuid); if SubnetIdentitiesV3::::contains_key(netuid) { SubnetIdentitiesV3::::remove(netuid); Self::deposit_event(Event::SubnetIdentityRemoved(netuid)); diff --git a/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs index a26d73eb5d..008ac0facf 100644 --- a/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs +++ b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs @@ -2,7 +2,6 @@ use super::*; use crate::HasMigrationRun; use frame_support::{traits::Get, weights::Weight}; use scale_info::prelude::string::String; -use sp_io::{KillStorageResult, hashing::twox_128, storage::clear_prefix}; pub fn migrate_remove_old_identity_maps() -> Weight { let migration_name = b"migrate_remove_old_identity_maps".to_vec(); @@ -11,7 +10,7 @@ pub fn migrate_remove_old_identity_maps() -> Weight { if HasMigrationRun::::get(&migration_name) { log::info!( "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name); + String::from_utf8_lossy(&migration_name) ); return weight; } @@ -37,7 +36,7 @@ pub fn migrate_remove_old_identity_maps() -> Weight { log::info!( "Migration '{:?}' completed successfully.", - String::from_utf8_lossy(&migration_name); + String::from_utf8_lossy(&migration_name) ); weight From 7c747ecb9a9b5f55b3681697b685faee2ae30e63 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 18:23:28 -0800 Subject: [PATCH 04/11] fixes for migration --- pallets/subtensor/src/macros/hooks.rs | 10 +- .../src/migrations/migrate_chain_identity.rs | 171 ------------------ .../src/migrations/migrate_identities_v2.rs | 91 ---------- .../migrate_remove_old_identity_maps.rs | 2 +- .../migrate_subnet_identities_to_v3.rs | 70 ------- pallets/subtensor/src/migrations/mod.rs | 3 - 6 files changed, 4 insertions(+), 343 deletions(-) delete mode 100644 pallets/subtensor/src/migrations/migrate_chain_identity.rs delete mode 100644 pallets/subtensor/src/migrations/migrate_identities_v2.rs delete mode 100644 pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs diff --git a/pallets/subtensor/src/macros/hooks.rs b/pallets/subtensor/src/macros/hooks.rs index 1b7d5fd77e..aab4403e3f 100644 --- a/pallets/subtensor/src/macros/hooks.rs +++ b/pallets/subtensor/src/macros/hooks.rs @@ -75,8 +75,6 @@ mod hooks { // Populate OwnedHotkeys map for coldkey swap. Doesn't update storage vesion. // Storage version v6 -> v7 .saturating_add(migrations::migrate_populate_owned_hotkeys::migrate_populate_owned::()) - // Migrate Delegate Ids on chain - .saturating_add(migrations::migrate_chain_identity::migrate_set_hotkey_identities::()) // Migrate Commit-Reval 2.0 .saturating_add(migrations::migrate_commit_reveal_v2::migrate_commit_reveal_2::()) // Migrate to RAO @@ -84,8 +82,6 @@ mod hooks { // Fix the IsNetworkMember map to be consistent with other storage maps .saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::()) .saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::()) - // Upgrade identities to V2 - .saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::()) // Set the min burn across all subnets to a new minimum .saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::()) // Set the min difficulty across all subnets to a new minimum @@ -121,8 +117,6 @@ mod hooks { .saturating_add(migrations::migrate_fix_root_subnet_tao::migrate_fix_root_subnet_tao::()) // Fix the owner disable the registration .saturating_add(migrations::migrate_set_registration_enable::migrate_set_registration_enable::()) - // Migrate Subnet Identities to V3 - .saturating_add(migrations::migrate_subnet_identities_to_v3::migrate_subnet_identities_to_v3::()) // Migrate subnet symbols to fix the shift after subnet 81 .saturating_add(migrations::migrate_subnet_symbols::migrate_subnet_symbols::()) // Migrate CRV3 add commit_block @@ -162,7 +156,9 @@ mod hooks { // Migrate pending emissions .saturating_add(migrations::migrate_pending_emissions::migrate_pending_emissions::()) // Reset unactive subnets - .saturating_add(migrations::migrate_reset_unactive_sn::migrate_reset_unactive_sn::()); + .saturating_add(migrations::migrate_reset_unactive_sn::migrate_reset_unactive_sn::()) + // Remove old identity map entries(Identities, SubnetIdentities, SubnetIdentitiesV2) + .saturating_add(migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::()); weight } diff --git a/pallets/subtensor/src/migrations/migrate_chain_identity.rs b/pallets/subtensor/src/migrations/migrate_chain_identity.rs deleted file mode 100644 index 735e63168c..0000000000 --- a/pallets/subtensor/src/migrations/migrate_chain_identity.rs +++ /dev/null @@ -1,171 +0,0 @@ -use crate::alloc::borrow::ToOwned; -use codec::Decode; -use scale_info::prelude::{string::String, vec::Vec}; -use serde::Deserialize; -use sp_core::{ConstU32, crypto::Ss58Codec}; -use sp_runtime::{AccountId32, BoundedVec}; - -use super::*; -use frame_support::{traits::Get, weights::Weight}; -use log; - -#[derive(Deserialize, Debug)] -struct RegistrationRecordJSON { - address: String, - name: String, - url: String, - description: String, -} - -fn string_to_bounded_vec(input: &str) -> Result>, &'static str> { - let vec_u8: Vec = input.to_owned().into_bytes(); - - // Check if the length is within bounds - if vec_u8.len() > 64 { - return Err("Input string is too long"); - } - - // Convert to BoundedVec - BoundedVec::>::try_from(vec_u8) - .map_err(|_| "Failed to convert to BoundedVec") -} - -pub fn migrate_set_hotkey_identities() -> Weight { - let migration_name = b"migrate_identities".to_vec(); - - // Initialize the weight with one read operation. - let mut weight = T::DbWeight::get().reads(1); - - // Check if the migration has already run - if HasMigrationRun::::get(&migration_name) { - log::info!( - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - log::info!( - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - - // Include the JSON file with delegate info - let data = include_str!("../../../../docs/delegate-info.json"); - - // Iterate over all the delegate records - if let Ok(delegates) = serde_json::from_str::>(data) { - // Iterate through the delegates - for delegate in delegates.iter() { - // Convert fields to bounded vecs - let name_result = string_to_bounded_vec(&delegate.name); - let desc_result = string_to_bounded_vec(&delegate.description); - let url_result = string_to_bounded_vec(&delegate.url); - let hotkey: AccountId32 = match AccountId32::from_ss58check(&delegate.address) { - Ok(account) => account, - Err(_) => { - log::warn!( - "Invalid SS58 address: {:?}. Skipping this delegate.", - delegate.address - ); - continue; - } - }; - let decoded_hotkey: T::AccountId = match T::AccountId::decode(&mut hotkey.as_ref()) { - Ok(decoded) => decoded, - Err(e) => { - log::warn!("Failed to decode hotkey: {e:?}. Skipping this delegate."); - continue; - } - }; - log::info!("Hotkey unwrapped: {decoded_hotkey:?}"); - - // If we should continue with real values. - let mut name: BoundedVec> = BoundedVec::default(); - let mut description: BoundedVec> = BoundedVec::default(); - let mut url: BoundedVec> = BoundedVec::default(); - if let Ok(n) = name_result { - name = n; - } - if let Ok(d) = desc_result { - description = d; - } - if let Ok(u) = url_result { - url = u; - } - - // Unwrap the real values. - let image: BoundedVec> = BoundedVec::default(); - let discord: BoundedVec> = BoundedVec::default(); - let additional: BoundedVec> = BoundedVec::default(); - - // Create the chain identity. - let identity = ChainIdentityOf { - name: name.into(), - url: url.into(), - image: image.into(), - discord: discord.into(), - description: description.into(), - additional: additional.into(), - }; - - // Log the identity details - log::info!("Setting identity for hotkey: {hotkey:?}"); - log::info!("Name: {:?}", String::from_utf8_lossy(&identity.name)); - log::info!("URL: {:?}", String::from_utf8_lossy(&identity.url)); - log::info!("Image: {:?}", String::from_utf8_lossy(&identity.image)); - log::info!("Discord: {:?}", String::from_utf8_lossy(&identity.discord)); - log::info!( - "Description: {:?}", - String::from_utf8_lossy(&identity.description) - ); - log::info!( - "Additional: {:?}", - String::from_utf8_lossy(&identity.additional) - ); - - // Check validation. - let total_length = identity - .name - .len() - .saturating_add(identity.url.len()) - .saturating_add(identity.image.len()) - .saturating_add(identity.discord.len()) - .saturating_add(identity.description.len()) - .saturating_add(identity.additional.len()); - let is_valid: bool = total_length <= 256 + 256 + 1024 + 256 + 1024 + 1024 - && identity.name.len() <= 256 - && identity.url.len() <= 256 - && identity.image.len() <= 1024 - && identity.discord.len() <= 256 - && identity.description.len() <= 1024 - && identity.additional.len() <= 1024; - if !is_valid { - log::info!("Bytes not correct"); - continue; - } - - // Get the owning coldkey. - let coldkey = Owner::::get(decoded_hotkey.clone()); - log::info!("ColdKey: {decoded_hotkey:?}"); - - weight = weight.saturating_add(T::DbWeight::get().reads(1)); - - // Sink into the map. - Identities::::insert(coldkey.clone(), identity.clone()); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - } else { - log::info!("Failed to decode JSON"); - } - // Mark the migration as completed - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - "Migration '{:?}' completed. Storage version set to 7.", - String::from_utf8_lossy(&migration_name) - ); - - // Return the migration weight. - weight -} diff --git a/pallets/subtensor/src/migrations/migrate_identities_v2.rs b/pallets/subtensor/src/migrations/migrate_identities_v2.rs deleted file mode 100644 index 505b617b2f..0000000000 --- a/pallets/subtensor/src/migrations/migrate_identities_v2.rs +++ /dev/null @@ -1,91 +0,0 @@ -use super::*; -use frame_support::weights::Weight; -use log; -use scale_info::prelude::{string::String, vec::Vec}; - -pub fn migrate_identities_to_v2() -> Weight { - use frame_support::traits::Get; - let migration_name = b"migrate_identities_to_v2".to_vec(); - - // Start counting weight - let mut weight = T::DbWeight::get().reads(1); - - // Check if we already ran this migration - if HasMigrationRun::::get(&migration_name) { - log::info!( - target: "runtime", - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - - log::info!( - target: "runtime", - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - - // ----------------------------- - // 1) Migrate Chain Identities - // ----------------------------- - let old_identities = Identities::::iter().collect::>(); - for (account_id, old_identity) in old_identities.clone() { - let new_identity = ChainIdentityV2 { - name: old_identity.name, - url: old_identity.url, - github_repo: Vec::new(), - image: old_identity.image, - discord: old_identity.discord, - description: old_identity.description, - additional: old_identity.additional, - }; - - // Insert into the new storage map - IdentitiesV2::::insert(&account_id, &new_identity); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - Identities::::remove(&account_id); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - - weight = weight.saturating_add(T::DbWeight::get().reads(old_identities.len() as u64)); - - // ----------------------------- - // 2) Migrate Subnet Identities - // ----------------------------- - let old_subnet_identities = SubnetIdentities::::iter().collect::>(); - for (netuid, old_subnet_identity) in old_subnet_identities.clone() { - let new_subnet_identity = SubnetIdentityV2 { - subnet_name: old_subnet_identity.subnet_name, - github_repo: old_subnet_identity.github_repo, - subnet_contact: old_subnet_identity.subnet_contact, - subnet_url: Vec::new(), - discord: Vec::new(), - description: Vec::new(), - additional: Vec::new(), - }; - - // Insert into the new storage map - SubnetIdentitiesV2::::insert(netuid, &new_subnet_identity); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - SubnetIdentities::::remove(netuid); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - weight = weight.saturating_add(T::DbWeight::get().reads(old_subnet_identities.len() as u64)); - - // ----------------------------- - // Mark the migration as done - // ----------------------------- - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - target: "runtime", - "Migration '{}' completed successfully.", - String::from_utf8_lossy(&migration_name) - ); - - weight -} diff --git a/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs index 008ac0facf..96dc4de2b4 100644 --- a/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs +++ b/pallets/subtensor/src/migrations/migrate_remove_old_identity_maps.rs @@ -15,7 +15,7 @@ pub fn migrate_remove_old_identity_maps() -> Weight { return weight; } - log::info( + log::info!( "Running migration '{}'", String::from_utf8_lossy(&migration_name), ); diff --git a/pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs b/pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs deleted file mode 100644 index fb892645d5..0000000000 --- a/pallets/subtensor/src/migrations/migrate_subnet_identities_to_v3.rs +++ /dev/null @@ -1,70 +0,0 @@ -use super::*; -use frame_support::weights::Weight; -use log; -use scale_info::prelude::{string::String, vec::Vec}; - -pub fn migrate_subnet_identities_to_v3() -> Weight { - use frame_support::traits::Get; - let migration_name = b"migrate_subnet_identities_to_v3".to_vec(); - - // Start counting weight - let mut weight = T::DbWeight::get().reads(1); - - // Check if we already ran this migration - if HasMigrationRun::::get(&migration_name) { - log::info!( - target: "runtime", - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - - log::info!( - target: "runtime", - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - // ----------------------------- - // 1) Migrate Subnet Identities - // ----------------------------- - let old_subnet_identities = SubnetIdentitiesV2::::iter().collect::>(); - for (netuid, old_subnet_identity) in old_subnet_identities.clone() { - // check for existing SubnetIdentitiesV3 entry, skip if found - if SubnetIdentitiesV3::::contains_key(netuid) { - continue; - } - let new_subnet_identity = SubnetIdentityV3 { - subnet_name: old_subnet_identity.subnet_name, - github_repo: old_subnet_identity.github_repo, - subnet_contact: old_subnet_identity.subnet_contact, - subnet_url: Vec::new(), - discord: Vec::new(), - description: Vec::new(), - logo_url: Vec::new(), - additional: Vec::new(), - }; - - // Insert into the new storage map - SubnetIdentitiesV3::::insert(netuid, &new_subnet_identity); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - SubnetIdentitiesV2::::remove(netuid); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - weight = weight.saturating_add(T::DbWeight::get().reads(old_subnet_identities.len() as u64)); - - // ----------------------------- - // Mark the migration as done - // ----------------------------- - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - target: "runtime", - "Migration '{}' completed successfully.", - String::from_utf8_lossy(&migration_name) - ); - - weight -} diff --git a/pallets/subtensor/src/migrations/mod.rs b/pallets/subtensor/src/migrations/mod.rs index 9309decc0e..4ad7e7abfc 100644 --- a/pallets/subtensor/src/migrations/mod.rs +++ b/pallets/subtensor/src/migrations/mod.rs @@ -5,7 +5,6 @@ use sp_io::KillStorageResult; use sp_io::hashing::twox_128; use sp_io::storage::clear_prefix; pub mod migrate_auto_stake_destination; -pub mod migrate_chain_identity; pub mod migrate_coldkey_swap_scheduled; pub mod migrate_commit_reveal_settings; pub mod migrate_commit_reveal_v2; @@ -19,7 +18,6 @@ pub mod migrate_fix_childkeys; pub mod migrate_fix_is_network_member; pub mod migrate_fix_root_subnet_tao; pub mod migrate_fix_root_tao_and_alpha_in; -pub mod migrate_identities_v2; pub mod migrate_init_tao_flow; pub mod migrate_init_total_issuance; pub mod migrate_kappa_map_to_default; @@ -50,7 +48,6 @@ pub mod migrate_set_nominator_min_stake; pub mod migrate_set_registration_enable; pub mod migrate_set_subtoken_enabled; pub mod migrate_stake_threshold; -pub mod migrate_subnet_identities_to_v3; pub mod migrate_subnet_limit_to_default; pub mod migrate_subnet_locked; pub mod migrate_subnet_symbols; From d17244421e5ecf91143b3a945742e78a1d25945e Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 18:33:55 -0800 Subject: [PATCH 05/11] fix benchmark --- pallets/subtensor/src/benchmarks.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 223c086419..476be905e9 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -446,15 +446,16 @@ mod pallet_benchmarks { Subtensor::::add_balance_to_coldkey_account(&old_coldkey, free_balance_old.into()); let name: Vec = b"The fourth Coolest Identity".to_vec(); - let identity = ChainIdentity { + let identity = ChainIdentityV2 { name, url: vec![], + github_repo: vec![], image: vec![], discord: vec![], description: vec![], additional: vec![], }; - Identities::::insert(&old_coldkey, identity); + IdentitiesV2::::insert(&old_coldkey, identity); #[extrinsic_call] _( From fb02a19f2e23eacc58a2ada7b2456f710224e217 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 18:40:58 -0800 Subject: [PATCH 06/11] fix tests --- pallets/subtensor/src/tests/serving.rs | 203 ------------------------- 1 file changed, 203 deletions(-) diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index d8a9b866d9..b52666bf26 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -5,7 +5,6 @@ use crate::Error; use crate::transaction_extension::SubtensorTransactionExtension; use crate::*; use frame_support::assert_noop; -use frame_support::pallet_prelude::Weight; use frame_support::{ assert_ok, dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, @@ -908,208 +907,6 @@ fn test_set_and_get_identity() { }); } -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test serving -- test_migrate_set_hotkey_identities --exact --nocapture -#[test] -fn test_migrate_set_hotkey_identities() { - new_test_ext(1).execute_with(|| { - // Run the migration - let weight = - crate::migrations::migrate_chain_identity::migrate_set_hotkey_identities::(); - - // Assert that the migration has run - assert!(HasMigrationRun::::get(b"migrate_identities".to_vec())); - - // Verify that some identities were set - // Note: This assumes that at least one valid identity was in the JSON file - let mut identity_count = 0; - for (_, _) in Identities::::iter() { - identity_count += 1; - } - assert!( - identity_count > 0, - "No identities were set during migration" - ); - - // Verify that the weight is non-zero - assert!( - weight != Weight::zero(), - "Migration weight should be non-zero" - ); - }); -} - -#[test] -fn test_migrate_identities_to_v2() { - new_test_ext(1).execute_with(|| { - let account_id_1 = U256::from(1); - let account_id_2 = U256::from(2); - - let chainone_name = b"ChainOne".to_vec(); - let chainone_url = b"https://chainone.example".to_vec(); - let chainone_image = b"some_image_data".to_vec(); - let chainone_discord = b"discord#1".to_vec(); - let chainone_description = b"Old chain identity".to_vec(); - let chainone_additional = b"extra-info".to_vec(); - - let chaintwo_name = b"ChainTwo".to_vec(); - let chaintwo_url = b"https://chaintwo.example".to_vec(); - let chaintwo_description = b"Another chain identity".to_vec(); - - Identities::::insert( - account_id_1, - ChainIdentity { - name: chainone_name.clone(), - url: chainone_url.clone(), - image: chainone_image.clone(), - discord: chainone_discord.clone(), - description: chainone_description.clone(), - additional: chainone_additional.clone(), - }, - ); - - Identities::::insert( - account_id_2, - ChainIdentity { - name: chaintwo_name.clone(), - url: chaintwo_url.clone(), - image: b"".to_vec(), - discord: b"".to_vec(), - description: chaintwo_description.clone(), - additional: b"".to_vec(), - }, - ); - - let old_subnet_name = b"SubnetExample".to_vec(); - let old_github_repo = b"https://github.com/org/repo".to_vec(); - let old_subnet_contact = b"subnet@example".to_vec(); - - SubnetIdentities::::insert( - NetUid::from(42), - SubnetIdentity { - subnet_name: old_subnet_name.clone(), - github_repo: old_github_repo.clone(), - subnet_contact: old_subnet_contact.clone(), - }, - ); - - assert!(Identities::::get(account_id_1).is_some()); - assert!(Identities::::get(account_id_2).is_some()); - assert!(SubnetIdentities::::get(NetUid::from(42)).is_some()); - assert!(!HasMigrationRun::::get( - b"migrate_identities_to_v2".to_vec() - )); - - let weight = crate::migrations::migrate_identities_v2::migrate_identities_to_v2::(); - - assert!( - HasMigrationRun::::get(b"migrate_identities_to_v2".to_vec()), - "Expected HasMigrationRun to be true after migration" - ); - assert!(Identities::::get(account_id_1).is_none()); - assert!(Identities::::get(account_id_2).is_none()); - assert!(SubnetIdentities::::get(NetUid::from(42)).is_none()); - - let new_identity_1 = IdentitiesV2::::get(account_id_1) - .expect("ChainOne should be migrated to IdentitiesV2"); - let expected_github_repo = b"".to_vec(); - - assert_eq!(new_identity_1.name, chainone_name); - assert_eq!(new_identity_1.url, chainone_url); - assert_eq!(new_identity_1.github_repo, expected_github_repo); - assert_eq!(new_identity_1.image, chainone_image); - assert_eq!(new_identity_1.discord, chainone_discord); - assert_eq!(new_identity_1.description, chainone_description); - assert_eq!(new_identity_1.additional, chainone_additional); - - let new_identity_2 = IdentitiesV2::::get(account_id_2) - .expect("ChainTwo should be migrated to IdentitiesV2"); - assert_eq!(new_identity_2.name, chaintwo_name); - assert_eq!(new_identity_2.url, chaintwo_url); - assert_eq!(new_identity_2.github_repo, b"".to_vec()); - - let new_subnet_identity = SubnetIdentitiesV2::::get(NetUid::from(42)) - .expect("SubnetExample should be migrated to SubnetIdentitiesV2"); - - let expected_subnet_url = b"".to_vec(); - let expected_discord = b"".to_vec(); - let expected_description = b"".to_vec(); - let expected_additional = b"".to_vec(); - - assert_eq!(new_subnet_identity.subnet_name, old_subnet_name); - assert_eq!(new_subnet_identity.github_repo, old_github_repo); - assert_eq!(new_subnet_identity.subnet_contact, old_subnet_contact); - assert_eq!(new_subnet_identity.subnet_url, expected_subnet_url); - assert_eq!(new_subnet_identity.discord, expected_discord); - assert_eq!(new_subnet_identity.description, expected_description); - assert_eq!(new_subnet_identity.additional, expected_additional); - - assert!( - weight != Weight::zero(), - "Migration weight should be non-zero" - ); - }); -} - -// SKIP_WASM_BUILD=1 RUST_LOG=DEBUG cargo test --release -p pallet-subtensor test_migrate_subnet_identities_to_v3 -- --nocapture -#[test] -fn test_migrate_subnet_identities_to_v3() { - new_test_ext(1).execute_with(|| { - let old_subnet_name = b"SubnetExample".to_vec(); - let old_github_repo = b"https://github.com/org/repo".to_vec(); - let old_subnet_contact = b"subnet@example".to_vec(); - - SubnetIdentitiesV2::::insert( - NetUid::from(16), - SubnetIdentityV2 { - subnet_name: old_subnet_name.clone(), - github_repo: old_github_repo.clone(), - subnet_contact: old_subnet_contact.clone(), - subnet_url: b"".to_vec(), - discord: b"".to_vec(), - description: b"".to_vec(), - additional: b"".to_vec(), - }, - ); - - assert!(SubnetIdentitiesV2::::get(NetUid::from(16)).is_some()); - assert!(!HasMigrationRun::::get( - b"migrate_subnet_identities_to_v3".to_vec() - )); - - let weight = - crate::migrations::migrate_subnet_identities_to_v3::migrate_subnet_identities_to_v3::< - Test, - >(); - - assert!( - HasMigrationRun::::get(b"migrate_subnet_identities_to_v3".to_vec()), - "Expected HasMigrationRun to be true after migration" - ); - assert!(SubnetIdentitiesV2::::get(NetUid::from(16)).is_none()); - - let new_subnet_identity = SubnetIdentitiesV3::::get(NetUid::from(16)) - .expect("SubnetExample should be migrated to SubnetIdentitiesV3"); - - let expected_subnet_url = b"".to_vec(); - let expected_discord = b"".to_vec(); - let expected_description = b"".to_vec(); - let expected_additional = b"".to_vec(); - - assert_eq!(new_subnet_identity.subnet_name, old_subnet_name); - assert_eq!(new_subnet_identity.github_repo, old_github_repo); - assert_eq!(new_subnet_identity.subnet_contact, old_subnet_contact); - assert_eq!(new_subnet_identity.subnet_url, expected_subnet_url); - assert_eq!(new_subnet_identity.discord, expected_discord); - assert_eq!(new_subnet_identity.description, expected_description); - assert_eq!(new_subnet_identity.additional, expected_additional); - - assert!( - weight != Weight::zero(), - "Migration weight should be non-zero" - ); - }); -} - // SKIP_WASM_BUILD=1 RUST_LOG=DEBUG cargo test --release -p pallet-subtensor test_do_set_subnet_identity -- --nocapture #[test] fn test_do_set_subnet_identity() { From 61daf55173869cb84d048245ca1ee810ce5cb162 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 19:37:30 -0800 Subject: [PATCH 07/11] tests for migration --- pallets/subtensor/src/tests/migration.rs | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index b694459eaa..ab36093964 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -2724,3 +2724,36 @@ fn test_migrate_reset_unactive_sn_idempotence() { assert_eq!(TotalIssuance::::get(), total_issuance_before); }); } + +#[test] +fn test_migrate_remove_old_identity_maps() { + let migration = crate::migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::; + + const MIGRATION_NAME: &str = "migrate_remove_old_identity_maps"; + + let pallet_name = "SubtensorModule"; + + test_remove_storage_item( + MIGRATION_NAME, + pallet_name, + "Identities", + migration, + 100, + ); + + test_remove_storage_item( + MIGRATION_NAME, + pallet_name, + "SubnetIdentities", + migration, + 100, + ); + + test_remove_storage_item( + MIGRATION_NAME, + pallet_name, + "SubnetIdentitiesV2", + migration, + 100, + ); +} From fc79576111fc7c4c3471d5ee33a0e1e154e3eec8 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 21:54:55 -0800 Subject: [PATCH 08/11] cargo fmt --- pallets/subtensor/src/tests/migration.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index ab36093964..6f2bf005bf 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -2727,19 +2727,14 @@ fn test_migrate_reset_unactive_sn_idempotence() { #[test] fn test_migrate_remove_old_identity_maps() { - let migration = crate::migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::; + let migration = + crate::migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::; const MIGRATION_NAME: &str = "migrate_remove_old_identity_maps"; let pallet_name = "SubtensorModule"; - test_remove_storage_item( - MIGRATION_NAME, - pallet_name, - "Identities", - migration, - 100, - ); + test_remove_storage_item(MIGRATION_NAME, pallet_name, "Identities", migration, 100); test_remove_storage_item( MIGRATION_NAME, From fead518a619997d1c1acaefbd1982e4937d7389b Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 21:59:24 -0800 Subject: [PATCH 09/11] bump spec_version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2171708685..8f46d2d8e2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 348, + spec_version: 349, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From e3489c5425161a146e11daa76efc2c668c43b74f Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 25 Nov 2025 22:00:14 -0800 Subject: [PATCH 10/11] bump spec_version to 351 --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8f46d2d8e2..11d3487f33 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 349, + spec_version: 351, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From a4fbd0285aaf3bb401014d1ded5030a19e2c3b5a Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Wed, 26 Nov 2025 14:24:08 -0800 Subject: [PATCH 11/11] fix: merge errors --- pallets/subtensor/src/macros/hooks.rs | 2 +- pallets/subtensor/src/tests/migration.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/hooks.rs b/pallets/subtensor/src/macros/hooks.rs index c77d4d4f50..b62263e370 100644 --- a/pallets/subtensor/src/macros/hooks.rs +++ b/pallets/subtensor/src/macros/hooks.rs @@ -158,7 +158,7 @@ mod hooks { // Reset unactive subnets .saturating_add(migrations::migrate_reset_unactive_sn::migrate_reset_unactive_sn::()) // Remove old identity map entries(Identities, SubnetIdentities, SubnetIdentitiesV2) - .saturating_add(migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::()); + .saturating_add(migrations::migrate_remove_old_identity_maps::migrate_remove_old_identity_maps::()) // Remove unknown neuron axon, certificate prom .saturating_add(migrations::migrate_remove_unknown_neuron_axon_cert_prom::migrate_remove_unknown_neuron_axon_cert_prom::()); weight diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 33cb0871ff..8d439e4e8f 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -2751,6 +2751,9 @@ fn test_migrate_remove_old_identity_maps() { migration, 100, ); +} + +#[test] fn test_migrate_remove_unknown_neuron_axon_cert_prom() { use crate::migrations::migrate_remove_unknown_neuron_axon_cert_prom::*; const MIGRATION_NAME: &[u8] = b"migrate_remove_neuron_axon_cert_prom";