Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 98 additions & 171 deletions contract-tests/yarn.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,4 +1666,23 @@ mod pallet_benchmarks {
#[extrinsic_call]
_(RawOrigin::Root, netuid, 100);
}

#[benchmark]
fn sudo_set_emission_suppression_override() {
let coldkey: T::AccountId = whitelisted_caller();
let hotkey: T::AccountId = account("A", 0, 1);

let netuid = Subtensor::<T>::get_next_netuid();

let lock_cost = Subtensor::<T>::get_network_lock_cost();
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, lock_cost.into());

assert_ok!(Subtensor::<T>::register_network(
RawOrigin::Signed(coldkey.clone()).into(),
hotkey.clone()
));

#[extrinsic_call]
_(RawOrigin::Root, netuid, Some(true));
}
}
3 changes: 3 additions & 0 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ impl<T: Config> Pallet<T> {
SubnetEmaTaoFlow::<T>::remove(netuid);
SubnetTaoProvided::<T>::remove(netuid);

// --- 12b. Emission suppression.
EmissionSuppressionOverride::<T>::remove(netuid);

// --- 13. Token / mechanism / registration toggles.
TokenSymbol::<T>::remove(netuid);
SubnetMechanism::<T>::remove(netuid);
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<T: Config> Pallet<T> {
});

if root_sell_flag {
// Only accumulate root alpha divs if root sell is allowed.
// Accumulate root alpha divs for root validators.
PendingRootAlphaDivs::<T>::mutate(*netuid_i, |total| {
*total = total.saturating_add(tou64!(root_alpha).into());
});
Expand Down
32 changes: 28 additions & 4 deletions pallets/subtensor/src/coinbase/subnet_emissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,34 @@ impl<T: Config> Pallet<T> {
subnets_to_emit_to: &[NetUid],
block_emission: U96F32,
) -> BTreeMap<NetUid, U96F32> {
// Get subnet TAO emissions.
let shares = Self::get_shares(subnets_to_emit_to);
// Filter out suppressed subnets before computing shares so they never
// enter the share calculation and remaining subnets naturally split the
// full emission without a separate zero-and-renormalize step.
let active: Vec<NetUid> = subnets_to_emit_to
.iter()
.filter(|netuid| !Self::is_subnet_emission_suppressed(**netuid))
.copied()
.collect();
let shares = Self::get_shares(&active);
log::debug!("Subnet emission shares = {shares:?}");

shares
let mut emissions: BTreeMap<NetUid, U96F32> = shares
.into_iter()
.map(|(netuid, share)| {
let emission = U64F64::saturating_from_num(block_emission).saturating_mul(share);
(netuid, U96F32::saturating_from_num(emission))
})
.collect::<BTreeMap<NetUid, U96F32>>()
.collect();

// Add suppressed subnets back with zero TAO emission so they still
// appear in the emission map. This is required because emit_to_subnets
// uses the map to drive alpha issuance (which continues independently
// of TAO suppression).
for netuid in subnets_to_emit_to {
emissions.entry(*netuid).or_insert(U96F32::from_num(0));
}

emissions
}

pub fn record_tao_inflow(netuid: NetUid, tao: TaoCurrency) {
Expand Down Expand Up @@ -246,4 +263,11 @@ impl<T: Config> Pallet<T> {
})
.collect::<BTreeMap<NetUid, U64F64>>()
}

/// Check if a subnet is currently emission-suppressed via the root override.
/// Returns true only for `Some(true)`. `Some(false)` and `None` both yield
/// false (not suppressed).
pub(crate) fn is_subnet_emission_suppressed(netuid: NetUid) -> bool {
matches!(EmissionSuppressionOverride::<T>::get(netuid), Some(true))
}
}
9 changes: 9 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,15 @@ pub mod pallet {
pub type PendingChildKeyCooldown<T: Config> =
StorageValue<_, u64, ValueQuery, DefaultPendingChildKeyCooldown<T>>;

/// Root override for emission suppression per subnet.
/// Some(true) = force suppressed; None or Some(false) = not suppressed.
/// Some(false) is functionally identical to None today and is reserved for
/// future use (e.g. an automatic suppression mechanism whose effect
/// Some(false) could explicitly override).
#[pallet::storage]
pub type EmissionSuppressionOverride<T: Config> =
StorageMap<_, Identity, NetUid, bool, OptionQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
/// Stakes record in genesis.
Expand Down
31 changes: 31 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2416,5 +2416,36 @@ mod dispatches {

Ok(())
}

/// --- Set or clear the root override for emission suppression on a subnet.
/// Some(true) forces suppression. None removes the override (subnet is not
/// suppressed). Some(false) is accepted and stored but is currently
/// functionally identical to None; it is reserved for future use.
#[pallet::call_index(133)]
#[pallet::weight((
Weight::from_parts(5_000_000, 0)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1)),
DispatchClass::Operational,
Pays::No
))]
pub fn sudo_set_emission_suppression_override(
origin: OriginFor<T>,
netuid: NetUid,
override_value: Option<bool>,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(Self::if_subnet_exist(netuid), Error::<T>::SubnetNotExists);
ensure!(!netuid.is_root(), Error::<T>::CannotSuppressRootSubnet);
match override_value {
Some(val) => EmissionSuppressionOverride::<T>::insert(netuid, val),
None => EmissionSuppressionOverride::<T>::remove(netuid),
}
Self::deposit_event(Event::EmissionSuppressionOverrideSet {
netuid,
override_value,
});
Ok(())
}
}
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,7 @@ mod errors {
InvalidSubnetNumber,
/// Unintended precision loss when unstaking alpha
PrecisionLoss,
/// Cannot set emission suppression override for the root subnet.
CannotSuppressRootSubnet,
}
}
9 changes: 9 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,14 @@ mod events {
/// The amount of alpha distributed
alpha: AlphaCurrency,
},

/// Root set or cleared the emission suppression override for a subnet.
EmissionSuppressionOverrideSet {
/// The subnet affected
netuid: NetUid,
/// The override value: Some(true) = force suppress, None = cleared/not suppressed,
/// Some(false) = stored but currently identical to None (reserved for future use)
override_value: Option<bool>,
},
}
}
Loading
Loading