Skip to content
Merged
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
22 changes: 22 additions & 0 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetHyperparams")]
fn get_subnet_hyperparams(&self, netuid: NetUid, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetHyperparamsV2")]
fn get_subnet_hyperparams_v2(
&self,
netuid: NetUid,
at: Option<BlockHash>,
) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getAllDynamicInfo")]
fn get_all_dynamic_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getDynamicInfo")]
Expand Down Expand Up @@ -284,6 +290,22 @@ where
}
}

fn get_subnet_hyperparams_v2(
&self,
netuid: NetUid,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Vec<u8>> {
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<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
Expand Down
3 changes: 2 additions & 1 deletion pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +36,7 @@ sp_api::decl_runtime_apis! {
fn get_subnet_info_v2(netuid: NetUid) -> Option<SubnetInfov2<AccountId32>>;
fn get_subnets_info_v2() -> Vec<Option<SubnetInfov2<AccountId32>>>;
fn get_subnet_hyperparams(netuid: NetUid) -> Option<SubnetHyperparams>;
fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option<SubnetHyperparamsV2>;
fn get_all_dynamic_info() -> Vec<Option<DynamicInfo<AccountId32>>>;
fn get_all_metagraphs() -> Vec<Option<Metagraph<AccountId32>>>;
fn get_metagraph(netuid: NetUid) -> Option<Metagraph<AccountId32>>;
Expand Down
118 changes: 116 additions & 2 deletions pallets/subtensor/src/rpc_info/subnet_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -52,7 +53,7 @@ pub struct SubnetInfov2<AccountId: TypeInfo + Encode + Decode> {
identity: Option<SubnetIdentityV3>,
}

#[freeze_struct("769dc2ca2135b525")]
#[freeze_struct("7b506df55bd44646")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct SubnetHyperparams {
rho: Compact<u16>,
Expand Down Expand Up @@ -82,6 +83,43 @@ pub struct SubnetHyperparams {
alpha_high: Compact<u16>,
alpha_low: Compact<u16>,
liquid_alpha_enabled: bool,
}

#[freeze_struct("a13c536303dec16f")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
pub struct SubnetHyperparamsV2 {
rho: Compact<u16>,
kappa: Compact<u16>,
immunity_period: Compact<u16>,
min_allowed_weights: Compact<u16>,
max_weights_limit: Compact<u16>,
tempo: Compact<u16>,
min_difficulty: Compact<u64>,
max_difficulty: Compact<u64>,
weights_version: Compact<u64>,
weights_rate_limit: Compact<u64>,
adjustment_interval: Compact<u16>,
activity_cutoff: Compact<u16>,
pub registration_allowed: bool,
target_regs_per_interval: Compact<u16>,
min_burn: Compact<u64>,
max_burn: Compact<u64>,
bonds_moving_avg: Compact<u64>,
max_regs_per_block: Compact<u16>,
serving_rate_limit: Compact<u64>,
max_validators: Compact<u16>,
adjustment_alpha: Compact<u64>,
difficulty: Compact<u64>,
commit_reveal_period: Compact<u64>,
commit_reveal_weights_enabled: bool,
alpha_high: Compact<u16>,
alpha_low: Compact<u16>,
liquid_alpha_enabled: bool,
alpha_sigmoid_steepness: I32F32,
yuma_version: Compact<u16>,
subnet_is_active: bool,
transfers_enabled: bool,
bonds_reset_enabled: bool,
user_liquidity_enabled: bool,
}

Expand Down Expand Up @@ -258,7 +296,6 @@ impl<T: Config> Pallet<T> {
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(),
Expand Down Expand Up @@ -288,6 +325,83 @@ impl<T: Config> Pallet<T> {
alpha_high: alpha_high.into(),
alpha_low: alpha_low.into(),
liquid_alpha_enabled,
})
}

pub fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option<SubnetHyperparamsV2> {
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,
})
}
Expand Down
8 changes: 8 additions & 0 deletions pallets/subtensor/src/utils/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,14 @@ impl<T: Config> Pallet<T> {
Yuma3On::<T>::get(netuid)
}

pub fn get_subtoken_enabled(netuid: NetUid) -> bool {
SubtokenEnabled::<T>::get(netuid)
}

pub fn get_transfer_toggle(netuid: NetUid) -> bool {
TransferToggle::<T>::get(netuid)
}

/// Set the duration for coldkey swap
///
/// # Arguments
Expand Down
6 changes: 5 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2277,6 +2277,10 @@ impl_runtime_apis! {
SubtensorModule::get_subnet_hyperparams(netuid)
}

fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option<SubnetHyperparamsV2> {
SubtensorModule::get_subnet_hyperparams_v2(netuid)
}

fn get_dynamic_info(netuid: NetUid) -> Option<DynamicInfo<AccountId32>> {
SubtensorModule::get_dynamic_info(netuid)
}
Expand Down
Loading