Skip to content

Commit 05f0631

Browse files
committed
add impl
1 parent 69e3a43 commit 05f0631

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,19 @@ impl<T: Config> Pallet<T> {
375375

376376
// Distribute mining incentives.
377377
for (hotkey, incentive) in incentives {
378-
// Increase stake for miner.
379378
log::debug!("incentives: hotkey: {:?}", incentive);
379+
380+
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
381+
if hotkey == owner_hotkey {
382+
log::debug!(
383+
"incentives: hotkey: {:?} is SN owner hotkey, skipping {:?}",
384+
hotkey,
385+
incentive
386+
);
387+
continue; // Skip/burn miner-emission for SN owner hotkey.
388+
}
389+
}
390+
// Increase stake for miner.
380391
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
381392
&hotkey.clone(),
382393
&Owner::<T>::get(hotkey.clone()),

pallets/subtensor/src/epoch/math.rs

+16
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,22 @@ pub fn mask_diag_sparse(sparse_matrix: &[Vec<(u16, I32F32)>]) -> Vec<Vec<(u16, I
604604
.collect()
605605
}
606606

607+
// Return a new sparse matrix with a masked out diagonal of input sparse matrix,
608+
// except for the diagonal entry at except_index.
609+
#[allow(dead_code)]
610+
pub fn mask_diag_sparse_except_index(
611+
sparse_matrix: &[Vec<(u16, I32F32)>],
612+
except_index: u16,
613+
) -> Vec<Vec<(u16, I32F32)>> {
614+
// Store the diagonal entry at except_index
615+
let diag_at_index = sparse_matrix[except_index as usize][except_index as usize].clone();
616+
// Mask out the diagonal
617+
let mut result = mask_diag_sparse(sparse_matrix);
618+
// Replace the diagonal entry at except_index
619+
result[except_index as usize][except_index as usize] = diag_at_index;
620+
result
621+
}
622+
607623
// Remove cells from sparse matrix where the mask function of two vectors is true.
608624
#[allow(dead_code, clippy::indexing_slicing)]
609625
pub fn vec_mask_sparse_matrix(

pallets/subtensor/src/epoch/run_epoch.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ impl<T: Config> Pallet<T> {
454454
// == Weights ==
455455
// =============
456456

457+
let owner_uid: Option<u16> = Self::get_owner_uid(netuid);
458+
457459
// Access network weights row unnormalized.
458460
let mut weights: Vec<Vec<(u16, I32F32)>> = Self::get_weights_sparse(netuid);
459461
log::trace!("Weights: {:?}", &weights);
@@ -462,8 +464,12 @@ impl<T: Config> Pallet<T> {
462464
weights = mask_rows_sparse(&validator_forbids, &weights);
463465
log::trace!("Weights (permit): {:?}", &weights);
464466

465-
// Remove self-weight by masking diagonal.
466-
weights = mask_diag_sparse(&weights);
467+
// Remove self-weight by masking diagonal; keep owner_uid self-weight.
468+
if let Some(owner_uid) = owner_uid {
469+
weights = mask_diag_sparse_except_index(&weights, owner_uid);
470+
} else {
471+
weights = mask_diag_sparse(&weights);
472+
}
467473
log::trace!("Weights (permit+diag): {:?}", &weights);
468474

469475
// Remove weights referring to deregistered neurons.

pallets/subtensor/src/utils/misc.rs

+10
Original file line numberDiff line numberDiff line change
@@ -733,4 +733,14 @@ impl<T: Config> Pallet<T> {
733733
SubnetOwnerHotkey::<T>::insert(netuid, hotkey.clone());
734734
Self::deposit_event(Event::SubnetOwnerHotkeySet(netuid, hotkey.clone()));
735735
}
736+
737+
// Get the uid of the Owner Hotkey for a subnet.
738+
pub fn get_owner_uid(netuid: u16) -> Option<u16> {
739+
let owner_hotkey = SubnetOwnerHotkey::<T>::get(netuid);
740+
if Uids::<T>::contains_key(netuid, &owner_hotkey) {
741+
Some(Uids::<T>::get(netuid, &owner_hotkey))
742+
} else {
743+
None
744+
}
745+
}
736746
}

0 commit comments

Comments
 (0)