Skip to content

Commit cb03dd6

Browse files
committed
only allow top-stake SN owner hk to stay immune
1 parent ecf7f52 commit cb03dd6

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

pallets/subtensor/src/subnets/registration.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::*;
22
use sp_core::{H256, U256};
33
use sp_io::hashing::{keccak_256, sha2_256};
44
use sp_runtime::Saturating;
5+
use substrate_fixed::types::I64F64;
56
use system::pallet_prelude::BlockNumberFor;
67

78
const LOG_TARGET: &str = "runtime::subtensor::registration";
@@ -424,13 +425,32 @@ impl<T: Config> Pallet<T> {
424425
return 0; // If there are no neurons in this network.
425426
}
426427

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);
427431
for neuron_uid in 0..neurons_n {
428-
// Do not deregister the owner
429432
if let Ok(hotkey) = Self::get_hotkey_for_net_and_uid(netuid, neuron_uid) {
430433
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 {
432435
continue;
433436
}
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+
}
434454
}
435455

436456
let pruning_score: u16 = Self::get_pruning_score_for_uid(netuid, neuron_uid);

0 commit comments

Comments
 (0)