diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index b6512c6055..eb3c7b11ca 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -58,6 +58,12 @@ pub trait SubtensorCustomApi { fn get_subnets_info_v2(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetHyperparams")] fn get_subnet_hyperparams(&self, netuid: NetUid, at: Option) -> RpcResult>; + #[method(name = "subnetInfo_getSubnetHyperparamsV2")] + fn get_subnet_hyperparams_v2( + &self, + netuid: NetUid, + at: Option, + ) -> RpcResult>; #[method(name = "subnetInfo_getAllDynamicInfo")] fn get_all_dynamic_info(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getDynamicInfo")] @@ -284,6 +290,22 @@ where } } + fn get_subnet_hyperparams_v2( + &self, + netuid: NetUid, + at: Option<::Hash>, + ) -> RpcResult> { + let api = self.client.runtime_api(); + let at = at.unwrap_or_else(|| self.client.info().best_hash); + + match api.get_subnet_hyperparams_v2(at, netuid) { + Ok(result) => Ok(result.encode()), + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) + } + } + } + fn get_all_dynamic_info(&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 ac2de7e9d9..e482a01251 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -9,7 +9,7 @@ use pallet_subtensor::rpc_info::{ neuron_info::{NeuronInfo, NeuronInfoLite}, show_subnet::SubnetState, stake_info::StakeInfo, - subnet_info::{SubnetHyperparams, SubnetInfo, SubnetInfov2}, + subnet_info::{SubnetHyperparams, SubnetHyperparamsV2, SubnetInfo, SubnetInfov2}, }; use sp_runtime::AccountId32; use subtensor_runtime_common::NetUid; @@ -36,6 +36,7 @@ sp_api::decl_runtime_apis! { fn get_subnet_info_v2(netuid: NetUid) -> Option>; fn get_subnets_info_v2() -> Vec>>; fn get_subnet_hyperparams(netuid: NetUid) -> Option; + fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option; fn get_all_dynamic_info() -> Vec>>; fn get_all_metagraphs() -> Vec>>; fn get_metagraph(netuid: NetUid) -> Option>; diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 98082bccc9..cab1f8800b 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -3,6 +3,7 @@ use frame_support::pallet_prelude::{Decode, Encode}; use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; +use substrate_fixed::types::I32F32; use subtensor_runtime_common::NetUid; #[freeze_struct("dd2293544ffd8f2e")] @@ -52,7 +53,7 @@ pub struct SubnetInfov2 { identity: Option, } -#[freeze_struct("769dc2ca2135b525")] +#[freeze_struct("7b506df55bd44646")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetHyperparams { rho: Compact, @@ -82,6 +83,43 @@ pub struct SubnetHyperparams { alpha_high: Compact, alpha_low: Compact, liquid_alpha_enabled: bool, +} + +#[freeze_struct("a13c536303dec16f")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] +pub struct SubnetHyperparamsV2 { + rho: Compact, + kappa: Compact, + immunity_period: Compact, + min_allowed_weights: Compact, + max_weights_limit: Compact, + tempo: Compact, + min_difficulty: Compact, + max_difficulty: Compact, + weights_version: Compact, + weights_rate_limit: Compact, + adjustment_interval: Compact, + activity_cutoff: Compact, + pub registration_allowed: bool, + target_regs_per_interval: Compact, + min_burn: Compact, + max_burn: Compact, + bonds_moving_avg: Compact, + max_regs_per_block: Compact, + serving_rate_limit: Compact, + max_validators: Compact, + adjustment_alpha: Compact, + difficulty: Compact, + commit_reveal_period: Compact, + commit_reveal_weights_enabled: bool, + alpha_high: Compact, + alpha_low: Compact, + liquid_alpha_enabled: bool, + alpha_sigmoid_steepness: I32F32, + yuma_version: Compact, + subnet_is_active: bool, + transfers_enabled: bool, + bonds_reset_enabled: bool, user_liquidity_enabled: bool, } @@ -258,7 +296,6 @@ impl Pallet { let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); let (alpha_low, alpha_high): (u16, u16) = Self::get_alpha_values(netuid); - let user_liquidity_enabled: bool = Self::is_user_liquidity_enabled(netuid); Some(SubnetHyperparams { rho: rho.into(), @@ -288,6 +325,83 @@ impl Pallet { alpha_high: alpha_high.into(), alpha_low: alpha_low.into(), liquid_alpha_enabled, + }) + } + + pub fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option { + if !Self::if_subnet_exist(netuid) { + return None; + } + + let rho = Self::get_rho(netuid); + let kappa = Self::get_kappa(netuid); + let immunity_period = Self::get_immunity_period(netuid); + let min_allowed_weights = Self::get_min_allowed_weights(netuid); + let max_weights_limit = Self::get_max_weight_limit(netuid); + let tempo = Self::get_tempo(netuid); + let min_difficulty = Self::get_min_difficulty(netuid); + let max_difficulty = Self::get_max_difficulty(netuid); + let weights_version = Self::get_weights_version_key(netuid); + let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); + let adjustment_interval = Self::get_adjustment_interval(netuid); + let activity_cutoff = Self::get_activity_cutoff(netuid); + let registration_allowed = Self::get_network_registration_allowed(netuid); + let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); + let min_burn = Self::get_min_burn_as_u64(netuid); + let max_burn = Self::get_max_burn_as_u64(netuid); + let bonds_moving_avg = Self::get_bonds_moving_average(netuid); + let max_regs_per_block = Self::get_max_registrations_per_block(netuid); + let serving_rate_limit = Self::get_serving_rate_limit(netuid); + let max_validators = Self::get_max_allowed_validators(netuid); + let adjustment_alpha = Self::get_adjustment_alpha(netuid); + let difficulty = Self::get_difficulty_as_u64(netuid); + let commit_reveal_period = Self::get_reveal_period(netuid); + let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); + let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); + let (alpha_low, alpha_high): (u16, u16) = Self::get_alpha_values(netuid); + let alpha_sigmoid_steepness = Self::get_alpha_sigmoid_steepness(netuid); + let yuma_version: u16 = match Self::get_yuma3_enabled(netuid) { + true => 3u16, + false => 2u16, + }; + let subnet_token_enabled = Self::get_subtoken_enabled(netuid); + let transfers_enabled = Self::get_transfer_toggle(netuid); + let bonds_reset = Self::get_bonds_reset(netuid); + let user_liquidity_enabled: bool = Self::is_user_liquidity_enabled(netuid); + + Some(SubnetHyperparamsV2 { + rho: rho.into(), + kappa: kappa.into(), + immunity_period: immunity_period.into(), + min_allowed_weights: min_allowed_weights.into(), + max_weights_limit: max_weights_limit.into(), + tempo: tempo.into(), + min_difficulty: min_difficulty.into(), + max_difficulty: max_difficulty.into(), + weights_version: weights_version.into(), + weights_rate_limit: weights_rate_limit.into(), + adjustment_interval: adjustment_interval.into(), + activity_cutoff: activity_cutoff.into(), + registration_allowed, + target_regs_per_interval: target_regs_per_interval.into(), + min_burn: min_burn.into(), + max_burn: max_burn.into(), + bonds_moving_avg: bonds_moving_avg.into(), + max_regs_per_block: max_regs_per_block.into(), + serving_rate_limit: serving_rate_limit.into(), + max_validators: max_validators.into(), + adjustment_alpha: adjustment_alpha.into(), + difficulty: difficulty.into(), + commit_reveal_period: commit_reveal_period.into(), + commit_reveal_weights_enabled, + alpha_high: alpha_high.into(), + alpha_low: alpha_low.into(), + liquid_alpha_enabled, + alpha_sigmoid_steepness, + yuma_version: yuma_version.into(), + subnet_is_active: subnet_token_enabled, + transfers_enabled, + bonds_reset_enabled: bonds_reset, user_liquidity_enabled, }) } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index c6075995a9..9641cfb0ee 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -723,6 +723,14 @@ impl Pallet { Yuma3On::::get(netuid) } + pub fn get_subtoken_enabled(netuid: NetUid) -> bool { + SubtokenEnabled::::get(netuid) + } + + pub fn get_transfer_toggle(netuid: NetUid) -> bool { + TransferToggle::::get(netuid) + } + /// Set the duration for coldkey swap /// /// # Arguments diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 49e02adefa..8adf4b6c55 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -42,7 +42,7 @@ use pallet_subtensor::rpc_info::{ neuron_info::{NeuronInfo, NeuronInfoLite}, show_subnet::SubnetState, stake_info::StakeInfo, - subnet_info::{SubnetHyperparams, SubnetInfo, SubnetInfov2}, + subnet_info::{SubnetHyperparams, SubnetHyperparamsV2, SubnetInfo, SubnetInfov2}, }; use smallvec::smallvec; use sp_api::impl_runtime_apis; @@ -2277,6 +2277,10 @@ impl_runtime_apis! { SubtensorModule::get_subnet_hyperparams(netuid) } + fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option { + SubtensorModule::get_subnet_hyperparams_v2(netuid) + } + fn get_dynamic_info(netuid: NetUid) -> Option> { SubtensorModule::get_dynamic_info(netuid) }