From 41b6ae66588706afaf2b4e82da8606ecf48e55e1 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Mon, 26 Aug 2024 18:03:30 +0400 Subject: [PATCH] feat: implement subnetinfov2 , add_network with identities --- pallets/admin-utils/tests/tests.rs | 2 +- pallets/subtensor/rpc/src/lib.rs | 24 ++++ pallets/subtensor/runtime-api/src/lib.rs | 2 + pallets/subtensor/src/coinbase/root.rs | 125 ++++++++++++++++-- pallets/subtensor/src/macros/dispatches.rs | 19 ++- pallets/subtensor/src/rpc_info/subnet_info.rs | 99 +++++++++++++- pallets/subtensor/tests/epoch.rs | 4 +- pallets/subtensor/tests/migration.rs | 1 - pallets/subtensor/tests/root.rs | 25 +--- runtime/src/lib.rs | 15 +++ 10 files changed, 271 insertions(+), 45 deletions(-) diff --git a/pallets/admin-utils/tests/tests.rs b/pallets/admin-utils/tests/tests.rs index a1395a056..8ab85f177 100644 --- a/pallets/admin-utils/tests/tests.rs +++ b/pallets/admin-utils/tests/tests.rs @@ -1243,7 +1243,7 @@ fn test_sudo_get_set_alpha() { DispatchError::BadOrigin ); - assert_ok!(SubtensorModule::register_network(signer.clone(), None)); + assert_ok!(SubtensorModule::register_network(signer.clone())); assert_ok!(AdminUtils::sudo_set_alpha_values( signer.clone(), diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 2f71e9c21..2445a5eda 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -46,6 +46,10 @@ pub trait SubtensorCustomApi { fn get_subnet_info(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetsInfo")] fn get_subnets_info(&self, at: Option) -> RpcResult>; + #[method(name = "subnetInfo_getSubnetInfo_v2")] + fn get_subnet_info_v2(&self, netuid: u16, at: Option) -> RpcResult>; + #[method(name = "subnetInfo_getSubnetsInf_v2")] + fn get_subnets_info_v2(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetHyperparams")] fn get_subnet_hyperparams(&self, netuid: u16, at: Option) -> RpcResult>; @@ -215,6 +219,26 @@ where .map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into()) } + fn get_subnet_info_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); + + api.get_subnet_info_v2(at, netuid) + .map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) + } + + fn get_subnets_info_v2(&self, at: Option<::Hash>) -> RpcResult> { + let api = self.client.runtime_api(); + let at = at.unwrap_or_else(|| self.client.info().best_hash); + + api.get_subnets_info_v2(at) + .map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into()) + } + fn get_network_lock_cost(&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 9095ad54a..ca43384b8 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -21,6 +21,8 @@ sp_api::decl_runtime_apis! { pub trait SubnetInfoRuntimeApi { fn get_subnet_info(netuid: u16) -> Vec; fn get_subnets_info() -> Vec; + fn get_subnet_info_v2(netuid: u16) -> Vec; + fn get_subnets_info_v2() -> Vec; fn get_subnet_hyperparams(netuid: u16) -> Vec; } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index c1c9b3ad9..4a25f5ab8 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -895,6 +895,100 @@ impl Pallet { /// /// # Args: /// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed. + /// + /// # Events: + /// * `NetworkAdded(netuid, modality)`: Emitted when a new network is successfully added. + /// * `NetworkRemoved(netuid)`: Emitted when an existing network is removed to make room for the new one. + /// + /// # Raises: + /// * 'TxRateLimitExceeded': If the rate limit for network registration is exceeded. + /// * 'NotEnoughBalanceToStake': If there isn't enough balance to stake for network registration. + /// * 'BalanceWithdrawalError': If an error occurs during balance withdrawal for network registration. + /// + pub fn user_add_network(origin: T::RuntimeOrigin) -> dispatch::DispatchResult { + // --- 0. Ensure the caller is a signed user. + let coldkey = ensure_signed(origin)?; + + // --- 1. Rate limit for network registrations. + let current_block = Self::get_current_block_as_u64(); + let last_lock_block = Self::get_network_last_lock_block(); + ensure!( + current_block.saturating_sub(last_lock_block) >= NetworkRateLimit::::get(), + Error::::NetworkTxRateLimitExceeded + ); + + // --- 2. Calculate and lock the required tokens. + let lock_amount: u64 = Self::get_network_lock_cost(); + log::debug!("network lock_amount: {:?}", lock_amount); + ensure!( + Self::can_remove_balance_from_coldkey_account(&coldkey, lock_amount), + Error::::NotEnoughBalanceToStake + ); + + // --- 4. Determine the netuid to register. + let netuid_to_register: u16 = { + log::debug!( + "subnet count: {:?}\nmax subnets: {:?}", + Self::get_num_subnets(), + Self::get_max_subnets() + ); + if Self::get_num_subnets().saturating_sub(1) < Self::get_max_subnets() { + // We subtract one because we don't want root subnet to count towards total + let mut next_available_netuid = 0; + loop { + next_available_netuid.saturating_inc(); + if !Self::if_subnet_exist(next_available_netuid) { + log::debug!("got subnet id: {:?}", next_available_netuid); + break next_available_netuid; + } + } + } else { + let netuid_to_prune = Self::get_subnet_to_prune(); + ensure!(netuid_to_prune > 0, Error::::AllNetworksInImmunity); + + Self::remove_network(netuid_to_prune); + log::debug!("remove_network: {:?}", netuid_to_prune,); + Self::deposit_event(Event::NetworkRemoved(netuid_to_prune)); + + if SubnetIdentities::::take(netuid_to_prune).is_some() { + Self::deposit_event(Event::SubnetIdentityRemoved(netuid_to_prune)); + } + + netuid_to_prune + } + }; + + // --- 5. Perform the lock operation. + let actual_lock_amount = Self::remove_balance_from_coldkey_account(&coldkey, lock_amount)?; + Self::set_subnet_locked_balance(netuid_to_register, actual_lock_amount); + Self::set_network_last_lock(actual_lock_amount); + + // --- 6. Set initial and custom parameters for the network. + Self::init_new_network(netuid_to_register, 360); + log::debug!("init_new_network: {:?}", netuid_to_register,); + + // --- 7. Set netuid storage. + let current_block_number: u64 = Self::get_current_block_as_u64(); + NetworkLastRegistered::::set(current_block_number); + NetworkRegisteredAt::::insert(netuid_to_register, current_block_number); + SubnetOwner::::insert(netuid_to_register, coldkey); + + // --- 8. Emit the NetworkAdded event. + log::debug!( + "NetworkAdded( netuid:{:?}, modality:{:?} )", + netuid_to_register, + 0 + ); + Self::deposit_event(Event::NetworkAdded(netuid_to_register, 0)); + + // --- 9. Return success. + Ok(()) + } + + /// Facilitates user registration of a new subnetwork with subnet identity. + /// + /// # Args: + /// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed. /// * `identity` (`Option`): Optional identity to be associated with the new subnetwork. /// /// # Events: @@ -908,7 +1002,7 @@ impl Pallet { /// * 'NotEnoughBalanceToStake': If there isn't enough balance to stake for network registration. /// * 'BalanceWithdrawalError': If an error occurs during balance withdrawal for network registration. /// - pub fn user_add_network( + pub fn user_add_network_with_identity( origin: T::RuntimeOrigin, identity: Option, ) -> dispatch::DispatchResult { @@ -1126,8 +1220,8 @@ impl Pallet { /// Removes a network (identified by netuid) and all associated parameters. /// /// This function is responsible for cleaning up all the data associated with a network. - /// It ensures that all the storage values related to the network are removed, and any - /// reserved balance is returned to the network owner. + /// It ensures that all the storage values related to the network are removed, any + /// reserved balance is returned to the network owner, and the subnet identity is removed if it exists. /// /// # Args: /// * 'netuid': ('u16'): The unique identifier of the network to be removed. @@ -1136,10 +1230,15 @@ impl Pallet { /// This function does not emit any events, nor does it raise any errors. It silently /// returns if any internal checks fail. /// + /// # Example: + /// ```rust + /// let netuid_to_remove: u16 = 5; + /// Pallet::::remove_network(netuid_to_remove); + /// ``` pub fn remove_network(netuid: u16) { // --- 1. Return balance to subnet owner. - let owner_coldkey = SubnetOwner::::get(netuid); - let reserved_amount = Self::get_subnet_locked_balance(netuid); + let owner_coldkey: T::AccountId = SubnetOwner::::get(netuid); + let reserved_amount: u64 = Self::get_subnet_locked_balance(netuid); // --- 2. Remove network count. SubnetworkN::::remove(netuid); @@ -1150,13 +1249,13 @@ impl Pallet { // --- 4. Remove netuid from added networks. NetworksAdded::::remove(netuid); - // --- 6. Decrement the network counter. - TotalNetworks::::mutate(|n| *n = n.saturating_sub(1)); + // --- 5. Decrement the network counter. + TotalNetworks::::mutate(|n: &mut u16| *n = n.saturating_sub(1)); - // --- 7. Remove various network-related storages. + // --- 6. Remove various network-related storages. NetworkRegisteredAt::::remove(netuid); - // --- 8. Remove incentive mechanism memory. + // --- 7. Remove incentive mechanism memory. let _ = Uids::::clear_prefix(netuid, u32::MAX, None); let _ = Keys::::clear_prefix(netuid, u32::MAX, None); let _ = Bonds::::clear_prefix(netuid, u32::MAX, None); @@ -1171,7 +1270,7 @@ impl Pallet { ) { // Create a new vector to hold modified weights. - let mut modified_weights = weights_i.clone(); + let mut modified_weights: Vec<(u16, u16)> = weights_i.clone(); // Iterate over each weight entry to potentially update it. for (subnet_id, weight) in modified_weights.iter_mut() { if subnet_id == &netuid { @@ -1213,6 +1312,12 @@ impl Pallet { Self::add_balance_to_coldkey_account(&owner_coldkey, reserved_amount); Self::set_subnet_locked_balance(netuid, 0); SubnetOwner::::remove(netuid); + + // --- 13. Remove subnet identity if it exists. + if SubnetIdentities::::contains_key(netuid) { + SubnetIdentities::::remove(netuid); + Self::deposit_event(Event::SubnetIdentityRemoved(netuid)); + } } #[allow(clippy::arithmetic_side_effects)] diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index b1446b69d..f33b0c3bc 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -901,11 +901,8 @@ mod dispatches { #[pallet::weight((Weight::from_parts(157_000_000, 0) .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] - pub fn register_network( - origin: OriginFor, - identity: Option, - ) -> DispatchResult { - Self::user_add_network(origin, identity) + pub fn register_network(origin: OriginFor) -> DispatchResult { + Self::user_add_network(origin) } /// Facility extrinsic for user to get taken from faucet @@ -1201,5 +1198,17 @@ mod dispatches { ) -> DispatchResult { Self::do_set_subnet_identity(origin, netuid, subnet_name, github_repo, subnet_contact) } + + /// User register a new subnetwork + #[pallet::call_index(79)] + #[pallet::weight((Weight::from_parts(157_000_000, 0) + .saturating_add(T::DbWeight::get().reads(16)) + .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] + pub fn register_network_with_identity( + origin: OriginFor, + identity: Option, + ) -> DispatchResult { + Self::user_add_network_with_identity(origin, identity) + } } } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 6e8b4bdc5..9b22e0401 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -4,7 +4,7 @@ use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; -#[freeze_struct("ccca539640c3f631")] +#[freeze_struct("fe79d58173da662a")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] pub struct SubnetInfo { netuid: Compact, @@ -25,6 +25,29 @@ pub struct SubnetInfo { emission_values: Compact, burn: Compact, owner: T::AccountId, +} + +#[freeze_struct("65f931972fa13222")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] +pub struct SubnetInfov2 { + netuid: Compact, + rho: Compact, + kappa: Compact, + difficulty: Compact, + immunity_period: Compact, + max_allowed_validators: Compact, + min_allowed_weights: Compact, + max_weights_limit: Compact, + scaling_law_power: Compact, + subnetwork_n: Compact, + max_allowed_uids: Compact, + blocks_since_last_step: Compact, + tempo: Compact, + network_modality: Compact, + network_connect: Vec<[u16; 2]>, + emission_values: Compact, + burn: Compact, + owner: T::AccountId, identity: Option, } @@ -81,8 +104,6 @@ impl Pallet { let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); let burn: Compact = Self::get_burn_as_u64(netuid).into(); - let identity: Option = SubnetIdentities::::get(netuid); - // DEPRECATED let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { @@ -108,7 +129,6 @@ impl Pallet { emission_values: emission_values.into(), burn, owner: Self::get_subnet_owner(netuid), - identity, }) } @@ -134,6 +154,77 @@ impl Pallet { subnets_info } + pub fn get_subnet_info_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 difficulty: Compact = Self::get_difficulty_as_u64(netuid).into(); + let immunity_period = Self::get_immunity_period(netuid); + let max_allowed_validators = Self::get_max_allowed_validators(netuid); + let min_allowed_weights = Self::get_min_allowed_weights(netuid); + let max_weights_limit = Self::get_max_weight_limit(netuid); + let scaling_law_power = Self::get_scaling_law_power(netuid); + let subnetwork_n = Self::get_subnetwork_n(netuid); + let max_allowed_uids = Self::get_max_allowed_uids(netuid); + let blocks_since_last_step = Self::get_blocks_since_last_step(netuid); + let tempo = Self::get_tempo(netuid); + let network_modality = >::get(netuid); + let emission_values = Self::get_emission_value(netuid); + let burn: Compact = Self::get_burn_as_u64(netuid).into(); + let identity: Option = SubnetIdentities::::get(netuid); + + // DEPRECATED + let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); + // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { + // network_connect.push([_netuid_, con_req]); + // } + + Some(SubnetInfov2 { + rho: rho.into(), + kappa: kappa.into(), + difficulty, + immunity_period: immunity_period.into(), + netuid: netuid.into(), + max_allowed_validators: max_allowed_validators.into(), + min_allowed_weights: min_allowed_weights.into(), + max_weights_limit: max_weights_limit.into(), + scaling_law_power: scaling_law_power.into(), + subnetwork_n: subnetwork_n.into(), + max_allowed_uids: max_allowed_uids.into(), + blocks_since_last_step: blocks_since_last_step.into(), + tempo: tempo.into(), + network_modality: network_modality.into(), + network_connect, + emission_values: emission_values.into(), + burn, + owner: Self::get_subnet_owner(netuid), + identity, + }) + } + pub fn get_subnets_info_v2() -> Vec>> { + let mut subnet_netuids = Vec::::new(); + let mut max_netuid: u16 = 0; + for (netuid, added) in as IterableStorageMap>::iter() { + if added { + subnet_netuids.push(netuid); + if netuid > max_netuid { + max_netuid = netuid; + } + } + } + + let mut subnets_info = Vec::>>::new(); + for netuid_ in 0..=max_netuid { + if subnet_netuids.contains(&netuid_) { + subnets_info.push(Self::get_subnet_info(netuid_)); + } + } + + subnets_info + } pub fn get_subnet_hyperparams(netuid: u16) -> Option { if !Self::if_subnet_exist(netuid) { return None; diff --git a/pallets/subtensor/tests/epoch.rs b/pallets/subtensor/tests/epoch.rs index 30cc1d304..9c4bf87cc 100644 --- a/pallets/subtensor/tests/epoch.rs +++ b/pallets/subtensor/tests/epoch.rs @@ -1501,7 +1501,7 @@ fn test_set_alpha_disabled() { assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,)); assert_ok!(SubtensorModule::add_stake(signer.clone(), hotkey, 1000)); // Only owner can set alpha values - assert_ok!(SubtensorModule::register_network(signer.clone(), None)); + assert_ok!(SubtensorModule::register_network(signer.clone())); // Explicitly set to false SubtensorModule::set_liquid_alpha_enabled(netuid, false); @@ -2584,7 +2584,7 @@ fn test_get_set_alpha() { DispatchError::BadOrigin ); - assert_ok!(SubtensorModule::register_network(signer.clone(), None)); + assert_ok!(SubtensorModule::register_network(signer.clone())); assert_ok!(SubtensorModule::do_set_alpha_values( signer.clone(), diff --git a/pallets/subtensor/tests/migration.rs b/pallets/subtensor/tests/migration.rs index 95479d7d7..6c40d7d78 100644 --- a/pallets/subtensor/tests/migration.rs +++ b/pallets/subtensor/tests/migration.rs @@ -171,7 +171,6 @@ fn test_total_issuance_global() { assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero. assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); SubtensorModule::set_max_allowed_uids(netuid, 1); // Set the maximum allowed unique identifiers for the network to 1. assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero. diff --git a/pallets/subtensor/tests/root.rs b/pallets/subtensor/tests/root.rs index 0c621739b..6a2904c87 100644 --- a/pallets/subtensor/tests/root.rs +++ b/pallets/subtensor/tests/root.rs @@ -237,7 +237,6 @@ fn test_root_set_weights() { log::debug!("Adding network with netuid: {}", netuid); assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(U256::from(netuid + 456)), - None )); } @@ -383,7 +382,6 @@ fn test_root_set_weights_out_of_order_netuids() { if netuid % 2 == 0 { assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(U256::from(netuid)), - None )); } else { add_network(netuid as u16 * 10, 1000, 0) @@ -475,7 +473,6 @@ fn test_root_subnet_creation_deletion() { // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 0, lock_reduction_interval: 2, current_block: 0, mult: 1 lock_cost: 100000000000 assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 0, lock_reduction_interval: 2, current_block: 0, mult: 1 lock_cost: 100000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 100_000_000_000); @@ -483,7 +480,6 @@ fn test_root_subnet_creation_deletion() { // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 0, lock_reduction_interval: 2, current_block: 1, mult: 1 lock_cost: 100000000000 assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 1, lock_reduction_interval: 2, current_block: 1, mult: 2 lock_cost: 200000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 200_000_000_000); // Doubles from previous subnet creation @@ -498,7 +494,6 @@ fn test_root_subnet_creation_deletion() { assert_eq!(SubtensorModule::get_network_lock_cost(), 100_000_000_000); // Reaches min value assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 4, lock_reduction_interval: 2, current_block: 4, mult: 2 lock_cost: 200000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 200_000_000_000); // Doubles from previous subnet creation @@ -506,7 +501,6 @@ fn test_root_subnet_creation_deletion() { // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 4, lock_reduction_interval: 2, current_block: 5, mult: 2 lock_cost: 150000000000 assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 150000000000, min_lock: 100000000000, last_lock_block: 5, lock_reduction_interval: 2, current_block: 5, mult: 2 lock_cost: 300000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 300_000_000_000); // Doubles from previous subnet creation @@ -514,7 +508,6 @@ fn test_root_subnet_creation_deletion() { // last_lock: 150000000000, min_lock: 100000000000, last_lock_block: 5, lock_reduction_interval: 2, current_block: 6, mult: 2 lock_cost: 225000000000 assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 225000000000, min_lock: 100000000000, last_lock_block: 6, lock_reduction_interval: 2, current_block: 6, mult: 2 lock_cost: 450000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 450_000_000_000); // Increasing @@ -522,19 +515,16 @@ fn test_root_subnet_creation_deletion() { // last_lock: 225000000000, min_lock: 100000000000, last_lock_block: 6, lock_reduction_interval: 2, current_block: 7, mult: 2 lock_cost: 337500000000 assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 337500000000, min_lock: 100000000000, last_lock_block: 7, lock_reduction_interval: 2, current_block: 7, mult: 2 lock_cost: 675000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 675_000_000_000); // Increasing. assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); // last_lock: 337500000000, min_lock: 100000000000, last_lock_block: 7, lock_reduction_interval: 2, current_block: 7, mult: 2 lock_cost: 675000000000 assert_eq!(SubtensorModule::get_network_lock_cost(), 1_350_000_000_000); // Double increasing. assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); assert_eq!(SubtensorModule::get_network_lock_cost(), 2_700_000_000_000); // Double increasing again. @@ -584,7 +574,6 @@ fn test_network_pruning() { )); assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(cold), - None )); log::debug!("Adding network with netuid: {}", (i as u16) + 1); assert!(SubtensorModule::if_subnet_exist((i as u16) + 1)); @@ -658,19 +647,16 @@ fn test_network_prune_results() { assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); step_block(3); assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); step_block(3); assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), - None )); step_block(3); @@ -715,7 +701,6 @@ fn test_weights_after_network_pruning() { // Register a network assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(cold), - None )); log::debug!("Adding network with netuid: {}", (i as u16) + 1); @@ -776,7 +761,6 @@ fn test_weights_after_network_pruning() { assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(cold), - None )); // Subnet should not exist, as it would replace a previous subnet. @@ -1028,7 +1012,7 @@ fn test_user_add_network_with_identity_fields_ok() { SubtensorModule::add_balance_to_coldkey_account(&coldkey_1, balance_1); - assert_ok!(SubtensorModule::user_add_network( + assert_ok!(SubtensorModule::user_add_network_with_identity( RuntimeOrigin::signed(coldkey_1), Some(identity_value_1.clone()) )); @@ -1036,7 +1020,7 @@ fn test_user_add_network_with_identity_fields_ok() { let balance_2 = SubtensorModule::get_network_lock_cost() + 10_000; SubtensorModule::add_balance_to_coldkey_account(&coldkey_2, balance_2); - assert_ok!(SubtensorModule::user_add_network( + assert_ok!(SubtensorModule::user_add_network_with_identity( RuntimeOrigin::signed(coldkey_2), Some(identity_value_2.clone()) )); @@ -1052,10 +1036,7 @@ fn test_user_add_network_with_identity_fields_ok() { assert_eq!(stored_identity_2.subnet_contact, subnet_contact_2); // Now remove the first network. - assert_ok!(SubtensorModule::user_remove_network( - RuntimeOrigin::signed(coldkey_1), - 1 - )); + assert_ok!(SubtensorModule::user_remove_network(coldkey_1, 1)); // Verify that the first network and identity have been removed. assert!(SubnetIdentities::::get(1).is_none()); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9ad0624d0..422954476 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1426,6 +1426,21 @@ impl_runtime_apis! { result.encode() } + fn get_subnet_info_v2(netuid: u16) -> Vec { + let _result = SubtensorModule::get_subnet_info_v2(netuid); + if _result.is_some() { + let result = _result.expect("Could not get SubnetInfo"); + result.encode() + } else { + vec![] + } + } + + fn get_subnets_info_v2() -> Vec { + let result = SubtensorModule::get_subnets_info_v2(); + result.encode() + } + fn get_subnet_hyperparams(netuid: u16) -> Vec { let _result = SubtensorModule::get_subnet_hyperparams(netuid); if _result.is_some() {