@@ -894,17 +894,24 @@ impl<T: Config> Pallet<T> {
894894 /// Facilitates user registration of a new subnetwork.
895895 ///
896896 /// # Args:
897- /// * 'origin': ('T::RuntimeOrigin'): The calling origin. Must be signed.
897+ /// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed.
898+ /// * `identity` (`Option<SubnetIdentityOf>`): Optional identity to be associated with the new subnetwork.
898899 ///
899- /// # Event:
900- /// * 'NetworkAdded': Emitted when a new network is successfully added.
900+ /// # Events:
901+ /// * `NetworkAdded(netuid, modality)`: Emitted when a new network is successfully added.
902+ /// * `SubnetIdentitySet(netuid)`: Emitted when a custom identity is set for a new subnetwork.
903+ /// * `NetworkRemoved(netuid)`: Emitted when an existing network is removed to make room for the new one.
904+ /// * `SubnetIdentityRemoved(netuid)`: Emitted when the identity of a removed network is also deleted.
901905 ///
902906 /// # Raises:
903907 /// * 'TxRateLimitExceeded': If the rate limit for network registration is exceeded.
904908 /// * 'NotEnoughBalanceToStake': If there isn't enough balance to stake for network registration.
905909 /// * 'BalanceWithdrawalError': If an error occurs during balance withdrawal for network registration.
906910 ///
907- pub fn user_add_network ( origin : T :: RuntimeOrigin ) -> dispatch:: DispatchResult {
911+ pub fn user_add_network (
912+ origin : T :: RuntimeOrigin ,
913+ identity : Option < SubnetIdentityOf > ,
914+ ) -> dispatch:: DispatchResult {
908915 // --- 0. Ensure the caller is a signed user.
909916 let coldkey = ensure_signed ( origin) ?;
910917
@@ -948,6 +955,11 @@ impl<T: Config> Pallet<T> {
948955 Self :: remove_network ( netuid_to_prune) ;
949956 log:: debug!( "remove_network: {:?}" , netuid_to_prune, ) ;
950957 Self :: deposit_event ( Event :: NetworkRemoved ( netuid_to_prune) ) ;
958+
959+ if SubnetIdentities :: < T > :: take ( netuid_to_prune) . is_some ( ) {
960+ Self :: deposit_event ( Event :: SubnetIdentityRemoved ( netuid_to_prune) ) ;
961+ }
962+
951963 netuid_to_prune
952964 }
953965 } ;
@@ -961,21 +973,32 @@ impl<T: Config> Pallet<T> {
961973 Self :: init_new_network ( netuid_to_register, 360 ) ;
962974 log:: debug!( "init_new_network: {:?}" , netuid_to_register, ) ;
963975
964- // --- 7. Set netuid storage.
976+ // --- 7. Add the identity if it exists
977+ if let Some ( identity_value) = identity {
978+ ensure ! (
979+ Self :: is_valid_subnet_identity( & identity_value) ,
980+ Error :: <T >:: InvalidIdentity
981+ ) ;
982+
983+ SubnetIdentities :: < T > :: insert ( netuid_to_register, identity_value) ;
984+ Self :: deposit_event ( Event :: SubnetIdentitySet ( netuid_to_register) ) ;
985+ }
986+
987+ // --- 8. Set netuid storage.
965988 let current_block_number: u64 = Self :: get_current_block_as_u64 ( ) ;
966989 NetworkLastRegistered :: < T > :: set ( current_block_number) ;
967990 NetworkRegisteredAt :: < T > :: insert ( netuid_to_register, current_block_number) ;
968991 SubnetOwner :: < T > :: insert ( netuid_to_register, coldkey) ;
969992
970- // --- 8 . Emit the NetworkAdded event.
993+ // --- 9 . Emit the NetworkAdded event.
971994 log:: debug!(
972995 "NetworkAdded( netuid:{:?}, modality:{:?} )" ,
973996 netuid_to_register,
974997 0
975998 ) ;
976999 Self :: deposit_event ( Event :: NetworkAdded ( netuid_to_register, 0 ) ) ;
9771000
978- // --- 9 . Return success.
1001+ // --- 10 . Return success.
9791002 Ok ( ( ) )
9801003 }
9811004
@@ -1005,14 +1028,19 @@ impl<T: Config> Pallet<T> {
10051028 Error :: <T >:: NotSubnetOwner
10061029 ) ;
10071030
1008- // --- 2. Explicitly erase the network and all its parameters.
1031+ // --- 4. Remove the subnet identity if it exists.
1032+ if SubnetIdentities :: < T > :: take ( netuid) . is_some ( ) {
1033+ Self :: deposit_event ( Event :: SubnetIdentityRemoved ( netuid) ) ;
1034+ }
1035+
1036+ // --- 5. Explicitly erase the network and all its parameters.
10091037 Self :: remove_network ( netuid) ;
10101038
1011- // --- 3 . Emit the NetworkRemoved event.
1039+ // --- 6 . Emit the NetworkRemoved event.
10121040 log:: debug!( "NetworkRemoved( netuid:{:?} )" , netuid) ;
10131041 Self :: deposit_event ( Event :: NetworkRemoved ( netuid) ) ;
10141042
1015- // --- 5 . Return success.
1043+ // --- 7 . Return success.
10161044 Ok ( ( ) )
10171045 }
10181046
0 commit comments