Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ mod pallet_benchmarks {
fn register_network_with_identity() {
let coldkey: T::AccountId = whitelisted_caller();
let hotkey: T::AccountId = account("Alice", 0, 1);
let identity: Option<SubnetIdentityOfV3> = None;
let identity: Option<SubnetIdentityOfV4> = None;

Subtensor::<T>::set_network_registration_allowed(1.into(), true);
Subtensor::<T>::set_network_rate_limit(1);
Expand Down Expand Up @@ -1315,6 +1315,7 @@ mod pallet_benchmarks {
let descr = vec![];
let logo_url = vec![];
let add = vec![];
let agent_docs_url = vec![];

SubnetOwner::<T>::insert(netuid, coldkey.clone());
SubtokenEnabled::<T>::insert(netuid, true);
Expand All @@ -1331,6 +1332,7 @@ mod pallet_benchmarks {
descr.clone(),
logo_url.clone(),
add.clone(),
agent_docs_url.clone(),
);
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ impl<T: Config> Pallet<T> {
let _ = LastHotkeySwapOnNetuid::<T>::clear_prefix(netuid, u32::MAX, None);

// --- 20. Identity maps across versions (netuid-scoped).
if SubnetIdentitiesV3::<T>::contains_key(netuid) {
SubnetIdentitiesV3::<T>::remove(netuid);
if SubnetIdentitiesV4::<T>::contains_key(netuid) {
SubnetIdentitiesV4::<T>::remove(netuid);
Self::deposit_event(Event::SubnetIdentityRemoved(netuid));
}

Expand Down
39 changes: 36 additions & 3 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ pub mod pallet {
pub additional: Vec<u8>,
}

/// Struct for SubnetIdentitiesV3.
/// Struct for SubnetIdentitiesV3. (DEPRECATED for V4)
pub type SubnetIdentityOfV3 = SubnetIdentityV3;
/// Data structure for Subnet Identities
/// Data structure for Subnet Identities (DEPRECATED for V4)
#[crate::freeze_struct("6a441335f985a0b")]
#[derive(
Encode, Decode, DecodeWithMemTracking, Default, TypeInfo, Clone, PartialEq, Eq, Debug,
Expand All @@ -315,6 +315,34 @@ pub mod pallet {
pub additional: Vec<u8>,
}

/// Struct for SubnetIdentitiesV4.
pub type SubnetIdentityOfV4 = SubnetIdentityV4;
Copy link
Copy Markdown
Collaborator

@l0r1s l0r1s Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is useless. What should be defined is SubnetIdentityOf<T> and it should be used across the codebase to avoid having to rename everytime there is a change.

You can get an example here

/// Data structure for Subnet Identities
#[crate::freeze_struct("4b9718ba1a9cb75f")]
#[derive(
Encode, Decode, DecodeWithMemTracking, Default, TypeInfo, Clone, PartialEq, Eq, Debug,
)]
pub struct SubnetIdentityV4 {
/// The name of the subnet
pub subnet_name: Vec<u8>,
/// The github repository associated with the subnet
pub github_repo: Vec<u8>,
/// The subnet's contact
pub subnet_contact: Vec<u8>,
/// The subnet's website
pub subnet_url: Vec<u8>,
/// The subnet's discord
pub discord: Vec<u8>,
/// The subnet's description
pub description: Vec<u8>,
/// The subnet's logo
pub logo_url: Vec<u8>,
/// Additional information about the subnet
pub additional: Vec<u8>,
/// The subnet's agent documentation URL
pub agent_docs_url: Vec<u8>,
}

/// Enum for recycle or burn for the owner_uid(s)
#[derive(TypeInfo, Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, Debug)]
pub enum RecycleOrBurnEnum {
Expand Down Expand Up @@ -2122,11 +2150,16 @@ pub mod pallet {
pub type IdentitiesV2<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOfV2, OptionQuery>;

/// --- MAP ( netuid ) --> SubnetIdentityOfV3
/// --- MAP ( netuid ) --> SubnetIdentityOfV3 (DEPRECATED for V4)
#[pallet::storage]
pub type SubnetIdentitiesV3<T: Config> =
StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOfV3, OptionQuery>;

/// --- MAP ( netuid ) --> SubnetIdentityOfV4
#[pallet::storage]
pub type SubnetIdentitiesV4<T: Config> =
StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOfV4, OptionQuery>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. We shouldn't be adding a new storage map for each version.


/// =================================
/// ==== Axon / Promo Endpoints =====
/// =================================
Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ mod dispatches {
description: Vec<u8>,
logo_url: Vec<u8>,
additional: Vec<u8>,
agent_docs_url: Vec<u8>,
) -> DispatchResult {
Self::do_set_subnet_identity(
origin,
Expand All @@ -1450,6 +1451,7 @@ mod dispatches {
description,
logo_url,
additional,
agent_docs_url,
)
}

Expand All @@ -1461,7 +1463,7 @@ mod dispatches {
pub fn register_network_with_identity(
origin: OriginFor<T>,
hotkey: T::AccountId,
identity: Option<SubnetIdentityOfV3>,
identity: Option<SubnetIdentityOfV4>,
) -> DispatchResult {
Self::do_register_network(origin, &hotkey, 1, identity)
}
Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ mod hooks {
// Fix staking hot keys
.saturating_add(migrations::migrate_fix_staking_hot_keys::migrate_fix_staking_hot_keys::<T>())
// Migrate coldkey swap scheduled to announcements
.saturating_add(migrations::migrate_coldkey_swap_scheduled_to_announcements::migrate_coldkey_swap_scheduled_to_announcements::<T>());
.saturating_add(migrations::migrate_coldkey_swap_scheduled_to_announcements::migrate_coldkey_swap_scheduled_to_announcements::<T>())
// Migrate SubnetIdentitiesV3 to SubnetIdentitiesV4
.saturating_add(migrations::migrate_subnet_identity_v3_to_v4::migrate_subnet_identity_v3_to_v4::<T>());
weight
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use super::*;
use crate::HasMigrationRun;
use frame_support::{traits::Get, weights::Weight};
use scale_info::prelude::string::String;

pub fn migrate_subnet_identity_v3_to_v4<T: Config>() -> Weight {
let migration_name = b"migrate_subnet_identity_v3_to_v4".to_vec();
let mut weight = T::DbWeight::get().reads(1);

if HasMigrationRun::<T>::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),
);

let mut migrated_count: u64 = 0;

for (netuid, v3_identity) in SubnetIdentitiesV3::<T>::iter() {
let v4_identity = SubnetIdentityOfV4 {
subnet_name: v3_identity.subnet_name,
github_repo: v3_identity.github_repo,
subnet_contact: v3_identity.subnet_contact,
subnet_url: v3_identity.subnet_url,
discord: v3_identity.discord,
description: v3_identity.description,
logo_url: v3_identity.logo_url,
additional: v3_identity.additional,
agent_docs_url: vec![],
};
SubnetIdentitiesV4::<T>::insert(netuid, v4_identity);
migrated_count += 1;
}

weight = weight.saturating_add(T::DbWeight::get().reads(migrated_count));
weight = weight.saturating_add(T::DbWeight::get().writes(migrated_count));

// Remove old V3 entries
remove_prefix::<T>("SubtensorModule", "SubnetIdentitiesV3", &mut weight);

HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

log::info!(
"Migration '{:?}' completed successfully. Migrated {migrated_count:?} subnet identities.",
String::from_utf8_lossy(&migration_name)
);

weight
}
Comment on lines +6 to +52
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done in place for V3.

1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub mod migrate_stake_threshold;
pub mod migrate_subnet_limit_to_default;
pub mod migrate_subnet_locked;
pub mod migrate_subnet_symbols;
pub mod migrate_subnet_identity_v3_to_v4;
pub mod migrate_subnet_volume;
pub mod migrate_to_v1_separate_emission;
pub mod migrate_to_v2_fixed_total_stake;
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/rpc_info/dynamic_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use substrate_fixed::types::I96F32;
use subtensor_macros::freeze_struct;
use subtensor_runtime_common::{AlphaBalance, NetUid, TaoBalance};

#[freeze_struct("cf677afa654c96a6")]
#[freeze_struct("1caba5f448641f8a")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct DynamicInfo<AccountId: TypeInfo + Encode + Decode> {
netuid: Compact<NetUid>,
Expand All @@ -28,7 +28,7 @@ pub struct DynamicInfo<AccountId: TypeInfo + Encode + Decode> {
pending_root_emission: Compact<TaoBalance>,
subnet_volume: Compact<u128>,
network_registered_at: Compact<u64>,
subnet_identity: Option<SubnetIdentityV3>,
subnet_identity: Option<SubnetIdentityV4>,
moving_price: I96F32,
}

Expand Down Expand Up @@ -68,7 +68,7 @@ impl<T: Config> Pallet<T> {
pending_root_emission: TaoBalance::ZERO.into(),
subnet_volume: SubnetVolume::<T>::get(netuid).into(),
network_registered_at: NetworkRegisteredAt::<T>::get(netuid).into(),
subnet_identity: SubnetIdentitiesV3::<T>::get(netuid),
subnet_identity: SubnetIdentitiesV4::<T>::get(netuid),
moving_price: SubnetMovingPrice::<T>::get(netuid),
})
}
Expand Down
12 changes: 6 additions & 6 deletions pallets/subtensor/src/rpc_info/metagraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use substrate_fixed::types::I96F32;
use subtensor_macros::freeze_struct;
use subtensor_runtime_common::{AlphaBalance, MechId, NetUid, NetUidStorageIndex, TaoBalance};

#[freeze_struct("fbab6d1e7f3c69ae")]
#[freeze_struct("ef0a499c338d0215")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct Metagraph<AccountId: TypeInfo + Encode + Decode> {
// Subnet index
Expand All @@ -19,7 +19,7 @@ pub struct Metagraph<AccountId: TypeInfo + Encode + Decode> {
// Name and symbol
name: Vec<Compact<u8>>, // name
symbol: Vec<Compact<u8>>, // token symbol
identity: Option<SubnetIdentityV3>, // identity information.
identity: Option<SubnetIdentityV4>, // identity information.
network_registered_at: Compact<u64>, // block at registration

// Keys for owner.
Expand Down Expand Up @@ -110,7 +110,7 @@ pub struct Metagraph<AccountId: TypeInfo + Encode + Decode> {
alpha_dividends_per_hotkey: Vec<(AccountId, Compact<AlphaBalance>)>, // List of dividend payout in alpha via subnet.
}

#[freeze_struct("3ff2befdb7b393ea")]
#[freeze_struct("25b9044298e38eeb")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct SelectiveMetagraph<AccountId: TypeInfo + Encode + Decode + Clone> {
// Subnet index
Expand All @@ -119,7 +119,7 @@ pub struct SelectiveMetagraph<AccountId: TypeInfo + Encode + Decode + Clone> {
// Name and symbol
name: Option<Vec<Compact<u8>>>, // name
symbol: Option<Vec<Compact<u8>>>, // token symbol
identity: Option<Option<SubnetIdentityV3>>, // identity information
identity: Option<Option<SubnetIdentityV4>>, // identity information
network_registered_at: Option<Compact<u64>>, // block at registration

// Keys for owner.
Expand Down Expand Up @@ -673,7 +673,7 @@ impl<T: Config> Pallet<T> {
.into_iter()
.map(Compact)
.collect(), // Symbol.
identity: SubnetIdentitiesV3::<T>::get(netuid), // identity information.
identity: SubnetIdentitiesV4::<T>::get(netuid), // identity information.
network_registered_at: NetworkRegisteredAt::<T>::get(netuid).into(), // block at registration

// Keys for owner.
Expand Down Expand Up @@ -916,7 +916,7 @@ impl<T: Config> Pallet<T> {
},
Some(SelectiveMetagraphIndex::Identity) => SelectiveMetagraph {
netuid: netuid.into(),
identity: Some(SubnetIdentitiesV3::<T>::get(netuid)),
identity: Some(SubnetIdentitiesV4::<T>::get(netuid)),
..Default::default()
},
Some(SelectiveMetagraphIndex::NetworkRegisteredAt) => SelectiveMetagraph {
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/rpc_info/subnet_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct SubnetInfo<AccountId: TypeInfo + Encode + Decode> {
owner: AccountId,
}

#[freeze_struct("e8e028bf4fbc6741")]
#[freeze_struct("ab2a1adcd6970bc9")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct SubnetInfov2<AccountId: TypeInfo + Encode + Decode> {
netuid: Compact<NetUid>,
Expand All @@ -50,7 +50,7 @@ pub struct SubnetInfov2<AccountId: TypeInfo + Encode + Decode> {
emission_value: Compact<u64>,
burn: Compact<TaoBalance>,
owner: AccountId,
identity: Option<SubnetIdentityV3>,
identity: Option<SubnetIdentityV4>,
}

#[freeze_struct("fd2db338b156d251")]
Expand Down Expand Up @@ -210,7 +210,7 @@ impl<T: Config> Pallet<T> {
let blocks_since_last_step = Self::get_blocks_since_last_step(netuid);
let tempo = Self::get_tempo(netuid);
let burn = Compact::from(Self::get_burn(netuid));
let identity: Option<SubnetIdentityV3> = SubnetIdentitiesV3::<T>::get(netuid);
let identity: Option<SubnetIdentityV4> = SubnetIdentitiesV4::<T>::get(netuid);

// DEPRECATED
let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new();
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/subnets/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<T: Config> Pallet<T> {
/// * **`origin`** – `T::RuntimeOrigin` &nbsp;Must be **signed** by the coldkey.
/// * **`hotkey`** – `&T::AccountId` &nbsp;First neuron of the new subnet.
/// * **`mechid`** – `u16` &nbsp;Only the dynamic mechanism (`1`) is currently supported.
/// * **`identity`** – `Option<SubnetIdentityOfV3>` &nbsp;Optional metadata for the subnet.
/// * **`identity`** – `Option<SubnetIdentityOfV4>` &nbsp;Optional metadata for the subnet.
///
/// ### Events
/// * `NetworkAdded(netuid, mechid)` – always.
Expand All @@ -112,7 +112,7 @@ impl<T: Config> Pallet<T> {
origin: T::RuntimeOrigin,
hotkey: &T::AccountId,
mechid: u16,
identity: Option<SubnetIdentityOfV3>,
identity: Option<SubnetIdentityOfV4>,
) -> DispatchResult {
// --- 1. Ensure the caller is a signed user.
let coldkey = ensure_signed(origin)?;
Expand Down Expand Up @@ -242,7 +242,7 @@ impl<T: Config> Pallet<T> {
Error::<T>::InvalidIdentity
);

SubnetIdentitiesV3::<T>::insert(netuid_to_register, identity_value);
SubnetIdentitiesV4::<T>::insert(netuid_to_register, identity_value);
Self::deposit_event(Event::SubnetIdentitySet(netuid_to_register));
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/subnets/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ pub static SYMBOLS: [&[u8]; 439] = [
/// Returns the Unicode symbol as a Vec<u8> for a given netuid.
impl<T: Config> Pallet<T> {
pub fn get_name_for_subnet(netuid: NetUid) -> Vec<u8> {
SubnetIdentitiesV3::<T>::try_get(netuid)
SubnetIdentitiesV4::<T>::try_get(netuid)
.and_then(|identity| {
if !identity.subnet_name.is_empty() {
Ok(identity.subnet_name)
Expand Down
Loading
Loading