From c2f53f14263ad3cc1d90958735bd8e0179bbb675 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 18:58:34 -0400 Subject: [PATCH] remove subnetinfo v2 because we take return types from metadata --- pallets/subtensor/rpc/src/lib.rs | 24 ----- pallets/subtensor/runtime-api/src/lib.rs | 4 +- pallets/subtensor/src/lib.rs | 4 +- pallets/subtensor/src/rpc_info/stake_info.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 99 +------------------ runtime/src/lib.rs | 14 --- 6 files changed, 8 insertions(+), 139 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 85e4529da..4247bf3ac 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -48,10 +48,6 @@ pub trait SubtensorCustomApi { fn get_subnet_info(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetsInfo")] fn get_subnets_info(&self, at: Option) -> RpcResult>; - #[method(name = "subnetInfo_getSubnetInfo_v2")] - fn get_subnet_info_v2(&self, netuid: u16, at: Option) -> RpcResult>; - #[method(name = "subnetInfo_getSubnetsInf_v2")] - fn get_subnets_info_v2(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetHyperparams")] fn get_subnet_hyperparams(&self, netuid: u16, at: Option) -> RpcResult>; @@ -275,26 +271,6 @@ where } } - fn get_subnet_info_v2( - &self, - netuid: u16, - at: Option<::Hash>, - ) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_subnet_info_v2(at, netuid) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) - } - - fn get_subnets_info_v2(&self, at: Option<::Hash>) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_subnets_info_v2(at) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into()) - } - fn get_network_lock_cost(&self, at: Option<::Hash>) -> RpcResult { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index 4b9d903b2..8cd786079 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -27,10 +27,8 @@ sp_api::decl_runtime_apis! { } pub trait SubnetInfoRuntimeApi { - fn get_subnet_info(netuid: u16) -> Option>; + fn get_subnet_info(netuid: u16) -> Option>; fn get_subnets_info() -> Vec>>; - fn get_subnet_info_v2(netuid: u16) -> Vec; - fn get_subnets_info_v2() -> Vec; fn get_subnet_hyperparams(netuid: u16) -> Option; } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 2985736c8..e08f5d490 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -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, diff --git a/pallets/subtensor/src/rpc_info/stake_info.rs b/pallets/subtensor/src/rpc_info/stake_info.rs index 27b3838bd..43a1e7070 100644 --- a/pallets/subtensor/src/rpc_info/stake_info.rs +++ b/pallets/subtensor/src/rpc_info/stake_info.rs @@ -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 { hotkey: AccountId, diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 1934968c4..af12d8139 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -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 { netuid: Compact, @@ -25,29 +25,6 @@ pub struct SubnetInfo { emission_values: Compact, burn: Compact, owner: AccountId, -} - -#[freeze_struct("65f931972fa13222")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct SubnetInfov2 { - netuid: Compact, - rho: Compact, - kappa: Compact, - difficulty: Compact, - immunity_period: Compact, - max_allowed_validators: Compact, - min_allowed_weights: Compact, - max_weights_limit: Compact, - scaling_law_power: Compact, - subnetwork_n: Compact, - max_allowed_uids: Compact, - blocks_since_last_step: Compact, - tempo: Compact, - network_modality: Compact, - network_connect: Vec<[u16; 2]>, - emission_values: Compact, - burn: Compact, - owner: T::AccountId, identity: Option, } @@ -104,6 +81,8 @@ impl Pallet { let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); let burn: Compact = Self::get_burn_as_u64(netuid).into(); + let identity: Option = SubnetIdentities::::get(netuid); + // DEPRECATED let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { @@ -129,6 +108,7 @@ impl Pallet { emission_values: emission_values.into(), burn, owner: Self::get_subnet_owner(netuid), + identity, }) } @@ -154,77 +134,6 @@ impl Pallet { subnets_info } - pub fn get_subnet_info_v2(netuid: u16) -> Option> { - if !Self::if_subnet_exist(netuid) { - return None; - } - - let rho = Self::get_rho(netuid); - let kappa = Self::get_kappa(netuid); - let difficulty: Compact = 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 = >::get(netuid); - let emission_values = Self::get_emission_value(netuid); - let burn: Compact = Self::get_burn_as_u64(netuid).into(); - let identity: Option = SubnetIdentities::::get(netuid); - - // DEPRECATED - let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); - // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::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>> { - let mut subnet_netuids = Vec::::new(); - let mut max_netuid: u16 = 0; - for (netuid, added) in as IterableStorageMap>::iter() { - if added { - subnet_netuids.push(netuid); - if netuid > max_netuid { - max_netuid = netuid; - } - } - } - - let mut subnets_info = Vec::>>::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 { if !Self::if_subnet_exist(netuid) { return None; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 09f1c9bc3..54bc4bac9 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1435,20 +1435,6 @@ impl_runtime_apis! { SubtensorModule::get_subnets_info() } - fn get_subnet_info_v2(netuid: u16) -> Vec { - 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 { - let result = SubtensorModule::get_subnets_info_v2(); - result.encode() - } fn get_subnet_hyperparams(netuid: u16) -> Option { SubtensorModule::get_subnet_hyperparams(netuid) }