Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -1225,7 +1225,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<SubnetIdentityOf> = None;

Subtensor::<T>::set_network_registration_allowed(1.into(), true);
Subtensor::<T>::set_network_rate_limit(1);
Expand Down Expand Up @@ -1331,6 +1331,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 @@ -1347,6 +1348,7 @@ mod pallet_benchmarks {
descr.clone(),
logo_url.clone(),
add.clone(),
agent_docs_url.clone(),
);
}

Expand Down
41 changes: 35 additions & 6 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ pub mod pallet {
pub additional: Vec<u8>,
}

/// Struct for SubnetIdentities. (DEPRECATED for V2)
pub type SubnetIdentityOf = SubnetIdentity;
/// Struct for SubnetIdentities. (DEPRECATED)
pub type SubnetIdentityOfV1 = SubnetIdentity;
/// Data structure for Subnet Identities. (DEPRECATED for V2)
#[crate::freeze_struct("f448dc3dad763108")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -292,9 +292,9 @@ pub mod pallet {
pub additional: Vec<u8>,
}

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

/// Type alias for the current subnet identity version.
/// Update this alias when introducing a new version.
pub type SubnetIdentityOf = SubnetIdentityV4;
/// 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 @@ -2155,10 +2184,10 @@ pub mod pallet {
pub type IdentitiesV2<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, ChainIdentityOfV2, OptionQuery>;

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

/// =================================
/// ==== 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<SubnetIdentityOf>,
) -> 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 entries from V3 to V4 encoding
.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,52 @@
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;

// Translate V3-encoded entries to V4 in place within SubnetIdentitiesV3.
SubnetIdentitiesV3::<T>::translate::<SubnetIdentityV3, _>(|_netuid, v3| {
migrated_count += 1;
Some(SubnetIdentityOf {
subnet_name: v3.subnet_name,
github_repo: v3.github_repo,
subnet_contact: v3.subnet_contact,
subnet_url: v3.subnet_url,
discord: v3.discord,
description: v3.description,
logo_url: v3.logo_url,
additional: v3.additional,
agent_docs_url: vec![],
})
});

weight = weight.saturating_add(T::DbWeight::get().reads_writes(migrated_count, migrated_count));

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
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
4 changes: 2 additions & 2 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("df57c3a5e8b0100c")]
#[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<SubnetIdentityOf>,
moving_price: I96F32,
}

Expand Down
8 changes: 4 additions & 4 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("1db9a42935e6a1a8")]
#[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<SubnetIdentityOf>, // 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("cb7d1187d7035b79")]
#[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<SubnetIdentityOf>>, // identity information
network_registered_at: Option<Compact<u64>>, // block at registration

// Keys for owner.
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("c8976c0491130e76")]
#[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<SubnetIdentityOf>,
}

#[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<SubnetIdentityOf> = SubnetIdentitiesV3::<T>::get(netuid);

// DEPRECATED
let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new();
Expand Down
4 changes: 2 additions & 2 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<SubnetIdentityOf>` &nbsp;Optional metadata for the subnet.
///
/// ### Events
/// * `NetworkAdded(netuid, mechid)` – always.
Expand All @@ -112,7 +112,7 @@ impl<T: Config> Pallet<T> {
origin: OriginFor<T>,
hotkey: &T::AccountId,
mechid: u16,
identity: Option<SubnetIdentityOfV3>,
identity: Option<SubnetIdentityOf>,
) -> DispatchResult {
// --- 1. Ensure the caller is a signed user.
let coldkey = ensure_signed(origin)?;
Expand Down
Loading