From 704dc96e113a1f158dfdd36bb7a23c2a17d791f8 Mon Sep 17 00:00:00 2001
From: Pawel Polewicz
Date: Wed, 25 Feb 2026 18:46:54 +0000
Subject: [PATCH 1/7] Add override-only emission suppression
Port emission suppression from emission_suppression branch with only
root-level override functionality (no EmissionSuppression vote map,
no EmissionSuppressionVote, no vote_emission_suppression extrinsic).
Includes:
- EmissionSuppressionOverride storage (root sets per-subnet)
- KeepRootSellPressureOnSuppressedSubnets (Disable/Enable/Recycle modes)
- sudo_set_emission_suppression_override extrinsic (call_index 133)
- sudo_set_root_sell_pressure_on_suppressed_subnets_mode (call_index 135)
- Suppressed subnets get zero emission share with renormalization
- Root alpha handling: Disable recycles to validators, Recycle swaps+burns
- Subnet dissolution cleanup
- 18 override-only tests
---
pallets/subtensor/src/coinbase/root.rs | 3 +
.../subtensor/src/coinbase/run_coinbase.rs | 39 +-
.../src/coinbase/subnet_emissions.rs | 39 +-
pallets/subtensor/src/lib.rs | 32 +
pallets/subtensor/src/macros/dispatches.rs | 51 ++
pallets/subtensor/src/macros/errors.rs | 2 +
pallets/subtensor/src/macros/events.rs | 14 +
.../src/tests/emission_suppression.rs | 858 ++++++++++++++++++
pallets/subtensor/src/tests/mod.rs | 1 +
9 files changed, 1034 insertions(+), 5 deletions(-)
create mode 100644 pallets/subtensor/src/tests/emission_suppression.rs
diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs
index 83567b6f57..3d356471d5 100644
--- a/pallets/subtensor/src/coinbase/root.rs
+++ b/pallets/subtensor/src/coinbase/root.rs
@@ -302,6 +302,9 @@ impl Pallet {
SubnetEmaTaoFlow::::remove(netuid);
SubnetTaoProvided::::remove(netuid);
+ // --- 12b. Emission suppression.
+ EmissionSuppressionOverride::::remove(netuid);
+
// --- 13. Token / mechanism / registration toggles.
TokenSymbol::::remove(netuid);
SubnetMechanism::::remove(netuid);
diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs
index 2091946598..bad9712e1e 100644
--- a/pallets/subtensor/src/coinbase/run_coinbase.rs
+++ b/pallets/subtensor/src/coinbase/run_coinbase.rs
@@ -183,6 +183,7 @@ impl Pallet {
// --- 3. Inject ALPHA for participants.
let cut_percent: U96F32 = Self::get_float_subnet_owner_cut();
+ let root_sell_pressure_mode = KeepRootSellPressureOnSuppressedSubnets::::get();
for netuid_i in subnets_to_emit_to.iter() {
// Get alpha_out for this block.
@@ -208,6 +209,9 @@ impl Pallet {
let root_proportion = Self::root_proportion(*netuid_i);
log::debug!("root_proportion: {root_proportion:?}");
+ // Check if subnet emission is suppressed (compute once to avoid double storage read).
+ let is_suppressed = Self::is_subnet_emission_suppressed(*netuid_i);
+
// Get root alpha from root prop.
let root_alpha: U96F32 = root_proportion
.saturating_mul(alpha_out_i) // Total alpha emission per block remaining.
@@ -235,10 +239,37 @@ impl Pallet {
});
if root_sell_flag {
- // Only accumulate root alpha divs if root sell is allowed.
- PendingRootAlphaDivs::::mutate(*netuid_i, |total| {
- *total = total.saturating_add(tou64!(root_alpha).into());
- });
+ // Determine disposition of root alpha based on suppression mode.
+ if is_suppressed
+ && root_sell_pressure_mode == RootSellPressureOnSuppressedSubnetsMode::Disable
+ {
+ // Disable mode: recycle root alpha back to subnet validators.
+ PendingValidatorEmission::::mutate(*netuid_i, |total| {
+ *total = total.saturating_add(tou64!(root_alpha).into());
+ });
+ } else if is_suppressed
+ && root_sell_pressure_mode == RootSellPressureOnSuppressedSubnetsMode::Recycle
+ {
+ // Recycle mode: swap alpha → TAO via AMM, then burn the TAO.
+ let root_alpha_currency = AlphaCurrency::from(tou64!(root_alpha));
+ if let Ok(swap_result) = Self::swap_alpha_for_tao(
+ *netuid_i,
+ root_alpha_currency,
+ TaoCurrency::ZERO, // no price limit
+ true, // drop fees
+ ) {
+ Self::record_tao_outflow(*netuid_i, swap_result.amount_paid_out);
+ Self::recycle_tao(swap_result.amount_paid_out);
+ } else {
+ // Swap failed: recycle alpha back to subnet to prevent loss.
+ Self::recycle_subnet_alpha(*netuid_i, root_alpha_currency);
+ }
+ } else {
+ // Enable mode (or non-suppressed subnet): accumulate for root validators.
+ PendingRootAlphaDivs::::mutate(*netuid_i, |total| {
+ *total = total.saturating_add(tou64!(root_alpha).into());
+ });
+ }
} else {
// If we are not selling the root alpha, we should recycle it.
Self::recycle_subnet_alpha(*netuid_i, AlphaCurrency::from(tou64!(root_alpha)));
diff --git a/pallets/subtensor/src/coinbase/subnet_emissions.rs b/pallets/subtensor/src/coinbase/subnet_emissions.rs
index 477a678864..be766baf00 100644
--- a/pallets/subtensor/src/coinbase/subnet_emissions.rs
+++ b/pallets/subtensor/src/coinbase/subnet_emissions.rs
@@ -27,7 +27,8 @@ impl Pallet {
block_emission: U96F32,
) -> BTreeMap {
// Get subnet TAO emissions.
- let shares = Self::get_shares(subnets_to_emit_to);
+ let mut shares = Self::get_shares(subnets_to_emit_to);
+ Self::apply_emission_suppression(&mut shares);
log::debug!("Subnet emission shares = {shares:?}");
shares
@@ -246,4 +247,40 @@ impl Pallet {
})
.collect::>()
}
+
+ /// Normalize shares so they sum to 1.0.
+ pub(crate) fn normalize_shares(shares: &mut BTreeMap) {
+ let sum: U64F64 = shares
+ .values()
+ .copied()
+ .fold(U64F64::saturating_from_num(0), |acc, v| {
+ acc.saturating_add(v)
+ });
+ if sum > U64F64::saturating_from_num(0) {
+ for s in shares.values_mut() {
+ *s = s.safe_div(sum);
+ }
+ }
+ }
+
+ /// Check if a subnet is currently emission-suppressed via the root override.
+ pub(crate) fn is_subnet_emission_suppressed(netuid: NetUid) -> bool {
+ matches!(EmissionSuppressionOverride::::get(netuid), Some(true))
+ }
+
+ /// Zero the emission share of any subnet that is force-suppressed via override,
+ /// then re-normalize the remaining shares.
+ pub(crate) fn apply_emission_suppression(shares: &mut BTreeMap) {
+ let zero = U64F64::saturating_from_num(0);
+ let mut any_zeroed = false;
+ for (netuid, share) in shares.iter_mut() {
+ if Self::is_subnet_emission_suppressed(*netuid) {
+ *share = zero;
+ any_zeroed = true;
+ }
+ }
+ if any_zeroed {
+ Self::normalize_shares(shares);
+ }
+ }
}
diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs
index 6ae43ac384..ca81249d5c 100644
--- a/pallets/subtensor/src/lib.rs
+++ b/pallets/subtensor/src/lib.rs
@@ -341,6 +341,23 @@ pub mod pallet {
},
}
+ /// Controls how root alpha dividends are handled on emission-suppressed subnets.
+ #[derive(
+ Encode, Decode, Default, TypeInfo, Clone, Copy, PartialEq, Eq, Debug, DecodeWithMemTracking,
+ )]
+ pub enum RootSellPressureOnSuppressedSubnetsMode {
+ /// Root gets no alpha on suppressed subnets; root alpha recycled to subnet validators.
+ #[codec(index = 0)]
+ Disable,
+ /// Root still accumulates alpha on suppressed subnets (old `true`).
+ #[codec(index = 1)]
+ Enable,
+ /// Root alpha is swapped to TAO via AMM and the TAO is burned.
+ #[default]
+ #[codec(index = 2)]
+ Recycle,
+ }
+
/// Default minimum root claim amount.
/// This is the minimum amount of root claim that can be made.
/// Any amount less than this will not be claimed.
@@ -2375,6 +2392,21 @@ pub mod pallet {
pub type PendingChildKeyCooldown =
StorageValue<_, u64, ValueQuery, DefaultPendingChildKeyCooldown>;
+ /// Root override for emission suppression per subnet.
+ /// Some(true) = force suppressed, Some(false) = force unsuppressed,
+ /// None = not overridden (subnet is not suppressed).
+ #[pallet::storage]
+ pub type EmissionSuppressionOverride =
+ StorageMap<_, Identity, NetUid, bool, OptionQuery>;
+
+ /// Controls how root alpha dividends are handled on emission-suppressed subnets.
+ /// - Disable (0x00): root gets no alpha; root alpha recycled to subnet validators.
+ /// - Enable (0x01): root still accumulates alpha (old behaviour).
+ /// - Recycle (0x02, default): root alpha swapped to TAO and TAO burned.
+ #[pallet::storage]
+ pub type KeepRootSellPressureOnSuppressedSubnets =
+ StorageValue<_, RootSellPressureOnSuppressedSubnetsMode, ValueQuery>;
+
#[pallet::genesis_config]
pub struct GenesisConfig {
/// Stakes record in genesis.
diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs
index 5c5d5ed1a7..4b1bbf7dae 100644
--- a/pallets/subtensor/src/macros/dispatches.rs
+++ b/pallets/subtensor/src/macros/dispatches.rs
@@ -2416,5 +2416,56 @@ mod dispatches {
Ok(())
}
+
+ /// --- Set or clear the root override for emission suppression on a subnet.
+ /// Some(true) forces suppression, Some(false) forces unsuppression,
+ /// None removes the override (subnet is not suppressed).
+ #[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,
+ netuid: NetUid,
+ override_value: Option,
+ ) -> DispatchResult {
+ ensure_root(origin)?;
+ ensure!(Self::if_subnet_exist(netuid), Error::::SubnetNotExists);
+ ensure!(!netuid.is_root(), Error::::CannotVoteOnRootSubnet);
+ match override_value {
+ Some(val) => EmissionSuppressionOverride::::insert(netuid, val),
+ None => EmissionSuppressionOverride::::remove(netuid),
+ }
+ Self::deposit_event(Event::EmissionSuppressionOverrideSet {
+ netuid,
+ override_value,
+ });
+ Ok(())
+ }
+
+ /// --- Set the mode for root alpha dividends on emission-suppressed subnets.
+ /// - Disable: root gets no alpha; root alpha recycled to subnet validators.
+ /// - Enable: root still accumulates alpha (old behaviour).
+ /// - Recycle: root alpha swapped to TAO via AMM, TAO burned.
+ #[pallet::call_index(135)]
+ #[pallet::weight((
+ Weight::from_parts(5_000_000, 0)
+ .saturating_add(T::DbWeight::get().writes(1)),
+ DispatchClass::Operational,
+ Pays::No
+ ))]
+ pub fn sudo_set_root_sell_pressure_on_suppressed_subnets_mode(
+ origin: OriginFor,
+ mode: RootSellPressureOnSuppressedSubnetsMode,
+ ) -> DispatchResult {
+ ensure_root(origin)?;
+ KeepRootSellPressureOnSuppressedSubnets::::put(mode);
+ Self::deposit_event(Event::RootSellPressureOnSuppressedSubnetsModeSet { mode });
+ Ok(())
+ }
}
}
diff --git a/pallets/subtensor/src/macros/errors.rs b/pallets/subtensor/src/macros/errors.rs
index 6c3d7a35df..26d3ce0da6 100644
--- a/pallets/subtensor/src/macros/errors.rs
+++ b/pallets/subtensor/src/macros/errors.rs
@@ -268,5 +268,7 @@ mod errors {
InvalidSubnetNumber,
/// Unintended precision loss when unstaking alpha
PrecisionLoss,
+ /// Cannot vote on emission suppression for the root subnet.
+ CannotVoteOnRootSubnet,
}
}
diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs
index c86cc1a1e5..21398dd547 100644
--- a/pallets/subtensor/src/macros/events.rs
+++ b/pallets/subtensor/src/macros/events.rs
@@ -481,5 +481,19 @@ 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, Some(false) = force unsuppress, None = cleared
+ override_value: Option,
+ },
+
+ /// Root set the RootSellPressureOnSuppressedSubnetsModeSet.
+ RootSellPressureOnSuppressedSubnetsModeSet {
+ /// The new mode
+ mode: RootSellPressureOnSuppressedSubnetsMode,
+ },
}
}
diff --git a/pallets/subtensor/src/tests/emission_suppression.rs b/pallets/subtensor/src/tests/emission_suppression.rs
new file mode 100644
index 0000000000..d20b396927
--- /dev/null
+++ b/pallets/subtensor/src/tests/emission_suppression.rs
@@ -0,0 +1,858 @@
+#![allow(clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]
+use super::mock::*;
+use crate::*;
+use alloc::collections::BTreeMap;
+use frame_support::assert_ok;
+use sp_core::U256;
+use substrate_fixed::types::{U64F64, U96F32};
+use subtensor_runtime_common::{AlphaCurrency, NetUid, TaoCurrency};
+
+/// Helper: create a non-root subnet with TAO flow so it gets shares.
+fn setup_subnet_with_flow(netuid: NetUid, tempo: u16, tao_flow: i64) {
+ add_network(netuid, tempo, 0);
+ SubnetTaoFlow::::insert(netuid, tao_flow);
+}
+
+/// Helper: seed root + subnet TAO/alpha so root_proportion is nonzero.
+fn setup_root_with_tao(sn: NetUid) {
+ // Set SubnetTAO for root so root_proportion numerator is nonzero.
+ SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000));
+ // Set alpha issuance for subnet so denominator is meaningful.
+ SubnetAlphaOut::::insert(sn, AlphaCurrency::from(1_000_000_000));
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 1: Override force suppress → share=0, rest renormalized
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_override_force_suppress() {
+ new_test_ext(1).execute_with(|| {
+ let sn1 = NetUid::from(1);
+ let sn2 = NetUid::from(2);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+ setup_subnet_with_flow(sn2, 10, 100_000_000);
+
+ // Override forces suppression.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ let mut shares = SubtensorModule::get_shares(&[sn1, sn2]);
+ SubtensorModule::apply_emission_suppression(&mut shares);
+
+ assert_eq!(
+ shares.get(&sn1).copied().unwrap_or(U64F64::from_num(0)),
+ U64F64::from_num(0)
+ );
+ let sn2_share = shares.get(&sn2).copied().unwrap_or(U64F64::from_num(0));
+ assert!(
+ sn2_share > U64F64::from_num(0.99),
+ "sn2 share should be ~1.0, got {sn2_share:?}"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 2: Override=Some(false) → not suppressed
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_override_force_unsuppress() {
+ new_test_ext(1).execute_with(|| {
+ let sn1 = NetUid::from(1);
+ let sn2 = NetUid::from(2);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+ setup_subnet_with_flow(sn2, 10, 100_000_000);
+
+ // Override forces unsuppression.
+ EmissionSuppressionOverride::::insert(sn1, false);
+
+ let mut shares = SubtensorModule::get_shares(&[sn1, sn2]);
+ let shares_before = shares.clone();
+ SubtensorModule::apply_emission_suppression(&mut shares);
+
+ // Shares should be unchanged (not suppressed).
+ assert_eq!(shares, shares_before);
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 3: No override → not suppressed (default)
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_no_override_not_suppressed() {
+ new_test_ext(1).execute_with(|| {
+ let sn1 = NetUid::from(1);
+ let sn2 = NetUid::from(2);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+ setup_subnet_with_flow(sn2, 10, 100_000_000);
+
+ // No override at all — default is not suppressed.
+ let mut shares = SubtensorModule::get_shares(&[sn1, sn2]);
+ let shares_before = shares.clone();
+ SubtensorModule::apply_emission_suppression(&mut shares);
+
+ // Shares should be unchanged.
+ assert_eq!(shares, shares_before);
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 4: Dissolution clears override
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_dissolution_clears_override() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ // Remove the network.
+ SubtensorModule::remove_network(sn1);
+
+ // Override should be cleaned up.
+ assert_eq!(EmissionSuppressionOverride::::get(sn1), None);
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 5: 3 subnets, suppress 1 → others sum to 1.0
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_shares_renormalize() {
+ new_test_ext(1).execute_with(|| {
+ let sn1 = NetUid::from(1);
+ let sn2 = NetUid::from(2);
+ let sn3 = NetUid::from(3);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+ setup_subnet_with_flow(sn2, 10, 200_000_000);
+ setup_subnet_with_flow(sn3, 10, 300_000_000);
+
+ // Suppress sn2 via override.
+ EmissionSuppressionOverride::::insert(sn2, true);
+
+ let mut shares = SubtensorModule::get_shares(&[sn1, sn2, sn3]);
+ SubtensorModule::apply_emission_suppression(&mut shares);
+
+ // sn2 should be 0.
+ assert_eq!(
+ shares.get(&sn2).copied().unwrap_or(U64F64::from_num(0)),
+ U64F64::from_num(0)
+ );
+
+ // Remaining shares should sum to ~1.0.
+ let sum: U64F64 = shares
+ .values()
+ .copied()
+ .fold(U64F64::from_num(0), |a, b| a.saturating_add(b));
+ let sum_f64: f64 = sum.to_num();
+ assert!(
+ (sum_f64 - 1.0).abs() < 1e-9,
+ "remaining shares should sum to ~1.0, got {sum_f64}"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 6: All subnets suppressed → all shares 0, zero emissions
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_all_subnets_suppressed() {
+ new_test_ext(1).execute_with(|| {
+ let sn1 = NetUid::from(1);
+ let sn2 = NetUid::from(2);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+ setup_subnet_with_flow(sn2, 10, 100_000_000);
+
+ // Suppress both via override.
+ EmissionSuppressionOverride::::insert(sn1, true);
+ EmissionSuppressionOverride::::insert(sn2, true);
+
+ let mut shares = SubtensorModule::get_shares(&[sn1, sn2]);
+ SubtensorModule::apply_emission_suppression(&mut shares);
+
+ // Both should be zero.
+ let s1 = shares.get(&sn1).copied().unwrap_or(U64F64::from_num(0));
+ let s2 = shares.get(&sn2).copied().unwrap_or(U64F64::from_num(0));
+ assert_eq!(s1, U64F64::from_num(0));
+ assert_eq!(s2, U64F64::from_num(0));
+
+ // Total emission via get_subnet_block_emissions should be zero.
+ let emissions =
+ SubtensorModule::get_subnet_block_emissions(&[sn1, sn2], U96F32::from_num(1_000_000));
+ let total: u64 = emissions
+ .values()
+ .map(|e| e.saturating_to_num::())
+ .fold(0u64, |a, b| a.saturating_add(b));
+ assert_eq!(total, 0, "all-suppressed should yield zero total emission");
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 7: Suppress subnet, Enable mode → root still gets alpha
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_suppressed_subnet_root_alpha_by_default() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ // Register a root validator and add stake on root so root_proportion > 0.
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ // Set TAO weight so root_proportion is nonzero.
+ SubtensorModule::set_tao_weight(u64::MAX);
+ setup_root_with_tao(sn1);
+
+ // Force-suppress sn1.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ // Default mode is Recycle; verify that, then set to Enable for this test.
+ assert_eq!(
+ KeepRootSellPressureOnSuppressedSubnets::::get(),
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
+ );
+
+ // Clear any pending emissions.
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+
+ // Build emission map with some emission for sn1.
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // Root should have received some alpha (pending root alpha divs > 0).
+ let pending_root = PendingRootAlphaDivs::::get(sn1);
+ assert!(
+ pending_root > AlphaCurrency::ZERO,
+ "with Enable mode, root should still get alpha on suppressed subnet"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 8: Suppress subnet, Disable mode → root gets no alpha, validators get more
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_suppressed_subnet_no_root_alpha_flag_off() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ // Register a root validator and add stake on root so root_proportion > 0.
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+ setup_root_with_tao(sn1);
+
+ // Force-suppress sn1.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ // Set mode to Disable: no root sell pressure on suppressed subnets.
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Disable,
+ );
+
+ // Clear any pending emissions.
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ PendingValidatorEmission::::insert(sn1, AlphaCurrency::ZERO);
+
+ // Build emission map.
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // Root should get NO alpha.
+ let pending_root = PendingRootAlphaDivs::::get(sn1);
+ assert_eq!(
+ pending_root,
+ AlphaCurrency::ZERO,
+ "with Disable mode, root should get no alpha on suppressed subnet"
+ );
+
+ // Validator emission should be non-zero (root alpha recycled to validators).
+ let pending_validator = PendingValidatorEmission::::get(sn1);
+ assert!(
+ pending_validator > AlphaCurrency::ZERO,
+ "validators should receive recycled root alpha"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 9: Disable mode actually recycles root alpha to validators
+// (validators get more than with Enable mode)
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_disable_mode_recycles_root_alpha_to_validators() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+ setup_root_with_tao(sn1);
+
+ // Force-suppress sn1.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ // ── Run with Enable mode first to get baseline ──
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
+ );
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ PendingValidatorEmission::::insert(sn1, AlphaCurrency::ZERO);
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ let enable_validator = PendingValidatorEmission::::get(sn1);
+ let enable_root = PendingRootAlphaDivs::::get(sn1);
+
+ // In Enable mode, root should accumulate some alpha.
+ assert!(
+ enable_root > AlphaCurrency::ZERO,
+ "Enable mode: root should get alpha"
+ );
+
+ // ── Now run with Disable mode ──
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Disable,
+ );
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ PendingValidatorEmission::::insert(sn1, AlphaCurrency::ZERO);
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ let disable_validator = PendingValidatorEmission::::get(sn1);
+ let disable_root = PendingRootAlphaDivs::::get(sn1);
+
+ // In Disable mode, root should get nothing.
+ assert_eq!(
+ disable_root,
+ AlphaCurrency::ZERO,
+ "Disable mode: root should get no alpha"
+ );
+
+ // Disable validators should get MORE than Enable validators because
+ // root alpha is recycled to them instead of going to root.
+ assert!(
+ disable_validator > enable_validator,
+ "Disable mode validators ({disable_validator:?}) should get more \
+ than Enable mode ({enable_validator:?}) because root alpha is recycled"
+ );
+
+ // The difference should equal the root alpha from Enable mode
+ // (root alpha is recycled to validators instead).
+ assert_eq!(
+ disable_validator.saturating_sub(enable_validator),
+ enable_root,
+ "difference should equal the root alpha that was recycled"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 10: Non-suppressed subnet → root alpha normal regardless of mode
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_unsuppressed_subnet_unaffected_by_flag() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+ setup_root_with_tao(sn1);
+
+ // sn1 is NOT suppressed.
+ // Set mode to Disable (should not matter for unsuppressed subnets).
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Disable,
+ );
+
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // Root should still get alpha since subnet is not suppressed.
+ let pending_root = PendingRootAlphaDivs::::get(sn1);
+ assert!(
+ pending_root > AlphaCurrency::ZERO,
+ "non-suppressed subnet should still give root alpha regardless of mode"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 11: sudo_set_emission_suppression_override emits event
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_sudo_override_emits_event() {
+ new_test_ext(1).execute_with(|| {
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ System::set_block_number(1);
+ System::reset_events();
+
+ assert_ok!(SubtensorModule::sudo_set_emission_suppression_override(
+ RuntimeOrigin::root(),
+ sn1,
+ Some(true),
+ ));
+
+ assert!(
+ System::events().iter().any(|e| {
+ matches!(
+ &e.event,
+ RuntimeEvent::SubtensorModule(
+ Event::EmissionSuppressionOverrideSet { netuid, override_value }
+ ) if *netuid == sn1 && *override_value == Some(true)
+ )
+ }),
+ "should emit EmissionSuppressionOverrideSet event"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 12: sudo_set_root_sell_pressure_on_suppressed_subnets_mode emits event
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_sudo_sell_pressure_emits_event() {
+ new_test_ext(1).execute_with(|| {
+ System::set_block_number(1);
+ System::reset_events();
+
+ assert_ok!(
+ SubtensorModule::sudo_set_root_sell_pressure_on_suppressed_subnets_mode(
+ RuntimeOrigin::root(),
+ RootSellPressureOnSuppressedSubnetsMode::Disable,
+ )
+ );
+
+ assert!(
+ System::events().iter().any(|e| {
+ matches!(
+ &e.event,
+ RuntimeEvent::SubtensorModule(
+ Event::RootSellPressureOnSuppressedSubnetsModeSet { mode }
+ ) if *mode == RootSellPressureOnSuppressedSubnetsMode::Disable
+ )
+ }),
+ "should emit RootSellPressureOnSuppressedSubnetsModeSet event"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 13: Default mode is Recycle
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_default_mode_is_recycle() {
+ new_test_ext(1).execute_with(|| {
+ assert_eq!(
+ KeepRootSellPressureOnSuppressedSubnets::::get(),
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 14: Recycle mode, suppressed subnet → alpha swapped to TAO, TAO burned
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ // Use add_dynamic_network to properly initialize the AMM.
+ let owner_hk = U256::from(50);
+ let owner_ck = U256::from(51);
+ let sn1 = add_dynamic_network(&owner_hk, &owner_ck);
+
+ // Seed the pool with TAO and alpha reserves.
+ let initial_tao = TaoCurrency::from(500_000_000u64);
+ let initial_alpha_in = AlphaCurrency::from(500_000_000u64);
+ SubnetTAO::::insert(sn1, initial_tao);
+ SubnetAlphaIn::::insert(sn1, initial_alpha_in);
+ SubnetTaoFlow::::insert(sn1, 100_000_000i64);
+
+ // Also set root TAO so root_proportion is nonzero.
+ SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000));
+ SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(1_000_000_000));
+
+ // Register a root validator.
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+
+ // Force-suppress sn1.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ // Default mode is Recycle.
+ assert_eq!(
+ KeepRootSellPressureOnSuppressedSubnets::::get(),
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+
+ // Record TotalIssuance before emission.
+ let issuance_before = TotalIssuance::::get();
+
+ // Clear pending.
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+
+ // Build emission map.
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // PendingRootAlphaDivs should be 0 (root did NOT accumulate alpha).
+ let pending_root = PendingRootAlphaDivs::::get(sn1);
+ assert_eq!(
+ pending_root,
+ AlphaCurrency::ZERO,
+ "in Recycle mode, PendingRootAlphaDivs should be 0"
+ );
+
+ // SubnetAlphaIn should have increased (alpha was swapped into pool).
+ let alpha_in_after = SubnetAlphaIn::::get(sn1);
+ assert!(
+ alpha_in_after > initial_alpha_in,
+ "SubnetAlphaIn should increase after swap"
+ );
+
+ // TotalIssuance should have decreased (TAO was recycled/burned).
+ let issuance_after = TotalIssuance::::get();
+ assert!(
+ issuance_after < issuance_before,
+ "TotalIssuance should decrease (TAO recycled)"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 15: Recycle mode on non-suppressed subnet → normal PendingRootAlphaDivs
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_recycle_mode_non_suppressed_subnet_normal() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ let sn1 = NetUid::from(1);
+ setup_subnet_with_flow(sn1, 10, 100_000_000);
+
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+ setup_root_with_tao(sn1);
+
+ // sn1 is NOT suppressed. Mode is Recycle (default).
+ assert_eq!(
+ KeepRootSellPressureOnSuppressedSubnets::::get(),
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // Root should still get alpha — Recycle only affects suppressed subnets.
+ let pending_root = PendingRootAlphaDivs::::get(sn1);
+ assert!(
+ pending_root > AlphaCurrency::ZERO,
+ "non-suppressed subnet should still give root alpha in Recycle mode"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 16: Recycle mode ignores RootClaimType (alpha never enters claim flow)
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_recycle_mode_ignores_root_claim_type() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ // Use add_dynamic_network to properly initialize the AMM.
+ let owner_hk = U256::from(50);
+ let owner_ck = U256::from(51);
+ let sn1 = add_dynamic_network(&owner_hk, &owner_ck);
+
+ SubnetTAO::::insert(sn1, TaoCurrency::from(500_000_000u64));
+ SubnetAlphaIn::::insert(sn1, AlphaCurrency::from(500_000_000u64));
+ SubnetTaoFlow::::insert(sn1, 100_000_000i64);
+ SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000));
+ SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(1_000_000_000));
+
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+
+ // Force-suppress sn1.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ // Set RootClaimType to Keep — in normal flow this would keep alpha.
+ // But Recycle mode should override and swap+burn regardless.
+ RootClaimType::::insert(coldkey, RootClaimTypeEnum::Keep);
+
+ // Default mode is Recycle.
+ assert_eq!(
+ KeepRootSellPressureOnSuppressedSubnets::::get(),
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+
+ let issuance_before = TotalIssuance::::get();
+
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // PendingRootAlphaDivs should still be 0 (recycled, not claimed).
+ let pending_root = PendingRootAlphaDivs::::get(sn1);
+ assert_eq!(
+ pending_root,
+ AlphaCurrency::ZERO,
+ "Recycle mode should swap+burn regardless of RootClaimType"
+ );
+
+ // TAO was burned.
+ let issuance_after = TotalIssuance::::get();
+ assert!(
+ issuance_after < issuance_before,
+ "TotalIssuance should decrease even with RootClaimType::Keep"
+ );
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 17: sudo_set_mode all 3 variants emit events
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_sudo_set_mode_all_variants_emit_events() {
+ new_test_ext(1).execute_with(|| {
+ System::set_block_number(1);
+
+ for mode in [
+ RootSellPressureOnSuppressedSubnetsMode::Disable,
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ ] {
+ System::reset_events();
+
+ assert_ok!(
+ SubtensorModule::sudo_set_root_sell_pressure_on_suppressed_subnets_mode(
+ RuntimeOrigin::root(),
+ mode,
+ )
+ );
+
+ assert_eq!(KeepRootSellPressureOnSuppressedSubnets::::get(), mode,);
+
+ assert!(
+ System::events().iter().any(|e| {
+ matches!(
+ &e.event,
+ RuntimeEvent::SubtensorModule(
+ Event::RootSellPressureOnSuppressedSubnetsModeSet { mode: m }
+ ) if *m == mode
+ )
+ }),
+ "should emit RootSellPressureOnSuppressedSubnetsModeSet for {mode:?}"
+ );
+ }
+ });
+}
+
+// ─────────────────────────────────────────────────────────────────────────────
+// Test 18: Recycle mode decreases price and flow EMA; Disable/Enable do not
+// ─────────────────────────────────────────────────────────────────────────────
+#[test]
+fn test_recycle_mode_decreases_price_and_flow_ema() {
+ new_test_ext(1).execute_with(|| {
+ add_network(NetUid::ROOT, 1, 0);
+ // Use add_dynamic_network to properly initialize the AMM.
+ let owner_hk = U256::from(50);
+ let owner_ck = U256::from(51);
+ let sn1 = add_dynamic_network(&owner_hk, &owner_ck);
+
+ // Large pool reserves to ensure swaps produce measurable effects.
+ let pool_reserve = 1_000_000_000u64;
+ SubnetTAO::::insert(sn1, TaoCurrency::from(pool_reserve));
+ SubnetAlphaIn::::insert(sn1, AlphaCurrency::from(pool_reserve));
+ SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(pool_reserve));
+ SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(pool_reserve));
+ SubnetTaoFlow::::insert(sn1, 100_000_000i64);
+
+ let hotkey = U256::from(10);
+ let coldkey = U256::from(11);
+ assert_ok!(SubtensorModule::root_register(
+ RuntimeOrigin::signed(coldkey),
+ hotkey,
+ ));
+ SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
+ &hotkey,
+ &coldkey,
+ NetUid::ROOT,
+ 1_000_000_000u64.into(),
+ );
+ SubtensorModule::set_tao_weight(u64::MAX);
+
+ // Force-suppress sn1.
+ EmissionSuppressionOverride::::insert(sn1, true);
+
+ let emission_amount = U96F32::from_num(10_000_000);
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, emission_amount);
+
+ // ── First: verify that Disable and Enable modes do NOT cause TAO outflow ──
+
+ for mode in [
+ RootSellPressureOnSuppressedSubnetsMode::Disable,
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
+ ] {
+ // Reset pool state.
+ SubnetTAO::::insert(sn1, TaoCurrency::from(pool_reserve));
+ SubnetAlphaIn::::insert(sn1, AlphaCurrency::from(pool_reserve));
+ SubnetTaoFlow::::insert(sn1, 0i64);
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(pool_reserve));
+
+ KeepRootSellPressureOnSuppressedSubnets::::put(mode);
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ let flow = SubnetTaoFlow::::get(sn1);
+ assert!(
+ flow >= 0,
+ "mode {mode:?}: SubnetTaoFlow should not be negative, got {flow}"
+ );
+ }
+
+ // ── Now: verify that Recycle mode DOES cause TAO outflow ──
+
+ // Reset pool state.
+ SubnetTAO::::insert(sn1, TaoCurrency::from(pool_reserve));
+ SubnetAlphaIn::::insert(sn1, AlphaCurrency::from(pool_reserve));
+ SubnetTaoFlow::::insert(sn1, 0i64);
+ PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(pool_reserve));
+
+ // Set Recycle mode.
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+
+ // Record TAO reserve before.
+ let tao_before = SubnetTAO::::get(sn1);
+
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+
+ // SubnetTaoFlow should be negative (TAO left the pool via swap).
+ let flow_after = SubnetTaoFlow::::get(sn1);
+ assert!(
+ flow_after < 0,
+ "Recycle mode: SubnetTaoFlow should be negative (TAO outflow), got {flow_after}"
+ );
+
+ // SubnetTAO should have decreased (TAO left the pool in the swap).
+ // Note: emit_to_subnets injects some TAO via inject_and_maybe_swap,
+ // but the swap_alpha_for_tao pulls TAO back out. The net flow recorded
+ // as negative proves outflow dominated.
+ let tao_after = SubnetTAO::::get(sn1);
+ assert!(
+ tao_after < tao_before,
+ "Recycle mode: SubnetTAO should decrease (TAO outflow), before={tao_before:?} after={tao_after:?}"
+ );
+ });
+}
diff --git a/pallets/subtensor/src/tests/mod.rs b/pallets/subtensor/src/tests/mod.rs
index bbaf25af58..3db0bfc421 100644
--- a/pallets/subtensor/src/tests/mod.rs
+++ b/pallets/subtensor/src/tests/mod.rs
@@ -7,6 +7,7 @@ mod consensus;
mod delegate_info;
mod difficulty;
mod emission;
+mod emission_suppression;
mod ensure;
mod epoch;
mod epoch_logs;
From 4f777815d187e2ce8d27e1557c18d99dd01f8e8a Mon Sep 17 00:00:00 2001
From: Pawel Polewicz
Date: Wed, 25 Feb 2026 21:16:55 +0000
Subject: [PATCH 2/7] Fix test 14/16: verify TAO is recycled, not just burned
Clarify that Recycle mode swaps root alpha to TAO via AMM, then
recycles the TAO (removes from TotalIssuance). Add assertions that
the TotalIssuance drop equals the TAO that left the subnet pool,
proving all swap proceeds were recycled. Fix comments to use
"recycled" instead of "burned" throughout.
---
.../src/tests/emission_suppression.rs | 83 +++++++++++++++----
1 file changed, 65 insertions(+), 18 deletions(-)
diff --git a/pallets/subtensor/src/tests/emission_suppression.rs b/pallets/subtensor/src/tests/emission_suppression.rs
index d20b396927..a764350da9 100644
--- a/pallets/subtensor/src/tests/emission_suppression.rs
+++ b/pallets/subtensor/src/tests/emission_suppression.rs
@@ -515,7 +515,21 @@ fn test_default_mode_is_recycle() {
}
// ─────────────────────────────────────────────────────────────────────────────
-// Test 14: Recycle mode, suppressed subnet → alpha swapped to TAO, TAO burned
+// Test 14: Recycle mode, suppressed subnet → root alpha swapped to TAO via
+// AMM, then TAO recycled (removed from TotalIssuance).
+//
+// The full flow is:
+// 1. Root alpha that would go to root validators is instead sold into the
+// subnet's AMM pool (alpha in, TAO out).
+// 2. The TAO received from the swap is recycled via `recycle_tao`, which
+// decreases TotalIssuance (TAO is permanently removed from circulation).
+//
+// We verify every step:
+// - PendingRootAlphaDivs stays 0 (root did NOT accumulate alpha).
+// - SubnetAlphaIn increases (alpha entered the pool via the swap).
+// - SubnetTAO decreases (TAO left the pool via the swap).
+// - TotalIssuance decreases by exactly the TAO that left the pool
+// (proving that TAO was recycled, not sent elsewhere).
// ─────────────────────────────────────────────────────────────────────────────
#[test]
fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
@@ -527,9 +541,8 @@ fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
let sn1 = add_dynamic_network(&owner_hk, &owner_ck);
// Seed the pool with TAO and alpha reserves.
- let initial_tao = TaoCurrency::from(500_000_000u64);
let initial_alpha_in = AlphaCurrency::from(500_000_000u64);
- SubnetTAO::::insert(sn1, initial_tao);
+ SubnetTAO::::insert(sn1, TaoCurrency::from(500_000_000u64));
SubnetAlphaIn::::insert(sn1, initial_alpha_in);
SubnetTaoFlow::::insert(sn1, 100_000_000i64);
@@ -561,38 +574,63 @@ fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
RootSellPressureOnSuppressedSubnetsMode::Recycle,
);
- // Record TotalIssuance before emission.
- let issuance_before = TotalIssuance::::get();
-
// Clear pending.
PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ // Snapshot state before emission.
+ // Note: emit_to_subnets calls inject_and_maybe_swap first which adds TAO
+ // to the pool, so we snapshot SubnetTAO *after* a dry run would inject.
+ // Instead we record TotalIssuance and SubnetTAO, and check relative changes.
+ let issuance_before = TotalIssuance::::get();
+ let subnet_tao_before = SubnetTAO::::get(sn1);
+
// Build emission map.
let mut subnet_emissions = BTreeMap::new();
subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
- // PendingRootAlphaDivs should be 0 (root did NOT accumulate alpha).
+ // 1. Root did NOT accumulate alpha — it was recycled instead.
let pending_root = PendingRootAlphaDivs::::get(sn1);
assert_eq!(
pending_root,
AlphaCurrency::ZERO,
- "in Recycle mode, PendingRootAlphaDivs should be 0"
+ "Recycle mode: PendingRootAlphaDivs must be 0"
);
- // SubnetAlphaIn should have increased (alpha was swapped into pool).
+ // 2. Alpha entered the pool (swap sold alpha into AMM).
let alpha_in_after = SubnetAlphaIn::::get(sn1);
assert!(
alpha_in_after > initial_alpha_in,
- "SubnetAlphaIn should increase after swap"
+ "Recycle mode: SubnetAlphaIn must increase (alpha entered pool via swap)"
);
- // TotalIssuance should have decreased (TAO was recycled/burned).
+ // 3. TAO left the pool (AMM paid out TAO for the alpha).
+ // emit_to_subnets also injects TAO via inject_and_maybe_swap, so
+ // SubnetTAO may have increased from that injection first; but the
+ // net SubnetTaoFlow being negative (checked in test 18) proves
+ // the swap outflow dominated. Here we check the pool TAO decreased
+ // relative to where it started before both inject + swap.
+ let subnet_tao_after = SubnetTAO::::get(sn1);
+ assert!(
+ subnet_tao_after < subnet_tao_before,
+ "Recycle mode: SubnetTAO must decrease (TAO left pool via swap), \
+ before={subnet_tao_before:?} after={subnet_tao_after:?}"
+ );
+
+ // 4. The TAO that left the pool was recycled (removed from TotalIssuance).
+ // The issuance drop should equal the TAO that left the subnet pool.
let issuance_after = TotalIssuance::::get();
+ let tao_recycled = issuance_before.saturating_sub(issuance_after);
+ let tao_left_pool = subnet_tao_before.saturating_sub(subnet_tao_after);
assert!(
- issuance_after < issuance_before,
- "TotalIssuance should decrease (TAO recycled)"
+ tao_recycled > TaoCurrency::ZERO,
+ "Recycle mode: TotalIssuance must decrease (TAO was recycled)"
+ );
+ assert_eq!(
+ tao_recycled, tao_left_pool,
+ "Recycle mode: TotalIssuance drop ({tao_recycled:?}) must equal TAO that \
+ left the pool ({tao_left_pool:?}) — all swap proceeds were recycled"
);
});
}
@@ -680,7 +718,7 @@ fn test_recycle_mode_ignores_root_claim_type() {
EmissionSuppressionOverride::::insert(sn1, true);
// Set RootClaimType to Keep — in normal flow this would keep alpha.
- // But Recycle mode should override and swap+burn regardless.
+ // But Recycle mode should override and swap+recycle regardless.
RootClaimType::::insert(coldkey, RootClaimTypeEnum::Keep);
// Default mode is Recycle.
@@ -689,6 +727,8 @@ fn test_recycle_mode_ignores_root_claim_type() {
RootSellPressureOnSuppressedSubnetsMode::Recycle,
);
+ let subnet_tao_before = SubnetTAO::::get(sn1);
+
PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
let issuance_before = TotalIssuance::::get();
@@ -703,14 +743,21 @@ fn test_recycle_mode_ignores_root_claim_type() {
assert_eq!(
pending_root,
AlphaCurrency::ZERO,
- "Recycle mode should swap+burn regardless of RootClaimType"
+ "Recycle mode should swap+recycle regardless of RootClaimType"
);
- // TAO was burned.
+ // TAO was recycled (removed from circulation).
let issuance_after = TotalIssuance::::get();
+ let subnet_tao_after = SubnetTAO::::get(sn1);
+ let tao_recycled = issuance_before.saturating_sub(issuance_after);
+ let tao_left_pool = subnet_tao_before.saturating_sub(subnet_tao_after);
assert!(
- issuance_after < issuance_before,
- "TotalIssuance should decrease even with RootClaimType::Keep"
+ tao_recycled > TaoCurrency::ZERO,
+ "TotalIssuance must decrease even with RootClaimType::Keep"
+ );
+ assert_eq!(
+ tao_recycled, tao_left_pool,
+ "all TAO from the swap must be recycled (removed from TotalIssuance)"
);
});
}
From 4f31c92bb0c351e6f211dbd26138ba24f5961133 Mon Sep 17 00:00:00 2001
From: Pawel Polewicz
Date: Wed, 25 Feb 2026 21:28:54 +0000
Subject: [PATCH 3/7] Fix recycle tests: compare Enable vs Recycle mode
issuance
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Tests 14 and 16 were incorrectly asserting that TotalIssuance decreases
in Recycle mode. In reality, emission increases TotalIssuance first
(via inject_and_maybe_swap), then the recycle partially offsets it.
The net effect is a smaller increase, not a decrease.
Rewrite both tests to run Enable mode as baseline, then Recycle mode
from the same starting state, and assert Recycle issuance < Enable
issuance — proving TAO was recycled without depending on test-setup
artifacts.
---
.../src/tests/emission_suppression.rs | 209 ++++++++++--------
1 file changed, 117 insertions(+), 92 deletions(-)
diff --git a/pallets/subtensor/src/tests/emission_suppression.rs b/pallets/subtensor/src/tests/emission_suppression.rs
index a764350da9..ed0bc34ec8 100644
--- a/pallets/subtensor/src/tests/emission_suppression.rs
+++ b/pallets/subtensor/src/tests/emission_suppression.rs
@@ -519,17 +519,21 @@ fn test_default_mode_is_recycle() {
// AMM, then TAO recycled (removed from TotalIssuance).
//
// The full flow is:
-// 1. Root alpha that would go to root validators is instead sold into the
+// 1. Emission injects TAO into the subnet pool (TotalIssuance increases).
+// 2. Root alpha that would go to root validators is instead sold into the
// subnet's AMM pool (alpha in, TAO out).
-// 2. The TAO received from the swap is recycled via `recycle_tao`, which
+// 3. The TAO received from the swap is recycled via `recycle_tao`, which
// decreases TotalIssuance (TAO is permanently removed from circulation).
//
-// We verify every step:
-// - PendingRootAlphaDivs stays 0 (root did NOT accumulate alpha).
-// - SubnetAlphaIn increases (alpha entered the pool via the swap).
-// - SubnetTAO decreases (TAO left the pool via the swap).
-// - TotalIssuance decreases by exactly the TAO that left the pool
-// (proving that TAO was recycled, not sent elsewhere).
+// Net effect: TotalIssuance still increases from the emission, but less than
+// it would with Enable mode because some TAO is recycled back out.
+//
+// We verify by running Enable mode first (baseline), then Recycle mode, and
+// comparing:
+// - PendingRootAlphaDivs is 0 in Recycle (root did NOT accumulate alpha).
+// - Recycle TotalIssuance < Enable TotalIssuance (TAO was recycled).
+// - The difference equals PendingRootAlphaDivs from the Enable run
+// converted through the AMM (the recycled amount).
// ─────────────────────────────────────────────────────────────────────────────
#[test]
fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
@@ -540,15 +544,22 @@ fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
let owner_ck = U256::from(51);
let sn1 = add_dynamic_network(&owner_hk, &owner_ck);
- // Seed the pool with TAO and alpha reserves.
- let initial_alpha_in = AlphaCurrency::from(500_000_000u64);
- SubnetTAO::::insert(sn1, TaoCurrency::from(500_000_000u64));
- SubnetAlphaIn::::insert(sn1, initial_alpha_in);
- SubnetTaoFlow::::insert(sn1, 100_000_000i64);
-
- // Also set root TAO so root_proportion is nonzero.
- SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000));
- SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(1_000_000_000));
+ let pool_tao = TaoCurrency::from(500_000_000u64);
+ let pool_alpha_in = AlphaCurrency::from(500_000_000u64);
+ let root_tao = TaoCurrency::from(1_000_000_000u64);
+ let sn1_alpha_out = AlphaCurrency::from(1_000_000_000u64);
+
+ // Helper closure to reset pool + pending state to a known baseline.
+ let reset_state = |sn: NetUid| {
+ SubnetTAO::::insert(sn, pool_tao);
+ SubnetAlphaIn::::insert(sn, pool_alpha_in);
+ SubnetTaoFlow::::insert(sn, 100_000_000i64);
+ SubnetTAO::::insert(NetUid::ROOT, root_tao);
+ SubnetAlphaOut::::insert(sn, sn1_alpha_out);
+ PendingRootAlphaDivs::::insert(sn, AlphaCurrency::ZERO);
+ PendingValidatorEmission::::insert(sn, AlphaCurrency::ZERO);
+ PendingServerEmission::::insert(sn, AlphaCurrency::ZERO);
+ };
// Register a root validator.
let hotkey = U256::from(10);
@@ -568,69 +579,61 @@ fn test_recycle_mode_suppressed_subnet_swaps_and_recycles() {
// Force-suppress sn1.
EmissionSuppressionOverride::::insert(sn1, true);
- // Default mode is Recycle.
- assert_eq!(
- KeepRootSellPressureOnSuppressedSubnets::::get(),
- RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ // ── Run with Enable mode first (baseline) ──
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
);
+ reset_state(sn1);
+ let issuance_before_enable = TotalIssuance::::get();
- // Clear pending.
- PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
- // Snapshot state before emission.
- // Note: emit_to_subnets calls inject_and_maybe_swap first which adds TAO
- // to the pool, so we snapshot SubnetTAO *after* a dry run would inject.
- // Instead we record TotalIssuance and SubnetTAO, and check relative changes.
- let issuance_before = TotalIssuance::::get();
- let subnet_tao_before = SubnetTAO::::get(sn1);
+ let issuance_after_enable = TotalIssuance::::get();
+ let enable_root_alpha = PendingRootAlphaDivs::::get(sn1);
- // Build emission map.
- let mut subnet_emissions = BTreeMap::new();
- subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+ // In Enable mode, root should have accumulated alpha.
+ assert!(
+ enable_root_alpha > AlphaCurrency::ZERO,
+ "Enable mode: root should accumulate alpha"
+ );
+
+ // ── Now run with Recycle mode ──
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+ reset_state(sn1);
+ // Reset TotalIssuance to the same starting point.
+ TotalIssuance::::put(issuance_before_enable);
SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
+ let issuance_after_recycle = TotalIssuance::::get();
+
// 1. Root did NOT accumulate alpha — it was recycled instead.
- let pending_root = PendingRootAlphaDivs::::get(sn1);
+ let recycle_root_alpha = PendingRootAlphaDivs::::get(sn1);
assert_eq!(
- pending_root,
+ recycle_root_alpha,
AlphaCurrency::ZERO,
"Recycle mode: PendingRootAlphaDivs must be 0"
);
- // 2. Alpha entered the pool (swap sold alpha into AMM).
- let alpha_in_after = SubnetAlphaIn::::get(sn1);
- assert!(
- alpha_in_after > initial_alpha_in,
- "Recycle mode: SubnetAlphaIn must increase (alpha entered pool via swap)"
- );
-
- // 3. TAO left the pool (AMM paid out TAO for the alpha).
- // emit_to_subnets also injects TAO via inject_and_maybe_swap, so
- // SubnetTAO may have increased from that injection first; but the
- // net SubnetTaoFlow being negative (checked in test 18) proves
- // the swap outflow dominated. Here we check the pool TAO decreased
- // relative to where it started before both inject + swap.
- let subnet_tao_after = SubnetTAO::::get(sn1);
+ // 2. Recycle mode results in less TotalIssuance than Enable mode,
+ // because the root alpha was swapped to TAO and that TAO was recycled.
+ // Both runs started from the same issuance and emitted the same amount,
+ // so the difference is exactly the recycled TAO.
assert!(
- subnet_tao_after < subnet_tao_before,
- "Recycle mode: SubnetTAO must decrease (TAO left pool via swap), \
- before={subnet_tao_before:?} after={subnet_tao_after:?}"
+ issuance_after_recycle < issuance_after_enable,
+ "Recycle mode TotalIssuance ({issuance_after_recycle:?}) must be less than \
+ Enable mode ({issuance_after_enable:?}) because TAO was recycled"
);
- // 4. The TAO that left the pool was recycled (removed from TotalIssuance).
- // The issuance drop should equal the TAO that left the subnet pool.
- let issuance_after = TotalIssuance::::get();
- let tao_recycled = issuance_before.saturating_sub(issuance_after);
- let tao_left_pool = subnet_tao_before.saturating_sub(subnet_tao_after);
+ let tao_recycled = issuance_after_enable.saturating_sub(issuance_after_recycle);
assert!(
tao_recycled > TaoCurrency::ZERO,
- "Recycle mode: TotalIssuance must decrease (TAO was recycled)"
- );
- assert_eq!(
- tao_recycled, tao_left_pool,
- "Recycle mode: TotalIssuance drop ({tao_recycled:?}) must equal TAO that \
- left the pool ({tao_left_pool:?}) — all swap proceeds were recycled"
+ "some TAO must have been recycled"
);
});
}
@@ -683,7 +686,12 @@ fn test_recycle_mode_non_suppressed_subnet_normal() {
}
// ─────────────────────────────────────────────────────────────────────────────
-// Test 16: Recycle mode ignores RootClaimType (alpha never enters claim flow)
+// Test 16: Recycle mode ignores RootClaimType (alpha never enters claim flow).
+// Even with RootClaimType::Keep, the root alpha is swapped to TAO and
+// recycled — it never reaches the claim flow.
+//
+// We compare Enable vs Recycle under identical conditions to show that
+// Recycle still removes TAO from circulation regardless of RootClaimType.
// ─────────────────────────────────────────────────────────────────────────────
#[test]
fn test_recycle_mode_ignores_root_claim_type() {
@@ -694,11 +702,21 @@ fn test_recycle_mode_ignores_root_claim_type() {
let owner_ck = U256::from(51);
let sn1 = add_dynamic_network(&owner_hk, &owner_ck);
- SubnetTAO::::insert(sn1, TaoCurrency::from(500_000_000u64));
- SubnetAlphaIn::::insert(sn1, AlphaCurrency::from(500_000_000u64));
- SubnetTaoFlow::::insert(sn1, 100_000_000i64);
- SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000));
- SubnetAlphaOut::::insert(sn1, AlphaCurrency::from(1_000_000_000));
+ let pool_tao = TaoCurrency::from(500_000_000u64);
+ let pool_alpha_in = AlphaCurrency::from(500_000_000u64);
+ let root_tao = TaoCurrency::from(1_000_000_000u64);
+ let sn1_alpha_out = AlphaCurrency::from(1_000_000_000u64);
+
+ let reset_state = |sn: NetUid| {
+ SubnetTAO::::insert(sn, pool_tao);
+ SubnetAlphaIn::::insert(sn, pool_alpha_in);
+ SubnetTaoFlow::::insert(sn, 100_000_000i64);
+ SubnetTAO::::insert(NetUid::ROOT, root_tao);
+ SubnetAlphaOut::::insert(sn, sn1_alpha_out);
+ PendingRootAlphaDivs::::insert(sn, AlphaCurrency::ZERO);
+ PendingValidatorEmission::::insert(sn, AlphaCurrency::ZERO);
+ PendingServerEmission::::insert(sn, AlphaCurrency::ZERO);
+ };
let hotkey = U256::from(10);
let coldkey = U256::from(11);
@@ -721,43 +739,50 @@ fn test_recycle_mode_ignores_root_claim_type() {
// But Recycle mode should override and swap+recycle regardless.
RootClaimType::::insert(coldkey, RootClaimTypeEnum::Keep);
- // Default mode is Recycle.
- assert_eq!(
- KeepRootSellPressureOnSuppressedSubnets::::get(),
- RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ let mut subnet_emissions = BTreeMap::new();
+ subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+
+ // ── Run with Enable mode (baseline) ──
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
);
+ reset_state(sn1);
+ let issuance_baseline = TotalIssuance::::get();
- let subnet_tao_before = SubnetTAO::::get(sn1);
+ SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
- PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
+ let issuance_after_enable = TotalIssuance::::get();
- let issuance_before = TotalIssuance::::get();
+ // In Enable mode, root should have accumulated alpha.
+ assert!(
+ PendingRootAlphaDivs::::get(sn1) > AlphaCurrency::ZERO,
+ "Enable baseline: root should accumulate alpha"
+ );
- let mut subnet_emissions = BTreeMap::new();
- subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
+ // ── Now run with Recycle mode ──
+ KeepRootSellPressureOnSuppressedSubnets::::put(
+ RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ );
+ reset_state(sn1);
+ TotalIssuance::::put(issuance_baseline);
SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
- // PendingRootAlphaDivs should still be 0 (recycled, not claimed).
- let pending_root = PendingRootAlphaDivs::::get(sn1);
+ let issuance_after_recycle = TotalIssuance::::get();
+
+ // Root did NOT accumulate alpha — recycled instead.
assert_eq!(
- pending_root,
+ PendingRootAlphaDivs::::get(sn1),
AlphaCurrency::ZERO,
- "Recycle mode should swap+recycle regardless of RootClaimType"
+ "Recycle mode should swap+recycle regardless of RootClaimType::Keep"
);
- // TAO was recycled (removed from circulation).
- let issuance_after = TotalIssuance::::get();
- let subnet_tao_after = SubnetTAO::::get(sn1);
- let tao_recycled = issuance_before.saturating_sub(issuance_after);
- let tao_left_pool = subnet_tao_before.saturating_sub(subnet_tao_after);
+ // Recycle mode results in less TotalIssuance than Enable mode:
+ // the root alpha was swapped to TAO and that TAO was recycled.
assert!(
- tao_recycled > TaoCurrency::ZERO,
- "TotalIssuance must decrease even with RootClaimType::Keep"
- );
- assert_eq!(
- tao_recycled, tao_left_pool,
- "all TAO from the swap must be recycled (removed from TotalIssuance)"
+ issuance_after_recycle < issuance_after_enable,
+ "Recycle mode TotalIssuance ({issuance_after_recycle:?}) must be less than \
+ Enable mode ({issuance_after_enable:?}) — TAO was recycled despite RootClaimType::Keep"
);
});
}
From 949a2b8958e605bd915486a02804305f627c4277 Mon Sep 17 00:00:00 2001
From: Pawel Polewicz
Date: Wed, 25 Feb 2026 21:53:34 +0000
Subject: [PATCH 4/7] Change default RootSellPressureOnSuppressedSubnetsMode to
Enable
---
pallets/subtensor/src/lib.rs | 4 ++--
.../subtensor/src/tests/emission_suppression.rs | 16 ++++++----------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs
index ca81249d5c..2447d16639 100644
--- a/pallets/subtensor/src/lib.rs
+++ b/pallets/subtensor/src/lib.rs
@@ -350,10 +350,10 @@ pub mod pallet {
#[codec(index = 0)]
Disable,
/// Root still accumulates alpha on suppressed subnets (old `true`).
+ #[default]
#[codec(index = 1)]
Enable,
- /// Root alpha is swapped to TAO via AMM and the TAO is burned.
- #[default]
+ /// Root alpha is swapped to TAO via AMM and the TAO is recycled.
#[codec(index = 2)]
Recycle,
}
diff --git a/pallets/subtensor/src/tests/emission_suppression.rs b/pallets/subtensor/src/tests/emission_suppression.rs
index ed0bc34ec8..371c885e84 100644
--- a/pallets/subtensor/src/tests/emission_suppression.rs
+++ b/pallets/subtensor/src/tests/emission_suppression.rs
@@ -217,12 +217,9 @@ fn test_suppressed_subnet_root_alpha_by_default() {
// Force-suppress sn1.
EmissionSuppressionOverride::::insert(sn1, true);
- // Default mode is Recycle; verify that, then set to Enable for this test.
+ // Default mode is Enable; this test uses it as-is.
assert_eq!(
KeepRootSellPressureOnSuppressedSubnets::::get(),
- RootSellPressureOnSuppressedSubnetsMode::Recycle,
- );
- KeepRootSellPressureOnSuppressedSubnets::::put(
RootSellPressureOnSuppressedSubnetsMode::Enable,
);
@@ -502,14 +499,14 @@ fn test_sudo_sell_pressure_emits_event() {
}
// ─────────────────────────────────────────────────────────────────────────────
-// Test 13: Default mode is Recycle
+// Test 13: Default mode is Enable
// ─────────────────────────────────────────────────────────────────────────────
#[test]
-fn test_default_mode_is_recycle() {
+fn test_default_mode_is_enable() {
new_test_ext(1).execute_with(|| {
assert_eq!(
KeepRootSellPressureOnSuppressedSubnets::::get(),
- RootSellPressureOnSuppressedSubnetsMode::Recycle,
+ RootSellPressureOnSuppressedSubnetsMode::Enable,
);
});
}
@@ -663,9 +660,8 @@ fn test_recycle_mode_non_suppressed_subnet_normal() {
SubtensorModule::set_tao_weight(u64::MAX);
setup_root_with_tao(sn1);
- // sn1 is NOT suppressed. Mode is Recycle (default).
- assert_eq!(
- KeepRootSellPressureOnSuppressedSubnets::::get(),
+ // sn1 is NOT suppressed. Set mode to Recycle for this test.
+ KeepRootSellPressureOnSuppressedSubnets::::put(
RootSellPressureOnSuppressedSubnetsMode::Recycle,
);
From 8a726a5428b6d00747d0afb0abab0ed89a2b8eda Mon Sep 17 00:00:00 2001
From: Pawel Polewicz
Date: Wed, 25 Feb 2026 22:05:45 +0000
Subject: [PATCH 5/7] Remove RootSellPressureOnSuppressedSubnetsMode and always
use Enable behavior
Remove the mode enum, storage value, sudo extrinsic (call_index 135), and
event. Root always accumulates alpha on suppressed subnets. Remove all
mode-related tests.
---
.../subtensor/src/coinbase/run_coinbase.rs | 39 +-
pallets/subtensor/src/lib.rs | 25 -
pallets/subtensor/src/macros/dispatches.rs | 21 -
pallets/subtensor/src/macros/events.rs | 6 -
.../src/tests/emission_suppression.rs | 666 +-----------------
5 files changed, 8 insertions(+), 749 deletions(-)
diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs
index bad9712e1e..d18073da36 100644
--- a/pallets/subtensor/src/coinbase/run_coinbase.rs
+++ b/pallets/subtensor/src/coinbase/run_coinbase.rs
@@ -183,7 +183,6 @@ impl Pallet {
// --- 3. Inject ALPHA for participants.
let cut_percent: U96F32 = Self::get_float_subnet_owner_cut();
- let root_sell_pressure_mode = KeepRootSellPressureOnSuppressedSubnets::::get();
for netuid_i in subnets_to_emit_to.iter() {
// Get alpha_out for this block.
@@ -209,9 +208,6 @@ impl Pallet {
let root_proportion = Self::root_proportion(*netuid_i);
log::debug!("root_proportion: {root_proportion:?}");
- // Check if subnet emission is suppressed (compute once to avoid double storage read).
- let is_suppressed = Self::is_subnet_emission_suppressed(*netuid_i);
-
// Get root alpha from root prop.
let root_alpha: U96F32 = root_proportion
.saturating_mul(alpha_out_i) // Total alpha emission per block remaining.
@@ -239,37 +235,10 @@ impl Pallet {
});
if root_sell_flag {
- // Determine disposition of root alpha based on suppression mode.
- if is_suppressed
- && root_sell_pressure_mode == RootSellPressureOnSuppressedSubnetsMode::Disable
- {
- // Disable mode: recycle root alpha back to subnet validators.
- PendingValidatorEmission::::mutate(*netuid_i, |total| {
- *total = total.saturating_add(tou64!(root_alpha).into());
- });
- } else if is_suppressed
- && root_sell_pressure_mode == RootSellPressureOnSuppressedSubnetsMode::Recycle
- {
- // Recycle mode: swap alpha → TAO via AMM, then burn the TAO.
- let root_alpha_currency = AlphaCurrency::from(tou64!(root_alpha));
- if let Ok(swap_result) = Self::swap_alpha_for_tao(
- *netuid_i,
- root_alpha_currency,
- TaoCurrency::ZERO, // no price limit
- true, // drop fees
- ) {
- Self::record_tao_outflow(*netuid_i, swap_result.amount_paid_out);
- Self::recycle_tao(swap_result.amount_paid_out);
- } else {
- // Swap failed: recycle alpha back to subnet to prevent loss.
- Self::recycle_subnet_alpha(*netuid_i, root_alpha_currency);
- }
- } else {
- // Enable mode (or non-suppressed subnet): accumulate for root validators.
- PendingRootAlphaDivs::::mutate(*netuid_i, |total| {
- *total = total.saturating_add(tou64!(root_alpha).into());
- });
- }
+ // Accumulate root alpha divs for root validators.
+ PendingRootAlphaDivs::::mutate(*netuid_i, |total| {
+ *total = total.saturating_add(tou64!(root_alpha).into());
+ });
} else {
// If we are not selling the root alpha, we should recycle it.
Self::recycle_subnet_alpha(*netuid_i, AlphaCurrency::from(tou64!(root_alpha)));
diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs
index 2447d16639..d4a27ff1f8 100644
--- a/pallets/subtensor/src/lib.rs
+++ b/pallets/subtensor/src/lib.rs
@@ -341,23 +341,6 @@ pub mod pallet {
},
}
- /// Controls how root alpha dividends are handled on emission-suppressed subnets.
- #[derive(
- Encode, Decode, Default, TypeInfo, Clone, Copy, PartialEq, Eq, Debug, DecodeWithMemTracking,
- )]
- pub enum RootSellPressureOnSuppressedSubnetsMode {
- /// Root gets no alpha on suppressed subnets; root alpha recycled to subnet validators.
- #[codec(index = 0)]
- Disable,
- /// Root still accumulates alpha on suppressed subnets (old `true`).
- #[default]
- #[codec(index = 1)]
- Enable,
- /// Root alpha is swapped to TAO via AMM and the TAO is recycled.
- #[codec(index = 2)]
- Recycle,
- }
-
/// Default minimum root claim amount.
/// This is the minimum amount of root claim that can be made.
/// Any amount less than this will not be claimed.
@@ -2399,14 +2382,6 @@ pub mod pallet {
pub type EmissionSuppressionOverride =
StorageMap<_, Identity, NetUid, bool, OptionQuery>;
- /// Controls how root alpha dividends are handled on emission-suppressed subnets.
- /// - Disable (0x00): root gets no alpha; root alpha recycled to subnet validators.
- /// - Enable (0x01): root still accumulates alpha (old behaviour).
- /// - Recycle (0x02, default): root alpha swapped to TAO and TAO burned.
- #[pallet::storage]
- pub type KeepRootSellPressureOnSuppressedSubnets =
- StorageValue<_, RootSellPressureOnSuppressedSubnetsMode, ValueQuery>;
-
#[pallet::genesis_config]
pub struct GenesisConfig {
/// Stakes record in genesis.
diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs
index 4b1bbf7dae..6e69ea244f 100644
--- a/pallets/subtensor/src/macros/dispatches.rs
+++ b/pallets/subtensor/src/macros/dispatches.rs
@@ -2446,26 +2446,5 @@ mod dispatches {
});
Ok(())
}
-
- /// --- Set the mode for root alpha dividends on emission-suppressed subnets.
- /// - Disable: root gets no alpha; root alpha recycled to subnet validators.
- /// - Enable: root still accumulates alpha (old behaviour).
- /// - Recycle: root alpha swapped to TAO via AMM, TAO burned.
- #[pallet::call_index(135)]
- #[pallet::weight((
- Weight::from_parts(5_000_000, 0)
- .saturating_add(T::DbWeight::get().writes(1)),
- DispatchClass::Operational,
- Pays::No
- ))]
- pub fn sudo_set_root_sell_pressure_on_suppressed_subnets_mode(
- origin: OriginFor,
- mode: RootSellPressureOnSuppressedSubnetsMode,
- ) -> DispatchResult {
- ensure_root(origin)?;
- KeepRootSellPressureOnSuppressedSubnets::::put(mode);
- Self::deposit_event(Event::RootSellPressureOnSuppressedSubnetsModeSet { mode });
- Ok(())
- }
}
}
diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs
index 21398dd547..8afc1166bc 100644
--- a/pallets/subtensor/src/macros/events.rs
+++ b/pallets/subtensor/src/macros/events.rs
@@ -489,11 +489,5 @@ mod events {
/// The override value: Some(true) = force suppress, Some(false) = force unsuppress, None = cleared
override_value: Option,
},
-
- /// Root set the RootSellPressureOnSuppressedSubnetsModeSet.
- RootSellPressureOnSuppressedSubnetsModeSet {
- /// The new mode
- mode: RootSellPressureOnSuppressedSubnetsMode,
- },
}
}
diff --git a/pallets/subtensor/src/tests/emission_suppression.rs b/pallets/subtensor/src/tests/emission_suppression.rs
index 371c885e84..4dba195f2d 100644
--- a/pallets/subtensor/src/tests/emission_suppression.rs
+++ b/pallets/subtensor/src/tests/emission_suppression.rs
@@ -188,10 +188,10 @@ fn test_all_subnets_suppressed() {
}
// ─────────────────────────────────────────────────────────────────────────────
-// Test 7: Suppress subnet, Enable mode → root still gets alpha
+// Test 7: Suppressed subnet → root still accumulates alpha (hardcoded behavior)
// ─────────────────────────────────────────────────────────────────────────────
#[test]
-fn test_suppressed_subnet_root_alpha_by_default() {
+fn test_suppressed_subnet_root_alpha_accumulated() {
new_test_ext(1).execute_with(|| {
add_network(NetUid::ROOT, 1, 0);
let sn1 = NetUid::from(1);
@@ -217,12 +217,6 @@ fn test_suppressed_subnet_root_alpha_by_default() {
// Force-suppress sn1.
EmissionSuppressionOverride::::insert(sn1, true);
- // Default mode is Enable; this test uses it as-is.
- assert_eq!(
- KeepRootSellPressureOnSuppressedSubnets::::get(),
- RootSellPressureOnSuppressedSubnetsMode::Enable,
- );
-
// Clear any pending emissions.
PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
@@ -236,208 +230,13 @@ fn test_suppressed_subnet_root_alpha_by_default() {
let pending_root = PendingRootAlphaDivs::::get(sn1);
assert!(
pending_root > AlphaCurrency::ZERO,
- "with Enable mode, root should still get alpha on suppressed subnet"
- );
- });
-}
-
-// ─────────────────────────────────────────────────────────────────────────────
-// Test 8: Suppress subnet, Disable mode → root gets no alpha, validators get more
-// ─────────────────────────────────────────────────────────────────────────────
-#[test]
-fn test_suppressed_subnet_no_root_alpha_flag_off() {
- new_test_ext(1).execute_with(|| {
- add_network(NetUid::ROOT, 1, 0);
- let sn1 = NetUid::from(1);
- setup_subnet_with_flow(sn1, 10, 100_000_000);
-
- // Register a root validator and add stake on root so root_proportion > 0.
- let hotkey = U256::from(10);
- let coldkey = U256::from(11);
- assert_ok!(SubtensorModule::root_register(
- RuntimeOrigin::signed(coldkey),
- hotkey,
- ));
- SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
- &hotkey,
- &coldkey,
- NetUid::ROOT,
- 1_000_000_000u64.into(),
- );
- SubtensorModule::set_tao_weight(u64::MAX);
- setup_root_with_tao(sn1);
-
- // Force-suppress sn1.
- EmissionSuppressionOverride::::insert(sn1, true);
-
- // Set mode to Disable: no root sell pressure on suppressed subnets.
- KeepRootSellPressureOnSuppressedSubnets::::put(
- RootSellPressureOnSuppressedSubnetsMode::Disable,
- );
-
- // Clear any pending emissions.
- PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
- PendingValidatorEmission::::insert(sn1, AlphaCurrency::ZERO);
-
- // Build emission map.
- let mut subnet_emissions = BTreeMap::new();
- subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
-
- SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
-
- // Root should get NO alpha.
- let pending_root = PendingRootAlphaDivs::::get(sn1);
- assert_eq!(
- pending_root,
- AlphaCurrency::ZERO,
- "with Disable mode, root should get no alpha on suppressed subnet"
- );
-
- // Validator emission should be non-zero (root alpha recycled to validators).
- let pending_validator = PendingValidatorEmission::::get(sn1);
- assert!(
- pending_validator > AlphaCurrency::ZERO,
- "validators should receive recycled root alpha"
+ "root should still get alpha on suppressed subnet"
);
});
}
// ─────────────────────────────────────────────────────────────────────────────
-// Test 9: Disable mode actually recycles root alpha to validators
-// (validators get more than with Enable mode)
-// ─────────────────────────────────────────────────────────────────────────────
-#[test]
-fn test_disable_mode_recycles_root_alpha_to_validators() {
- new_test_ext(1).execute_with(|| {
- add_network(NetUid::ROOT, 1, 0);
- let sn1 = NetUid::from(1);
- setup_subnet_with_flow(sn1, 10, 100_000_000);
-
- let hotkey = U256::from(10);
- let coldkey = U256::from(11);
- assert_ok!(SubtensorModule::root_register(
- RuntimeOrigin::signed(coldkey),
- hotkey,
- ));
- SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
- &hotkey,
- &coldkey,
- NetUid::ROOT,
- 1_000_000_000u64.into(),
- );
- SubtensorModule::set_tao_weight(u64::MAX);
- setup_root_with_tao(sn1);
-
- // Force-suppress sn1.
- EmissionSuppressionOverride::::insert(sn1, true);
-
- let mut subnet_emissions = BTreeMap::new();
- subnet_emissions.insert(sn1, U96F32::from_num(1_000_000));
-
- // ── Run with Enable mode first to get baseline ──
- KeepRootSellPressureOnSuppressedSubnets::::put(
- RootSellPressureOnSuppressedSubnetsMode::Enable,
- );
- PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
- PendingValidatorEmission::::insert(sn1, AlphaCurrency::ZERO);
-
- SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
-
- let enable_validator = PendingValidatorEmission::::get(sn1);
- let enable_root = PendingRootAlphaDivs::::get(sn1);
-
- // In Enable mode, root should accumulate some alpha.
- assert!(
- enable_root > AlphaCurrency::ZERO,
- "Enable mode: root should get alpha"
- );
-
- // ── Now run with Disable mode ──
- KeepRootSellPressureOnSuppressedSubnets::::put(
- RootSellPressureOnSuppressedSubnetsMode::Disable,
- );
- PendingRootAlphaDivs::::insert(sn1, AlphaCurrency::ZERO);
- PendingValidatorEmission::::insert(sn1, AlphaCurrency::ZERO);
-
- SubtensorModule::emit_to_subnets(&[sn1], &subnet_emissions, true);
-
- let disable_validator = PendingValidatorEmission::::get(sn1);
- let disable_root = PendingRootAlphaDivs::::get(sn1);
-
- // In Disable mode, root should get nothing.
- assert_eq!(
- disable_root,
- AlphaCurrency::ZERO,
- "Disable mode: root should get no alpha"
- );
-
- // Disable validators should get MORE than Enable validators because
- // root alpha is recycled to them instead of going to root.
- assert!(
- disable_validator > enable_validator,
- "Disable mode validators ({disable_validator:?}) should get more \
- than Enable mode ({enable_validator:?}) because root alpha is recycled"
- );
-
- // The difference should equal the root alpha from Enable mode
- // (root alpha is recycled to validators instead).
- assert_eq!(
- disable_validator.saturating_sub(enable_validator),
- enable_root,
- "difference should equal the root alpha that was recycled"
- );
- });
-}
-
-// ─────────────────────────────────────────────────────────────────────────────
-// Test 10: Non-suppressed subnet → root alpha normal regardless of mode
-// ─────────────────────────────────────────────────────────────────────────────
-#[test]
-fn test_unsuppressed_subnet_unaffected_by_flag() {
- new_test_ext(1).execute_with(|| {
- add_network(NetUid::ROOT, 1, 0);
- let sn1 = NetUid::from(1);
- setup_subnet_with_flow(sn1, 10, 100_000_000);
-
- let hotkey = U256::from(10);
- let coldkey = U256::from(11);
- assert_ok!(SubtensorModule::root_register(
- RuntimeOrigin::signed(coldkey),
- hotkey,
- ));
- SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
- &hotkey,
- &coldkey,
- NetUid::ROOT,
- 1_000_000_000u64.into(),
- );
- SubtensorModule::set_tao_weight(u64::MAX);
- setup_root_with_tao(sn1);
-
- // sn1 is NOT suppressed.
- // Set mode to Disable (should not matter for unsuppressed subnets).
- KeepRootSellPressureOnSuppressedSubnets::