diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 4af039ad65..4915bb3ace 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -299,7 +299,7 @@ benchmarks! { let amount: u64 = 1; let amount_to_be_staked = 100_000_000_000_000u64; Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - }: register_network(RawOrigin::Signed(coldkey), None) + }: register_network(RawOrigin::Signed(coldkey)) benchmark_dissolve_network { let seed : u32 = 1; @@ -311,8 +311,8 @@ benchmarks! { let amount: u64 = 1; let amount_to_be_staked = 100_000_000_000_000u64; Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - assert_ok!(Subtensor::::register_network(RawOrigin::Signed(coldkey.clone()).into(), None)); - }: dissolve_network(RawOrigin::Signed(coldkey), 1) + assert_ok!(Subtensor::::register_network(RawOrigin::Signed(coldkey.clone()).into())); + }: dissolve_network(RawOrigin::Root, coldkey.clone(), 1) // swap_hotkey { @@ -519,6 +519,6 @@ reveal_weights { Identities::::insert(&old_coldkey, identity); // Benchmark setup complete, now execute the extrinsic -}: swap_coldkey(RawOrigin::Signed(old_coldkey.clone()), old_coldkey.clone(), new_coldkey.clone()) +}: swap_coldkey(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()) } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 4a25f5ab84..067d5855bf 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -891,100 +891,6 @@ impl Pallet { .into()) } - /// Facilitates user registration of a new subnetwork. - /// - /// # 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: @@ -1002,7 +908,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_with_identity( + pub fn user_add_network( origin: T::RuntimeOrigin, identity: Option, ) -> dispatch::DispatchResult { @@ -1229,12 +1135,6 @@ impl Pallet { /// # Note: /// 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: T::AccountId = SubnetOwner::::get(netuid); diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index f33b0c3bc8..a97e4494d8 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -902,7 +902,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] pub fn register_network(origin: OriginFor) -> DispatchResult { - Self::user_add_network(origin) + Self::user_add_network(origin, None) } /// Facility extrinsic for user to get taken from faucet @@ -1208,7 +1208,7 @@ mod dispatches { origin: OriginFor, identity: Option, ) -> DispatchResult { - Self::user_add_network_with_identity(origin, identity) + Self::user_add_network(origin, identity) } } } diff --git a/pallets/subtensor/tests/root.rs b/pallets/subtensor/tests/root.rs index 6a2904c870..caf1e5935d 100644 --- a/pallets/subtensor/tests/root.rs +++ b/pallets/subtensor/tests/root.rs @@ -1012,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_with_identity( + assert_ok!(SubtensorModule::user_add_network( RuntimeOrigin::signed(coldkey_1), Some(identity_value_1.clone()) )); @@ -1020,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_with_identity( + assert_ok!(SubtensorModule::user_add_network( RuntimeOrigin::signed(coldkey_2), Some(identity_value_2.clone()) ));