From 30c7c536a2cc4ff2ad3e200fad6bc710ac7d837e Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Tue, 16 Dec 2025 07:06:04 +0100 Subject: [PATCH 1/8] Fix SubnetAlphaOut recycling in recycle_alpha.rs --- pallets/subtensor/src/staking/recycle_alpha.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pallets/subtensor/src/staking/recycle_alpha.rs b/pallets/subtensor/src/staking/recycle_alpha.rs index 7334c8126a..9591d4b4a6 100644 --- a/pallets/subtensor/src/staking/recycle_alpha.rs +++ b/pallets/subtensor/src/staking/recycle_alpha.rs @@ -55,6 +55,8 @@ impl Pallet { &hotkey, &coldkey, netuid, amount, ); + SubnetAlphaOut::::mutate(netuid, |val| *val = val.saturating_sub(amount)); + // Recycle means we should decrease the alpha issuance tracker. Self::recycle_subnet_alpha(netuid, amount); @@ -120,6 +122,8 @@ impl Pallet { &hotkey, &coldkey, netuid, amount, ); + SubnetAlphaOut::::mutate(netuid, |val| *val = val.saturating_sub(amount)); + Self::burn_subnet_alpha(netuid, amount); // Deposit event From 1db86333e7181f15ce46bc156a5f88063029b8fb Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Tue, 16 Dec 2025 14:22:10 +0100 Subject: [PATCH 2/8] Fix: Use actual_alpha_decrease in recycle and revert manual SubnetAlphaOut decr --- pallets/subtensor/src/staking/recycle_alpha.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pallets/subtensor/src/staking/recycle_alpha.rs b/pallets/subtensor/src/staking/recycle_alpha.rs index 9591d4b4a6..8e851f225c 100644 --- a/pallets/subtensor/src/staking/recycle_alpha.rs +++ b/pallets/subtensor/src/staking/recycle_alpha.rs @@ -55,10 +55,8 @@ impl Pallet { &hotkey, &coldkey, netuid, amount, ); - SubnetAlphaOut::::mutate(netuid, |val| *val = val.saturating_sub(amount)); - // Recycle means we should decrease the alpha issuance tracker. - Self::recycle_subnet_alpha(netuid, amount); + Self::recycle_subnet_alpha(netuid, actual_alpha_decrease); Self::deposit_event(Event::AlphaRecycled( coldkey, @@ -122,8 +120,6 @@ impl Pallet { &hotkey, &coldkey, netuid, amount, ); - SubnetAlphaOut::::mutate(netuid, |val| *val = val.saturating_sub(amount)); - Self::burn_subnet_alpha(netuid, amount); // Deposit event From 936f41f6bcf1afa13c0fcfa23a40f90640125298 Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Tue, 16 Dec 2025 14:43:54 +0100 Subject: [PATCH 3/8] chore: Update CI Rust toolchain to 1.89.0 to fix cargo-audit --- .github/workflows/cargo-audit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cargo-audit.yml b/.github/workflows/cargo-audit.yml index 9bd9795f17..c3891a8230 100644 --- a/.github/workflows/cargo-audit.yml +++ b/.github/workflows/cargo-audit.yml @@ -27,7 +27,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: 1.89.0 - name: Utilize Shared Rust Cache uses: Swatinem/rust-cache@v2 From a8e123b7479960764911ed2f3f40ce7de7dcb86a Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Tue, 16 Dec 2025 20:47:50 +0100 Subject: [PATCH 4/8] Revert cargo-audit toolchain to stable per maintainer feedback --- .github/workflows/cargo-audit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cargo-audit.yml b/.github/workflows/cargo-audit.yml index c3891a8230..9bd9795f17 100644 --- a/.github/workflows/cargo-audit.yml +++ b/.github/workflows/cargo-audit.yml @@ -27,7 +27,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.89.0 + toolchain: stable - name: Utilize Shared Rust Cache uses: Swatinem/rust-cache@v2 From 011903674d982645a66038fcf6c70207a56a78f8 Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Tue, 16 Dec 2025 21:50:25 +0100 Subject: [PATCH 5/8] Revert recycle_subnet_alpha argument to 'amount' per maintainer review --- pallets/subtensor/src/staking/recycle_alpha.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/staking/recycle_alpha.rs b/pallets/subtensor/src/staking/recycle_alpha.rs index 8e851f225c..7334c8126a 100644 --- a/pallets/subtensor/src/staking/recycle_alpha.rs +++ b/pallets/subtensor/src/staking/recycle_alpha.rs @@ -56,7 +56,7 @@ impl Pallet { ); // Recycle means we should decrease the alpha issuance tracker. - Self::recycle_subnet_alpha(netuid, actual_alpha_decrease); + Self::recycle_subnet_alpha(netuid, amount); Self::deposit_event(Event::AlphaRecycled( coldkey, From 0f4fcf21ddafd3f6800418ed135217a73d6f93c1 Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Tue, 16 Dec 2025 22:45:08 +0100 Subject: [PATCH 6/8] Fix accounting: Decrement TotalStake in recycle_subnet_alpha and add burn helper --- pallets/subtensor/src/lib.rs | 23 +++++++++++++++++++++++ pallets/subtensor/src/staking/helpers.rs | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index ce0781b536..be2f211365 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2396,6 +2396,29 @@ pub mod pallet { total_stake >= Self::get_stake_threshold() } + pub fn burn_tokens_and_update_stake( + hotkey: &T::AccountId, + amount: TaoCurrency, + ) -> DispatchResult { + use frame_support::traits::tokens::{Precision, Preservation}; + use frame_support::traits::tokens::fungible::Mutate; + + // 1. Burn from Balances (Correctly updates TotalIssuance) + ::Currency::burn_from( + hotkey, + amount.into(), + Precision::Exact, + Preservation::Expendable, + )?; + + // 2. Decrement TotalStake + TotalStake::::mutate(|total| { + *total = total.saturating_sub(amount); + }); + + Ok(()) + } + /// Helper function to check if register is allowed pub fn checked_allowed_register(netuid: NetUid) -> bool { if netuid.is_root() { diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 1176064e36..dc871293ce 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -324,6 +324,10 @@ impl Pallet { SubnetAlphaOut::::mutate(netuid, |total| { *total = total.saturating_sub(amount); }); + // Keep TotalStake in sync + TotalStake::::mutate(|total| { + *total = total.saturating_sub(amount.into()); + }); } /// The function clears Alpha map in batches. Each run will check ALPHA_MAP_BATCH_SIZE From 05361b95bef31e1ac0a2621d26425b0251b2006f Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Wed, 17 Dec 2025 06:35:23 +0100 Subject: [PATCH 7/8] Remove unused burn_tokens_and_update_stake function --- pallets/subtensor/src/lib.rs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index be2f211365..a2ba7da005 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2396,28 +2396,7 @@ pub mod pallet { total_stake >= Self::get_stake_threshold() } - pub fn burn_tokens_and_update_stake( - hotkey: &T::AccountId, - amount: TaoCurrency, - ) -> DispatchResult { - use frame_support::traits::tokens::{Precision, Preservation}; - use frame_support::traits::tokens::fungible::Mutate; - - // 1. Burn from Balances (Correctly updates TotalIssuance) - ::Currency::burn_from( - hotkey, - amount.into(), - Precision::Exact, - Preservation::Expendable, - )?; - - // 2. Decrement TotalStake - TotalStake::::mutate(|total| { - *total = total.saturating_sub(amount); - }); - Ok(()) - } /// Helper function to check if register is allowed pub fn checked_allowed_register(netuid: NetUid) -> bool { From 27c67c8366d2bb1b442bed55b6d218dcf1df89b5 Mon Sep 17 00:00:00 2001 From: Dairus01 Date: Wed, 17 Dec 2025 06:48:05 +0100 Subject: [PATCH 8/8] Fix E0277: Convert AlphaCurrency to u64 before casting to TaoCurrency in TotalStake update --- pallets/subtensor/src/staking/helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index dc871293ce..fc57ad2641 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -326,7 +326,7 @@ impl Pallet { }); // Keep TotalStake in sync TotalStake::::mutate(|total| { - *total = total.saturating_sub(amount.into()); + *total = total.saturating_sub(amount.to_u64().into()); }); }