Skip to content

Commit

Permalink
remove subnetinfo v2 because we take return types from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Sep 27, 2024
1 parent 8ca98f8 commit 646f2e8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 119 deletions.
4 changes: 0 additions & 4 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_subnet_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetsInfo")]
fn get_subnets_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetInfo_v2")]
fn get_subnet_info_v2(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetsInf_v2")]
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetHyperparams")]
fn get_subnet_hyperparams(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;

Expand Down
4 changes: 1 addition & 3 deletions pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ sp_api::decl_runtime_apis! {
}

pub trait SubnetInfoRuntimeApi {
fn get_subnet_info(netuid: u16) -> Option<SubnetInfo<AccountId32>>;
fn get_subnet_info(netuid: u16) -> Option<SubnetInfo<AccountId32>>;
fn get_subnets_info() -> Vec<Option<SubnetInfo<AccountId32>>>;
fn get_subnet_info_v2(netuid: u16) -> Vec<u8>;
fn get_subnets_info_v2() -> Vec<u8>;
fn get_subnet_hyperparams(netuid: u16) -> Option<SubnetHyperparams>;
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ pub mod pallet {
/// Struct for SubnetIdentities.
pub type SubnetIdentityOf = SubnetIdentity;
/// Data structure for Subnet Identities
#[crate::freeze_struct("f448dc3dad763108")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
#[crate::freeze_struct("4201ebd04ab73869")]
#[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug, TypeInfo)]
pub struct SubnetIdentity {
/// The name of the subnet
pub subnet_name: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/rpc_info/stake_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use frame_support::pallet_prelude::{Decode, Encode};
extern crate alloc;
use codec::Compact;

#[freeze_struct("4f16c654467bc8b6")]
#[freeze_struct("7ba412c8ac3f4677")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct StakeInfo<AccountId: TypeInfo + Encode + Decode> {
hotkey: AccountId,
Expand Down
99 changes: 4 additions & 95 deletions pallets/subtensor/src/rpc_info/subnet_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use frame_support::storage::IterableStorageMap;
extern crate alloc;
use codec::Compact;

#[freeze_struct("2a5e9b0845946de0")]
#[freeze_struct("50e2f95a64f9c6f6")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct SubnetInfo<AccountId: TypeInfo + Decode + Encode> {
netuid: Compact<u16>,
Expand All @@ -25,29 +25,6 @@ pub struct SubnetInfo<AccountId: TypeInfo + Decode + Encode> {
emission_values: Compact<u64>,
burn: Compact<u64>,
owner: AccountId,
}

#[freeze_struct("65f931972fa13222")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
pub struct SubnetInfov2<T: Config> {
netuid: Compact<u16>,
rho: Compact<u16>,
kappa: Compact<u16>,
difficulty: Compact<u64>,
immunity_period: Compact<u16>,
max_allowed_validators: Compact<u16>,
min_allowed_weights: Compact<u16>,
max_weights_limit: Compact<u16>,
scaling_law_power: Compact<u16>,
subnetwork_n: Compact<u16>,
max_allowed_uids: Compact<u16>,
blocks_since_last_step: Compact<u64>,
tempo: Compact<u16>,
network_modality: Compact<u16>,
network_connect: Vec<[u16; 2]>,
emission_values: Compact<u64>,
burn: Compact<u64>,
owner: T::AccountId,
identity: Option<SubnetIdentity>,
}

Expand Down Expand Up @@ -104,6 +81,8 @@ impl<T: Config> Pallet<T> {
let network_modality = <NetworkModality<T>>::get(netuid);
let emission_values = Self::get_emission_value(netuid);
let burn: Compact<u64> = Self::get_burn_as_u64(netuid).into();
let identity: Option<SubnetIdentity> = SubnetIdentities::<T>::get(netuid);

// DEPRECATED
let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new();
// DEPRECATED for ( _netuid_, con_req) in < NetworkConnect<T> as IterableStorageDoubleMap<u16, u16, u16> >::iter_prefix(netuid) {
Expand All @@ -129,6 +108,7 @@ impl<T: Config> Pallet<T> {
emission_values: emission_values.into(),
burn,
owner: Self::get_subnet_owner(netuid),
identity,
})
}

Expand All @@ -154,77 +134,6 @@ impl<T: Config> Pallet<T> {
subnets_info
}

pub fn get_subnet_info_v2(netuid: u16) -> Option<SubnetInfov2<T>> {
if !Self::if_subnet_exist(netuid) {
return None;
}

let rho = Self::get_rho(netuid);
let kappa = Self::get_kappa(netuid);
let difficulty: Compact<u64> = Self::get_difficulty_as_u64(netuid).into();
let immunity_period = Self::get_immunity_period(netuid);
let max_allowed_validators = Self::get_max_allowed_validators(netuid);
let min_allowed_weights = Self::get_min_allowed_weights(netuid);
let max_weights_limit = Self::get_max_weight_limit(netuid);
let scaling_law_power = Self::get_scaling_law_power(netuid);
let subnetwork_n = Self::get_subnetwork_n(netuid);
let max_allowed_uids = Self::get_max_allowed_uids(netuid);
let blocks_since_last_step = Self::get_blocks_since_last_step(netuid);
let tempo = Self::get_tempo(netuid);
let network_modality = <NetworkModality<T>>::get(netuid);
let emission_values = Self::get_emission_value(netuid);
let burn: Compact<u64> = Self::get_burn_as_u64(netuid).into();
let identity: Option<SubnetIdentity> = SubnetIdentities::<T>::get(netuid);

// DEPRECATED
let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new();
// DEPRECATED for ( _netuid_, con_req) in < NetworkConnect<T> as IterableStorageDoubleMap<u16, u16, u16> >::iter_prefix(netuid) {
// network_connect.push([_netuid_, con_req]);
// }

Some(SubnetInfov2 {
rho: rho.into(),
kappa: kappa.into(),
difficulty,
immunity_period: immunity_period.into(),
netuid: netuid.into(),
max_allowed_validators: max_allowed_validators.into(),
min_allowed_weights: min_allowed_weights.into(),
max_weights_limit: max_weights_limit.into(),
scaling_law_power: scaling_law_power.into(),
subnetwork_n: subnetwork_n.into(),
max_allowed_uids: max_allowed_uids.into(),
blocks_since_last_step: blocks_since_last_step.into(),
tempo: tempo.into(),
network_modality: network_modality.into(),
network_connect,
emission_values: emission_values.into(),
burn,
owner: Self::get_subnet_owner(netuid),
identity,
})
}
pub fn get_subnets_info_v2() -> Vec<Option<SubnetInfo<T>>> {
let mut subnet_netuids = Vec::<u16>::new();
let mut max_netuid: u16 = 0;
for (netuid, added) in <NetworksAdded<T> as IterableStorageMap<u16, bool>>::iter() {
if added {
subnet_netuids.push(netuid);
if netuid > max_netuid {
max_netuid = netuid;
}
}
}

let mut subnets_info = Vec::<Option<SubnetInfo<T>>>::new();
for netuid_ in 0..=max_netuid {
if subnet_netuids.contains(&netuid_) {
subnets_info.push(Self::get_subnet_info(netuid_));
}
}

subnets_info
}
pub fn get_subnet_hyperparams(netuid: u16) -> Option<SubnetHyperparams> {
if !Self::if_subnet_exist(netuid) {
return None;
Expand Down
14 changes: 0 additions & 14 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,20 +1435,6 @@ impl_runtime_apis! {
SubtensorModule::get_subnets_info()
}

fn get_subnet_info_v2(netuid: u16) -> Vec<u8> {
let _result = SubtensorModule::get_subnet_info_v2(netuid);
if _result.is_some() {
let result = _result.expect("Could not get SubnetInfo");
result.encode()
} else {
vec![]
}
}

fn get_subnets_info_v2() -> Vec<u8> {
let result = SubtensorModule::get_subnets_info_v2();
result.encode()
}
fn get_subnet_hyperparams(netuid: u16) -> Option<SubnetHyperparams> {
SubtensorModule::get_subnet_hyperparams(netuid)
}
Expand Down

0 comments on commit 646f2e8

Please sign in to comment.