Skip to content

Commit 898f460

Browse files
committed
Merge remote-tracking branch 'origin/devnet-ready' into sam-fix-benchmarks
2 parents 8176f57 + c23c7fd commit 898f460

File tree

11 files changed

+173
-45
lines changed

11 files changed

+173
-45
lines changed

pallets/admin-utils/tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ fn test_sudo_get_set_alpha() {
12431243
DispatchError::BadOrigin
12441244
);
12451245

1246-
assert_ok!(SubtensorModule::register_network(signer.clone(), None));
1246+
assert_ok!(SubtensorModule::register_network(signer.clone()));
12471247

12481248
assert_ok!(AdminUtils::sudo_set_alpha_values(
12491249
signer.clone(),

pallets/subtensor/rpc/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub trait SubtensorCustomApi<BlockHash> {
4646
fn get_subnet_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
4747
#[method(name = "subnetInfo_getSubnetsInfo")]
4848
fn get_subnets_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
49+
#[method(name = "subnetInfo_getSubnetInfo_v2")]
50+
fn get_subnet_info_v2(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
51+
#[method(name = "subnetInfo_getSubnetsInf_v2")]
52+
fn get_subnets_info_v2(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
4953
#[method(name = "subnetInfo_getSubnetHyperparams")]
5054
fn get_subnet_hyperparams(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
5155

@@ -215,6 +219,26 @@ where
215219
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
216220
}
217221

222+
fn get_subnet_info_v2(
223+
&self,
224+
netuid: u16,
225+
at: Option<<Block as BlockT>::Hash>,
226+
) -> RpcResult<Vec<u8>> {
227+
let api = self.client.runtime_api();
228+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
229+
230+
api.get_subnet_info_v2(at, netuid)
231+
.map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into())
232+
}
233+
234+
fn get_subnets_info_v2(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
235+
let api = self.client.runtime_api();
236+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
237+
238+
api.get_subnets_info_v2(at)
239+
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
240+
}
241+
218242
fn get_network_lock_cost(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<u64> {
219243
let api = self.client.runtime_api();
220244
let at = at.unwrap_or_else(|| self.client.info().best_hash);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ sp_api::decl_runtime_apis! {
2121
pub trait SubnetInfoRuntimeApi {
2222
fn get_subnet_info(netuid: u16) -> Vec<u8>;
2323
fn get_subnets_info() -> Vec<u8>;
24+
fn get_subnet_info_v2(netuid: u16) -> Vec<u8>;
25+
fn get_subnets_info_v2() -> Vec<u8>;
2426
fn get_subnet_hyperparams(netuid: u16) -> Vec<u8>;
2527
}
2628

pallets/subtensor/src/benchmarks.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ benchmarks! {
299299
let amount: u64 = 1;
300300
let amount_to_be_staked = 100_000_000_000_000u64;
301301
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
302-
}: register_network(RawOrigin::Signed(coldkey), None)
302+
}: register_network(RawOrigin::Signed(coldkey))
303303

304304
benchmark_dissolve_network {
305305
let seed : u32 = 1;
@@ -311,9 +311,8 @@ benchmarks! {
311311
let amount: u64 = 1;
312312
let amount_to_be_staked = 100_000_000_000_000u64;
313313
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
314-
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into(), None));
315-
let c1 = coldkey.clone();
316-
}: dissolve_network(RawOrigin::Signed(c1), coldkey, 1)
314+
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into()));
315+
}: dissolve_network(RawOrigin::Root, coldkey.clone(), 1)
317316

318317

319318
// swap_hotkey {
@@ -520,6 +519,6 @@ reveal_weights {
520519
Identities::<T>::insert(&old_coldkey, identity);
521520

522521
// Benchmark setup complete, now execute the extrinsic
523-
}: swap_coldkey(RawOrigin::Signed(old_coldkey.clone()), old_coldkey.clone(), new_coldkey.clone())
522+
}: swap_coldkey(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone())
524523

525524
}

pallets/subtensor/src/coinbase/root.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<T: Config> Pallet<T> {
891891
.into())
892892
}
893893

894-
/// Facilitates user registration of a new subnetwork.
894+
/// Facilitates user registration of a new subnetwork with subnet identity.
895895
///
896896
/// # Args:
897897
/// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed.
@@ -1126,20 +1126,19 @@ impl<T: Config> Pallet<T> {
11261126
/// Removes a network (identified by netuid) and all associated parameters.
11271127
///
11281128
/// This function is responsible for cleaning up all the data associated with a network.
1129-
/// It ensures that all the storage values related to the network are removed, and any
1130-
/// reserved balance is returned to the network owner.
1129+
/// It ensures that all the storage values related to the network are removed, any
1130+
/// reserved balance is returned to the network owner, and the subnet identity is removed if it exists.
11311131
///
11321132
/// # Args:
11331133
/// * 'netuid': ('u16'): The unique identifier of the network to be removed.
11341134
///
11351135
/// # Note:
11361136
/// This function does not emit any events, nor does it raise any errors. It silently
11371137
/// returns if any internal checks fail.
1138-
///
11391138
pub fn remove_network(netuid: u16) {
11401139
// --- 1. Return balance to subnet owner.
1141-
let owner_coldkey = SubnetOwner::<T>::get(netuid);
1142-
let reserved_amount = Self::get_subnet_locked_balance(netuid);
1140+
let owner_coldkey: T::AccountId = SubnetOwner::<T>::get(netuid);
1141+
let reserved_amount: u64 = Self::get_subnet_locked_balance(netuid);
11431142

11441143
// --- 2. Remove network count.
11451144
SubnetworkN::<T>::remove(netuid);
@@ -1150,13 +1149,13 @@ impl<T: Config> Pallet<T> {
11501149
// --- 4. Remove netuid from added networks.
11511150
NetworksAdded::<T>::remove(netuid);
11521151

1153-
// --- 6. Decrement the network counter.
1154-
TotalNetworks::<T>::mutate(|n| *n = n.saturating_sub(1));
1152+
// --- 5. Decrement the network counter.
1153+
TotalNetworks::<T>::mutate(|n: &mut u16| *n = n.saturating_sub(1));
11551154

1156-
// --- 7. Remove various network-related storages.
1155+
// --- 6. Remove various network-related storages.
11571156
NetworkRegisteredAt::<T>::remove(netuid);
11581157

1159-
// --- 8. Remove incentive mechanism memory.
1158+
// --- 7. Remove incentive mechanism memory.
11601159
let _ = Uids::<T>::clear_prefix(netuid, u32::MAX, None);
11611160
let _ = Keys::<T>::clear_prefix(netuid, u32::MAX, None);
11621161
let _ = Bonds::<T>::clear_prefix(netuid, u32::MAX, None);
@@ -1171,7 +1170,7 @@ impl<T: Config> Pallet<T> {
11711170
)
11721171
{
11731172
// Create a new vector to hold modified weights.
1174-
let mut modified_weights = weights_i.clone();
1173+
let mut modified_weights: Vec<(u16, u16)> = weights_i.clone();
11751174
// Iterate over each weight entry to potentially update it.
11761175
for (subnet_id, weight) in modified_weights.iter_mut() {
11771176
if subnet_id == &netuid {
@@ -1213,6 +1212,12 @@ impl<T: Config> Pallet<T> {
12131212
Self::add_balance_to_coldkey_account(&owner_coldkey, reserved_amount);
12141213
Self::set_subnet_locked_balance(netuid, 0);
12151214
SubnetOwner::<T>::remove(netuid);
1215+
1216+
// --- 13. Remove subnet identity if it exists.
1217+
if SubnetIdentities::<T>::contains_key(netuid) {
1218+
SubnetIdentities::<T>::remove(netuid);
1219+
Self::deposit_event(Event::SubnetIdentityRemoved(netuid));
1220+
}
12161221
}
12171222

12181223
#[allow(clippy::arithmetic_side_effects)]

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,8 @@ mod dispatches {
901901
#[pallet::weight((Weight::from_parts(157_000_000, 0)
902902
.saturating_add(T::DbWeight::get().reads(16))
903903
.saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))]
904-
pub fn register_network(
905-
origin: OriginFor<T>,
906-
identity: Option<SubnetIdentityOf>,
907-
) -> DispatchResult {
908-
Self::user_add_network(origin, identity)
904+
pub fn register_network(origin: OriginFor<T>) -> DispatchResult {
905+
Self::user_add_network(origin, None)
909906
}
910907

911908
/// Facility extrinsic for user to get taken from faucet
@@ -1201,5 +1198,17 @@ mod dispatches {
12011198
) -> DispatchResult {
12021199
Self::do_set_subnet_identity(origin, netuid, subnet_name, github_repo, subnet_contact)
12031200
}
1201+
1202+
/// User register a new subnetwork
1203+
#[pallet::call_index(79)]
1204+
#[pallet::weight((Weight::from_parts(157_000_000, 0)
1205+
.saturating_add(T::DbWeight::get().reads(16))
1206+
.saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))]
1207+
pub fn register_network_with_identity(
1208+
origin: OriginFor<T>,
1209+
identity: Option<SubnetIdentityOf>,
1210+
) -> DispatchResult {
1211+
Self::user_add_network(origin, identity)
1212+
}
12041213
}
12051214
}

pallets/subtensor/src/rpc_info/subnet_info.rs

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use frame_support::storage::IterableStorageMap;
44
extern crate alloc;
55
use codec::Compact;
66

7-
#[freeze_struct("ccca539640c3f631")]
7+
#[freeze_struct("fe79d58173da662a")]
88
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
99
pub struct SubnetInfo<T: Config> {
1010
netuid: Compact<u16>,
@@ -25,6 +25,29 @@ pub struct SubnetInfo<T: Config> {
2525
emission_values: Compact<u64>,
2626
burn: Compact<u64>,
2727
owner: T::AccountId,
28+
}
29+
30+
#[freeze_struct("65f931972fa13222")]
31+
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
32+
pub struct SubnetInfov2<T: Config> {
33+
netuid: Compact<u16>,
34+
rho: Compact<u16>,
35+
kappa: Compact<u16>,
36+
difficulty: Compact<u64>,
37+
immunity_period: Compact<u16>,
38+
max_allowed_validators: Compact<u16>,
39+
min_allowed_weights: Compact<u16>,
40+
max_weights_limit: Compact<u16>,
41+
scaling_law_power: Compact<u16>,
42+
subnetwork_n: Compact<u16>,
43+
max_allowed_uids: Compact<u16>,
44+
blocks_since_last_step: Compact<u64>,
45+
tempo: Compact<u16>,
46+
network_modality: Compact<u16>,
47+
network_connect: Vec<[u16; 2]>,
48+
emission_values: Compact<u64>,
49+
burn: Compact<u64>,
50+
owner: T::AccountId,
2851
identity: Option<SubnetIdentity>,
2952
}
3053

@@ -81,8 +104,6 @@ impl<T: Config> Pallet<T> {
81104
let network_modality = <NetworkModality<T>>::get(netuid);
82105
let emission_values = Self::get_emission_value(netuid);
83106
let burn: Compact<u64> = Self::get_burn_as_u64(netuid).into();
84-
let identity: Option<SubnetIdentity> = SubnetIdentities::<T>::get(netuid);
85-
86107
// DEPRECATED
87108
let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new();
88109
// DEPRECATED for ( _netuid_, con_req) in < NetworkConnect<T> as IterableStorageDoubleMap<u16, u16, u16> >::iter_prefix(netuid) {
@@ -108,7 +129,6 @@ impl<T: Config> Pallet<T> {
108129
emission_values: emission_values.into(),
109130
burn,
110131
owner: Self::get_subnet_owner(netuid),
111-
identity,
112132
})
113133
}
114134

@@ -134,6 +154,77 @@ impl<T: Config> Pallet<T> {
134154
subnets_info
135155
}
136156

157+
pub fn get_subnet_info_v2(netuid: u16) -> Option<SubnetInfov2<T>> {
158+
if !Self::if_subnet_exist(netuid) {
159+
return None;
160+
}
161+
162+
let rho = Self::get_rho(netuid);
163+
let kappa = Self::get_kappa(netuid);
164+
let difficulty: Compact<u64> = Self::get_difficulty_as_u64(netuid).into();
165+
let immunity_period = Self::get_immunity_period(netuid);
166+
let max_allowed_validators = Self::get_max_allowed_validators(netuid);
167+
let min_allowed_weights = Self::get_min_allowed_weights(netuid);
168+
let max_weights_limit = Self::get_max_weight_limit(netuid);
169+
let scaling_law_power = Self::get_scaling_law_power(netuid);
170+
let subnetwork_n = Self::get_subnetwork_n(netuid);
171+
let max_allowed_uids = Self::get_max_allowed_uids(netuid);
172+
let blocks_since_last_step = Self::get_blocks_since_last_step(netuid);
173+
let tempo = Self::get_tempo(netuid);
174+
let network_modality = <NetworkModality<T>>::get(netuid);
175+
let emission_values = Self::get_emission_value(netuid);
176+
let burn: Compact<u64> = Self::get_burn_as_u64(netuid).into();
177+
let identity: Option<SubnetIdentity> = SubnetIdentities::<T>::get(netuid);
178+
179+
// DEPRECATED
180+
let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new();
181+
// DEPRECATED for ( _netuid_, con_req) in < NetworkConnect<T> as IterableStorageDoubleMap<u16, u16, u16> >::iter_prefix(netuid) {
182+
// network_connect.push([_netuid_, con_req]);
183+
// }
184+
185+
Some(SubnetInfov2 {
186+
rho: rho.into(),
187+
kappa: kappa.into(),
188+
difficulty,
189+
immunity_period: immunity_period.into(),
190+
netuid: netuid.into(),
191+
max_allowed_validators: max_allowed_validators.into(),
192+
min_allowed_weights: min_allowed_weights.into(),
193+
max_weights_limit: max_weights_limit.into(),
194+
scaling_law_power: scaling_law_power.into(),
195+
subnetwork_n: subnetwork_n.into(),
196+
max_allowed_uids: max_allowed_uids.into(),
197+
blocks_since_last_step: blocks_since_last_step.into(),
198+
tempo: tempo.into(),
199+
network_modality: network_modality.into(),
200+
network_connect,
201+
emission_values: emission_values.into(),
202+
burn,
203+
owner: Self::get_subnet_owner(netuid),
204+
identity,
205+
})
206+
}
207+
pub fn get_subnets_info_v2() -> Vec<Option<SubnetInfo<T>>> {
208+
let mut subnet_netuids = Vec::<u16>::new();
209+
let mut max_netuid: u16 = 0;
210+
for (netuid, added) in <NetworksAdded<T> as IterableStorageMap<u16, bool>>::iter() {
211+
if added {
212+
subnet_netuids.push(netuid);
213+
if netuid > max_netuid {
214+
max_netuid = netuid;
215+
}
216+
}
217+
}
218+
219+
let mut subnets_info = Vec::<Option<SubnetInfo<T>>>::new();
220+
for netuid_ in 0..=max_netuid {
221+
if subnet_netuids.contains(&netuid_) {
222+
subnets_info.push(Self::get_subnet_info(netuid_));
223+
}
224+
}
225+
226+
subnets_info
227+
}
137228
pub fn get_subnet_hyperparams(netuid: u16) -> Option<SubnetHyperparams> {
138229
if !Self::if_subnet_exist(netuid) {
139230
return None;

pallets/subtensor/tests/epoch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ fn test_set_alpha_disabled() {
15011501
assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,));
15021502
assert_ok!(SubtensorModule::add_stake(signer.clone(), hotkey, 1000));
15031503
// Only owner can set alpha values
1504-
assert_ok!(SubtensorModule::register_network(signer.clone(), None));
1504+
assert_ok!(SubtensorModule::register_network(signer.clone()));
15051505

15061506
// Explicitly set to false
15071507
SubtensorModule::set_liquid_alpha_enabled(netuid, false);
@@ -2584,7 +2584,7 @@ fn test_get_set_alpha() {
25842584
DispatchError::BadOrigin
25852585
);
25862586

2587-
assert_ok!(SubtensorModule::register_network(signer.clone(), None));
2587+
assert_ok!(SubtensorModule::register_network(signer.clone()));
25882588

25892589
assert_ok!(SubtensorModule::do_set_alpha_values(
25902590
signer.clone(),

pallets/subtensor/tests/migration.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ fn test_total_issuance_global() {
171171
assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero.
172172
assert_ok!(SubtensorModule::register_network(
173173
<<Test as Config>::RuntimeOrigin>::signed(owner),
174-
None
175174
));
176175
SubtensorModule::set_max_allowed_uids(netuid, 1); // Set the maximum allowed unique identifiers for the network to 1.
177176
assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero.

0 commit comments

Comments
 (0)