@@ -891,100 +891,6 @@ impl<T: Config> Pallet<T> {
891891 . into ( ) )
892892 }
893893
894- /// Facilitates user registration of a new subnetwork.
895- ///
896- /// # Args:
897- /// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed.
898- ///
899- /// # Events:
900- /// * `NetworkAdded(netuid, modality)`: Emitted when a new network is successfully added.
901- /// * `NetworkRemoved(netuid)`: Emitted when an existing network is removed to make room for the new one.
902- ///
903- /// # Raises:
904- /// * 'TxRateLimitExceeded': If the rate limit for network registration is exceeded.
905- /// * 'NotEnoughBalanceToStake': If there isn't enough balance to stake for network registration.
906- /// * 'BalanceWithdrawalError': If an error occurs during balance withdrawal for network registration.
907- ///
908- pub fn user_add_network ( origin : T :: RuntimeOrigin ) -> dispatch:: DispatchResult {
909- // --- 0. Ensure the caller is a signed user.
910- let coldkey = ensure_signed ( origin) ?;
911-
912- // --- 1. Rate limit for network registrations.
913- let current_block = Self :: get_current_block_as_u64 ( ) ;
914- let last_lock_block = Self :: get_network_last_lock_block ( ) ;
915- ensure ! (
916- current_block. saturating_sub( last_lock_block) >= NetworkRateLimit :: <T >:: get( ) ,
917- Error :: <T >:: NetworkTxRateLimitExceeded
918- ) ;
919-
920- // --- 2. Calculate and lock the required tokens.
921- let lock_amount: u64 = Self :: get_network_lock_cost ( ) ;
922- log:: debug!( "network lock_amount: {:?}" , lock_amount) ;
923- ensure ! (
924- Self :: can_remove_balance_from_coldkey_account( & coldkey, lock_amount) ,
925- Error :: <T >:: NotEnoughBalanceToStake
926- ) ;
927-
928- // --- 4. Determine the netuid to register.
929- let netuid_to_register: u16 = {
930- log:: debug!(
931- "subnet count: {:?}\n max subnets: {:?}" ,
932- Self :: get_num_subnets( ) ,
933- Self :: get_max_subnets( )
934- ) ;
935- if Self :: get_num_subnets ( ) . saturating_sub ( 1 ) < Self :: get_max_subnets ( ) {
936- // We subtract one because we don't want root subnet to count towards total
937- let mut next_available_netuid = 0 ;
938- loop {
939- next_available_netuid. saturating_inc ( ) ;
940- if !Self :: if_subnet_exist ( next_available_netuid) {
941- log:: debug!( "got subnet id: {:?}" , next_available_netuid) ;
942- break next_available_netuid;
943- }
944- }
945- } else {
946- let netuid_to_prune = Self :: get_subnet_to_prune ( ) ;
947- ensure ! ( netuid_to_prune > 0 , Error :: <T >:: AllNetworksInImmunity ) ;
948-
949- Self :: remove_network ( netuid_to_prune) ;
950- log:: debug!( "remove_network: {:?}" , netuid_to_prune, ) ;
951- Self :: deposit_event ( Event :: NetworkRemoved ( netuid_to_prune) ) ;
952-
953- if SubnetIdentities :: < T > :: take ( netuid_to_prune) . is_some ( ) {
954- Self :: deposit_event ( Event :: SubnetIdentityRemoved ( netuid_to_prune) ) ;
955- }
956-
957- netuid_to_prune
958- }
959- } ;
960-
961- // --- 5. Perform the lock operation.
962- let actual_lock_amount = Self :: remove_balance_from_coldkey_account ( & coldkey, lock_amount) ?;
963- Self :: set_subnet_locked_balance ( netuid_to_register, actual_lock_amount) ;
964- Self :: set_network_last_lock ( actual_lock_amount) ;
965-
966- // --- 6. Set initial and custom parameters for the network.
967- Self :: init_new_network ( netuid_to_register, 360 ) ;
968- log:: debug!( "init_new_network: {:?}" , netuid_to_register, ) ;
969-
970- // --- 7. Set netuid storage.
971- let current_block_number: u64 = Self :: get_current_block_as_u64 ( ) ;
972- NetworkLastRegistered :: < T > :: set ( current_block_number) ;
973- NetworkRegisteredAt :: < T > :: insert ( netuid_to_register, current_block_number) ;
974- SubnetOwner :: < T > :: insert ( netuid_to_register, coldkey) ;
975-
976- // --- 8. Emit the NetworkAdded event.
977- log:: debug!(
978- "NetworkAdded( netuid:{:?}, modality:{:?} )" ,
979- netuid_to_register,
980- 0
981- ) ;
982- Self :: deposit_event ( Event :: NetworkAdded ( netuid_to_register, 0 ) ) ;
983-
984- // --- 9. Return success.
985- Ok ( ( ) )
986- }
987-
988894 /// Facilitates user registration of a new subnetwork with subnet identity.
989895 ///
990896 /// # Args:
@@ -1229,12 +1135,6 @@ impl<T: Config> Pallet<T> {
12291135 /// # Note:
12301136 /// This function does not emit any events, nor does it raise any errors. It silently
12311137 /// returns if any internal checks fail.
1232- ///
1233- /// # Example:
1234- /// ```rust
1235- /// let netuid_to_remove: u16 = 5;
1236- /// Pallet::<T>::remove_network(netuid_to_remove);
1237- /// ```
12381138 pub fn remove_network ( netuid : u16 ) {
12391139 // --- 1. Return balance to subnet owner.
12401140 let owner_coldkey: T :: AccountId = SubnetOwner :: < T > :: get ( netuid) ;
0 commit comments