@@ -2,6 +2,7 @@ use super::*;
2
2
use sp_core:: { H256 , U256 } ;
3
3
use sp_io:: hashing:: { keccak_256, sha2_256} ;
4
4
use sp_runtime:: Saturating ;
5
+ use substrate_fixed:: types:: I64F64 ;
5
6
use system:: pallet_prelude:: BlockNumberFor ;
6
7
7
8
const LOG_TARGET : & str = "runtime::subtensor::registration" ;
@@ -424,13 +425,32 @@ impl<T: Config> Pallet<T> {
424
425
return 0 ; // If there are no neurons in this network.
425
426
}
426
427
428
+ // Get SN owner top stake hotkey
429
+ let mut top_stake_sn_owner_hotkey: Option < T :: AccountId > = None ;
430
+ let mut max_stake_weight: I64F64 = I64F64 :: from_num ( -1 ) ;
427
431
for neuron_uid in 0 ..neurons_n {
428
- // Do not deregister the owner
429
432
if let Ok ( hotkey) = Self :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) {
430
433
let coldkey = Self :: get_owning_coldkey_for_hotkey ( & hotkey) ;
431
- if Self :: get_subnet_owner ( netuid) = = coldkey {
434
+ if Self :: get_subnet_owner ( netuid) ! = coldkey {
432
435
continue ;
433
436
}
437
+
438
+ let stake_weights = Self :: get_stake_weights_for_hotkey_on_subnet ( & hotkey, netuid) ;
439
+ if stake_weights. 0 > max_stake_weight {
440
+ max_stake_weight = stake_weights. 0 ;
441
+ top_stake_sn_owner_hotkey = Some ( hotkey) ;
442
+ }
443
+ }
444
+ }
445
+
446
+ for neuron_uid in 0 ..neurons_n {
447
+ // Do not deregister the owner's top-stake hotkey
448
+ if let Ok ( hotkey) = Self :: get_hotkey_for_net_and_uid ( netuid, neuron_uid) {
449
+ if let Some ( ref top_sn_owner_hotkey) = top_stake_sn_owner_hotkey {
450
+ if top_sn_owner_hotkey == & hotkey {
451
+ continue ;
452
+ }
453
+ }
434
454
}
435
455
436
456
let pruning_score: u16 = Self :: get_pruning_score_for_uid ( netuid, neuron_uid) ;
0 commit comments