From 848e71e2fbca1f20d5041094d38000f3cfd964a1 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 10 Jun 2025 12:47:16 -0700 Subject: [PATCH 1/7] impl hyperparams_v2 includes yuma3_enabled --- pallets/subtensor/rpc/src/lib.rs | 18 ++++ pallets/subtensor/runtime-api/src/lib.rs | 3 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 98 +++++++++++++++++++ runtime/src/lib.rs | 6 +- 4 files changed, 123 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index b3b60206dd..95211b067f 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -52,6 +52,8 @@ pub trait SubtensorCustomApi { fn get_subnets_info_v2(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetHyperparams")] fn get_subnet_hyperparams(&self, netuid: u16, at: Option) -> RpcResult>; + #[method(name = "subnetInfo_getSubnetHyperparamsV2")] + fn get_subnet_hyperparams_v2(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getAllDynamicInfo")] fn get_all_dynamic_info(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getDynamicInfo")] @@ -274,6 +276,22 @@ where } } + fn get_subnet_hyperparams_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); + + 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 1a2f34aa9e..f577fdb37d 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; @@ -35,6 +35,7 @@ sp_api::decl_runtime_apis! { fn get_subnet_info_v2(netuid: u16) -> Option>; fn get_subnets_info_v2() -> Vec>>; fn get_subnet_hyperparams(netuid: u16) -> Option; + fn get_subnet_hyperparams_v2(netuid: u16) -> Option; fn get_all_dynamic_info() -> Vec>>; fn get_all_metagraphs() -> Vec>>; fn get_metagraph(netuid: u16) -> Option>; diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 6e9e722295..17e47f4f5b 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -83,6 +83,39 @@ pub struct SubnetHyperparams { liquid_alpha_enabled: bool, } +#[freeze_struct("7dfa98f279500b4b")] +#[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, + yuma3_enabled: bool, +} + impl Pallet { pub fn get_subnet_info(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { @@ -287,4 +320,69 @@ impl Pallet { liquid_alpha_enabled, }) } + + pub fn get_subnet_hyperparams_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 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 yuma3_enabled = Self::get_yuma3_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, + yuma3_enabled, + }) + } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 27fed3ec0a..4f248071ef 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -38,7 +38,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; @@ -2234,6 +2234,10 @@ impl_runtime_apis! { SubtensorModule::get_subnet_hyperparams(netuid) } + fn get_subnet_hyperparams_v2(netuid: u16) -> Option { + SubtensorModule::get_subnet_hyperparams_v2(netuid) + } + fn get_dynamic_info(netuid: u16) -> Option> { SubtensorModule::get_dynamic_info(netuid) } From 7323aa7dbc2e2d666c9e4da449509108e7004ea7 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 10 Jun 2025 12:56:17 -0700 Subject: [PATCH 2/7] yuma3_enabled => yuma_version --- pallets/subtensor/src/rpc_info/subnet_info.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 17e47f4f5b..e5f18ce36b 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -83,7 +83,7 @@ pub struct SubnetHyperparams { liquid_alpha_enabled: bool, } -#[freeze_struct("7dfa98f279500b4b")] +#[freeze_struct("cb67d7ada314398e")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetHyperparamsV2 { rho: Compact, @@ -113,7 +113,7 @@ pub struct SubnetHyperparamsV2 { alpha_high: Compact, alpha_low: Compact, liquid_alpha_enabled: bool, - yuma3_enabled: bool, + yuma_version: Compact, } impl Pallet { @@ -352,7 +352,10 @@ 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 yuma3_enabled = Self::get_yuma3_enabled(netuid); + let yuma_version: u16 = match Self::get_yuma3_enabled(netuid) { + true => 3u16, + false => 2u16, + }; Some(SubnetHyperparamsV2 { rho: rho.into(), @@ -382,7 +385,7 @@ impl Pallet { alpha_high: alpha_high.into(), alpha_low: alpha_low.into(), liquid_alpha_enabled, - yuma3_enabled, + yuma_version: yuma_version.into(), }) } } From 44ac1831fed97ff372d8a624a1aea884dcbcc57a Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:11:06 -0700 Subject: [PATCH 3/7] add more parameters to v2 --- pallets/subtensor/src/rpc_info/subnet_info.rs | 15 ++++++++++++++- pallets/subtensor/src/utils/misc.rs | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index e5f18ce36b..9643f815ee 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; #[freeze_struct("1eee6f3911800c6b")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] @@ -83,7 +84,7 @@ pub struct SubnetHyperparams { liquid_alpha_enabled: bool, } -#[freeze_struct("cb67d7ada314398e")] +#[freeze_struct("34ec2962181256c6")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetHyperparamsV2 { rho: Compact, @@ -113,7 +114,11 @@ pub struct SubnetHyperparamsV2 { alpha_high: Compact, alpha_low: Compact, liquid_alpha_enabled: bool, + alpha_sigmoid_steepness: I32F32, yuma_version: Compact, + subnet_token_enabled: bool, + transfers_enabled: bool, + bonds_reset_enabled: bool, } impl Pallet { @@ -352,10 +357,14 @@ 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 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); Some(SubnetHyperparamsV2 { rho: rho.into(), @@ -385,7 +394,11 @@ impl Pallet { alpha_high: alpha_high.into(), alpha_low: alpha_low.into(), liquid_alpha_enabled, + alpha_sigmoid_steepness: alpha_sigmoid_steepness, yuma_version: yuma_version.into(), + subnet_token_enabled: subnet_token_enabled, + transfers_enabled: transfers_enabled, + bonds_reset_enabled: bonds_reset, }) } } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 899fa83646..7c69d2d7bd 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -719,6 +719,14 @@ impl Pallet { Yuma3On::::get(netuid) } + pub fn get_subtoken_enabled(netuid: u16) -> bool { + SubtokenEnabled::::get(netuid) + } + + pub fn get_transfer_toggle(netuid: u16) -> bool { + TransferToggle::::get(netuid) + } + /// Set the duration for coldkey swap /// /// # Arguments From b6d95454b1fa93a534419a32f9100964b113be6c Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:15:31 -0700 Subject: [PATCH 4/7] clippy --- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 9643f815ee..24ba8afa2d 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -394,10 +394,10 @@ impl Pallet { alpha_high: alpha_high.into(), alpha_low: alpha_low.into(), liquid_alpha_enabled, - alpha_sigmoid_steepness: alpha_sigmoid_steepness, + alpha_sigmoid_steepness, yuma_version: yuma_version.into(), - subnet_token_enabled: subnet_token_enabled, - transfers_enabled: transfers_enabled, + subnet_token_enabled, + transfers_enabled, bonds_reset_enabled: bonds_reset, }) } From 90a5768315197da66be6dc96add35b66110acdf1 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:42:53 -0700 Subject: [PATCH 5/7] fix merge errors --- pallets/subtensor/rpc/src/lib.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 ++-- runtime/src/lib.rs | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index e8980f8779..6c847d3258 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -288,7 +288,7 @@ where fn get_subnet_hyperparams_v2( &self, - netuid: u16, + netuid: NetUid, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 8699eadd86..9641cfb0ee 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -723,11 +723,11 @@ impl Pallet { Yuma3On::::get(netuid) } - pub fn get_subtoken_enabled(netuid: u16) -> bool { + pub fn get_subtoken_enabled(netuid: NetUid) -> bool { SubtokenEnabled::::get(netuid) } - pub fn get_transfer_toggle(netuid: u16) -> bool { + pub fn get_transfer_toggle(netuid: NetUid) -> bool { TransferToggle::::get(netuid) } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8751a0550f..8adf4b6c55 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -2281,10 +2281,6 @@ impl_runtime_apis! { SubtensorModule::get_subnet_hyperparams_v2(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) } From bd320d19772bbb296482dfc654159e6695125ac2 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:50:40 -0700 Subject: [PATCH 6/7] fmt --- pallets/subtensor/rpc/src/lib.rs | 6 +++++- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 6c847d3258..eb3c7b11ca 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -59,7 +59,11 @@ pub trait SubtensorCustomApi { #[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>; + 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")] diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 0a89124a6c..5e287b4482 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -3,8 +3,8 @@ use frame_support::pallet_prelude::{Decode, Encode}; use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; -use subtensor_runtime_common::NetUid; use substrate_fixed::types::I32F32; +use subtensor_runtime_common::NetUid; #[freeze_struct("dd2293544ffd8f2e")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] From 747f0838968de2cb85e71612a5c2f4651e0d28db Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:57:12 -0700 Subject: [PATCH 7/7] rename subnet_token_enabled => subnet_is_active --- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 5e287b4482..cab1f8800b 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -85,7 +85,7 @@ pub struct SubnetHyperparams { liquid_alpha_enabled: bool, } -#[freeze_struct("3fbe8d53738695c7")] +#[freeze_struct("a13c536303dec16f")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetHyperparamsV2 { rho: Compact, @@ -117,7 +117,7 @@ pub struct SubnetHyperparamsV2 { liquid_alpha_enabled: bool, alpha_sigmoid_steepness: I32F32, yuma_version: Compact, - subnet_token_enabled: bool, + subnet_is_active: bool, transfers_enabled: bool, bonds_reset_enabled: bool, user_liquidity_enabled: bool, @@ -399,7 +399,7 @@ impl Pallet { liquid_alpha_enabled, alpha_sigmoid_steepness, yuma_version: yuma_version.into(), - subnet_token_enabled, + subnet_is_active: subnet_token_enabled, transfers_enabled, bonds_reset_enabled: bonds_reset, user_liquidity_enabled,