Skip to content

Commit 35199c6

Browse files
authored
Merge pull request #1736 from opentensor/hyperparams-v2
Feat/SubnetHyperparamsV2
2 parents b54cdac + 747f083 commit 35199c6

File tree

5 files changed

+153
-4
lines changed

5 files changed

+153
-4
lines changed

pallets/subtensor/rpc/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ pub trait SubtensorCustomApi<BlockHash> {
5858
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
5959
#[method(name = "subnetInfo_getSubnetHyperparams")]
6060
fn get_subnet_hyperparams(&self, netuid: NetUid, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
61+
#[method(name = "subnetInfo_getSubnetHyperparamsV2")]
62+
fn get_subnet_hyperparams_v2(
63+
&self,
64+
netuid: NetUid,
65+
at: Option<BlockHash>,
66+
) -> RpcResult<Vec<u8>>;
6167
#[method(name = "subnetInfo_getAllDynamicInfo")]
6268
fn get_all_dynamic_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
6369
#[method(name = "subnetInfo_getDynamicInfo")]
@@ -284,6 +290,22 @@ where
284290
}
285291
}
286292

293+
fn get_subnet_hyperparams_v2(
294+
&self,
295+
netuid: NetUid,
296+
at: Option<<Block as BlockT>::Hash>,
297+
) -> RpcResult<Vec<u8>> {
298+
let api = self.client.runtime_api();
299+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
300+
301+
match api.get_subnet_hyperparams_v2(at, netuid) {
302+
Ok(result) => Ok(result.encode()),
303+
Err(e) => {
304+
Err(Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into())
305+
}
306+
}
307+
}
308+
287309
fn get_all_dynamic_info(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
288310
let api = self.client.runtime_api();
289311
let at = at.unwrap_or_else(|| self.client.info().best_hash);

pallets/subtensor/runtime-api/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use pallet_subtensor::rpc_info::{
99
neuron_info::{NeuronInfo, NeuronInfoLite},
1010
show_subnet::SubnetState,
1111
stake_info::StakeInfo,
12-
subnet_info::{SubnetHyperparams, SubnetInfo, SubnetInfov2},
12+
subnet_info::{SubnetHyperparams, SubnetHyperparamsV2, SubnetInfo, SubnetInfov2},
1313
};
1414
use sp_runtime::AccountId32;
1515
use subtensor_runtime_common::NetUid;
@@ -36,6 +36,7 @@ sp_api::decl_runtime_apis! {
3636
fn get_subnet_info_v2(netuid: NetUid) -> Option<SubnetInfov2<AccountId32>>;
3737
fn get_subnets_info_v2() -> Vec<Option<SubnetInfov2<AccountId32>>>;
3838
fn get_subnet_hyperparams(netuid: NetUid) -> Option<SubnetHyperparams>;
39+
fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option<SubnetHyperparamsV2>;
3940
fn get_all_dynamic_info() -> Vec<Option<DynamicInfo<AccountId32>>>;
4041
fn get_all_metagraphs() -> Vec<Option<Metagraph<AccountId32>>>;
4142
fn get_metagraph(netuid: NetUid) -> Option<Metagraph<AccountId32>>;

pallets/subtensor/src/rpc_info/subnet_info.rs

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use frame_support::pallet_prelude::{Decode, Encode};
33
use frame_support::storage::IterableStorageMap;
44
extern crate alloc;
55
use codec::Compact;
6+
use substrate_fixed::types::I32F32;
67
use subtensor_runtime_common::NetUid;
78

89
#[freeze_struct("dd2293544ffd8f2e")]
@@ -52,7 +53,7 @@ pub struct SubnetInfov2<AccountId: TypeInfo + Encode + Decode> {
5253
identity: Option<SubnetIdentityV3>,
5354
}
5455

55-
#[freeze_struct("769dc2ca2135b525")]
56+
#[freeze_struct("7b506df55bd44646")]
5657
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
5758
pub struct SubnetHyperparams {
5859
rho: Compact<u16>,
@@ -82,6 +83,43 @@ pub struct SubnetHyperparams {
8283
alpha_high: Compact<u16>,
8384
alpha_low: Compact<u16>,
8485
liquid_alpha_enabled: bool,
86+
}
87+
88+
#[freeze_struct("a13c536303dec16f")]
89+
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
90+
pub struct SubnetHyperparamsV2 {
91+
rho: Compact<u16>,
92+
kappa: Compact<u16>,
93+
immunity_period: Compact<u16>,
94+
min_allowed_weights: Compact<u16>,
95+
max_weights_limit: Compact<u16>,
96+
tempo: Compact<u16>,
97+
min_difficulty: Compact<u64>,
98+
max_difficulty: Compact<u64>,
99+
weights_version: Compact<u64>,
100+
weights_rate_limit: Compact<u64>,
101+
adjustment_interval: Compact<u16>,
102+
activity_cutoff: Compact<u16>,
103+
pub registration_allowed: bool,
104+
target_regs_per_interval: Compact<u16>,
105+
min_burn: Compact<u64>,
106+
max_burn: Compact<u64>,
107+
bonds_moving_avg: Compact<u64>,
108+
max_regs_per_block: Compact<u16>,
109+
serving_rate_limit: Compact<u64>,
110+
max_validators: Compact<u16>,
111+
adjustment_alpha: Compact<u64>,
112+
difficulty: Compact<u64>,
113+
commit_reveal_period: Compact<u64>,
114+
commit_reveal_weights_enabled: bool,
115+
alpha_high: Compact<u16>,
116+
alpha_low: Compact<u16>,
117+
liquid_alpha_enabled: bool,
118+
alpha_sigmoid_steepness: I32F32,
119+
yuma_version: Compact<u16>,
120+
subnet_is_active: bool,
121+
transfers_enabled: bool,
122+
bonds_reset_enabled: bool,
85123
user_liquidity_enabled: bool,
86124
}
87125

@@ -258,7 +296,6 @@ impl<T: Config> Pallet<T> {
258296
let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid);
259297
let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid);
260298
let (alpha_low, alpha_high): (u16, u16) = Self::get_alpha_values(netuid);
261-
let user_liquidity_enabled: bool = Self::is_user_liquidity_enabled(netuid);
262299

263300
Some(SubnetHyperparams {
264301
rho: rho.into(),
@@ -288,6 +325,83 @@ impl<T: Config> Pallet<T> {
288325
alpha_high: alpha_high.into(),
289326
alpha_low: alpha_low.into(),
290327
liquid_alpha_enabled,
328+
})
329+
}
330+
331+
pub fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option<SubnetHyperparamsV2> {
332+
if !Self::if_subnet_exist(netuid) {
333+
return None;
334+
}
335+
336+
let rho = Self::get_rho(netuid);
337+
let kappa = Self::get_kappa(netuid);
338+
let immunity_period = Self::get_immunity_period(netuid);
339+
let min_allowed_weights = Self::get_min_allowed_weights(netuid);
340+
let max_weights_limit = Self::get_max_weight_limit(netuid);
341+
let tempo = Self::get_tempo(netuid);
342+
let min_difficulty = Self::get_min_difficulty(netuid);
343+
let max_difficulty = Self::get_max_difficulty(netuid);
344+
let weights_version = Self::get_weights_version_key(netuid);
345+
let weights_rate_limit = Self::get_weights_set_rate_limit(netuid);
346+
let adjustment_interval = Self::get_adjustment_interval(netuid);
347+
let activity_cutoff = Self::get_activity_cutoff(netuid);
348+
let registration_allowed = Self::get_network_registration_allowed(netuid);
349+
let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid);
350+
let min_burn = Self::get_min_burn_as_u64(netuid);
351+
let max_burn = Self::get_max_burn_as_u64(netuid);
352+
let bonds_moving_avg = Self::get_bonds_moving_average(netuid);
353+
let max_regs_per_block = Self::get_max_registrations_per_block(netuid);
354+
let serving_rate_limit = Self::get_serving_rate_limit(netuid);
355+
let max_validators = Self::get_max_allowed_validators(netuid);
356+
let adjustment_alpha = Self::get_adjustment_alpha(netuid);
357+
let difficulty = Self::get_difficulty_as_u64(netuid);
358+
let commit_reveal_period = Self::get_reveal_period(netuid);
359+
let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid);
360+
let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid);
361+
let (alpha_low, alpha_high): (u16, u16) = Self::get_alpha_values(netuid);
362+
let alpha_sigmoid_steepness = Self::get_alpha_sigmoid_steepness(netuid);
363+
let yuma_version: u16 = match Self::get_yuma3_enabled(netuid) {
364+
true => 3u16,
365+
false => 2u16,
366+
};
367+
let subnet_token_enabled = Self::get_subtoken_enabled(netuid);
368+
let transfers_enabled = Self::get_transfer_toggle(netuid);
369+
let bonds_reset = Self::get_bonds_reset(netuid);
370+
let user_liquidity_enabled: bool = Self::is_user_liquidity_enabled(netuid);
371+
372+
Some(SubnetHyperparamsV2 {
373+
rho: rho.into(),
374+
kappa: kappa.into(),
375+
immunity_period: immunity_period.into(),
376+
min_allowed_weights: min_allowed_weights.into(),
377+
max_weights_limit: max_weights_limit.into(),
378+
tempo: tempo.into(),
379+
min_difficulty: min_difficulty.into(),
380+
max_difficulty: max_difficulty.into(),
381+
weights_version: weights_version.into(),
382+
weights_rate_limit: weights_rate_limit.into(),
383+
adjustment_interval: adjustment_interval.into(),
384+
activity_cutoff: activity_cutoff.into(),
385+
registration_allowed,
386+
target_regs_per_interval: target_regs_per_interval.into(),
387+
min_burn: min_burn.into(),
388+
max_burn: max_burn.into(),
389+
bonds_moving_avg: bonds_moving_avg.into(),
390+
max_regs_per_block: max_regs_per_block.into(),
391+
serving_rate_limit: serving_rate_limit.into(),
392+
max_validators: max_validators.into(),
393+
adjustment_alpha: adjustment_alpha.into(),
394+
difficulty: difficulty.into(),
395+
commit_reveal_period: commit_reveal_period.into(),
396+
commit_reveal_weights_enabled,
397+
alpha_high: alpha_high.into(),
398+
alpha_low: alpha_low.into(),
399+
liquid_alpha_enabled,
400+
alpha_sigmoid_steepness,
401+
yuma_version: yuma_version.into(),
402+
subnet_is_active: subnet_token_enabled,
403+
transfers_enabled,
404+
bonds_reset_enabled: bonds_reset,
291405
user_liquidity_enabled,
292406
})
293407
}

pallets/subtensor/src/utils/misc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,14 @@ impl<T: Config> Pallet<T> {
723723
Yuma3On::<T>::get(netuid)
724724
}
725725

726+
pub fn get_subtoken_enabled(netuid: NetUid) -> bool {
727+
SubtokenEnabled::<T>::get(netuid)
728+
}
729+
730+
pub fn get_transfer_toggle(netuid: NetUid) -> bool {
731+
TransferToggle::<T>::get(netuid)
732+
}
733+
726734
/// Set the duration for coldkey swap
727735
///
728736
/// # Arguments

runtime/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use pallet_subtensor::rpc_info::{
4242
neuron_info::{NeuronInfo, NeuronInfoLite},
4343
show_subnet::SubnetState,
4444
stake_info::StakeInfo,
45-
subnet_info::{SubnetHyperparams, SubnetInfo, SubnetInfov2},
45+
subnet_info::{SubnetHyperparams, SubnetHyperparamsV2, SubnetInfo, SubnetInfov2},
4646
};
4747
use smallvec::smallvec;
4848
use sp_api::impl_runtime_apis;
@@ -2277,6 +2277,10 @@ impl_runtime_apis! {
22772277
SubtensorModule::get_subnet_hyperparams(netuid)
22782278
}
22792279

2280+
fn get_subnet_hyperparams_v2(netuid: NetUid) -> Option<SubnetHyperparamsV2> {
2281+
SubtensorModule::get_subnet_hyperparams_v2(netuid)
2282+
}
2283+
22802284
fn get_dynamic_info(netuid: NetUid) -> Option<DynamicInfo<AccountId32>> {
22812285
SubtensorModule::get_dynamic_info(netuid)
22822286
}

0 commit comments

Comments
 (0)