diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 8d1d735052..2209ea7295 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -512,7 +512,7 @@ pub mod pallet { /// The extrinsic will call the Subtensor pallet to set the maximum allowed UIDs for a subnet. #[pallet::call_index(15)] #[pallet::weight(Weight::from_parts(32_140_000, 0) - .saturating_add(::DbWeight::get().reads(5_u64)) + .saturating_add(::DbWeight::get().reads(6_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_allowed_uids( origin: OriginFor, diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 8a6f8d757d..b370b6dbe1 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -1723,7 +1723,7 @@ mod pallet_benchmarks { } #[benchmark] - fn subnet_buyback() { + fn add_stake_burn() { let netuid = NetUid::from(1); let tempo: u16 = 1; let seed: u32 = 1; diff --git a/pallets/subtensor/src/extensions/subtensor.rs b/pallets/subtensor/src/extensions/subtensor.rs index 798f30dbe8..a24a54f3fd 100644 --- a/pallets/subtensor/src/extensions/subtensor.rs +++ b/pallets/subtensor/src/extensions/subtensor.rs @@ -20,7 +20,7 @@ use sp_std::vec::Vec; use subtensor_macros::freeze_struct; use subtensor_runtime_common::{NetUid, NetUidStorageIndex}; -const SUBNET_BUYBACK_PRIORITY_BOOST: u64 = 100; +const ADD_STAKE_BURN_PRIORITY_BOOST: u64 = 100; type CallOf = ::RuntimeCall; type OriginOf = ::RuntimeOrigin; @@ -297,12 +297,12 @@ where .map_err(|_| CustomTransactionError::EvmKeyAssociateRateLimitExceeded)?; Ok((Default::default(), (), origin)) } - Some(Call::subnet_buyback { netuid, .. }) => { + Some(Call::add_stake_burn { netuid, .. }) => { Pallet::::ensure_subnet_owner(origin.clone(), *netuid).map_err(|_| { TransactionValidityError::Invalid(InvalidTransaction::BadSigner) })?; - Ok((Self::validity_ok(SUBNET_BUYBACK_PRIORITY_BOOST), (), origin)) + Ok((Self::validity_ok(ADD_STAKE_BURN_PRIORITY_BOOST), (), origin)) } _ => Ok((Default::default(), (), origin)), } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index ba7e3dcbf6..69645c0419 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2722,9 +2722,9 @@ pub enum RateLimitKey { // Last tx block delegate key limit per account ID #[codec(index = 5)] LastTxBlockDelegateTake(AccountId), - // Subnet buyback rate limit + // "Add stake and burn" rate limit #[codec(index = 6)] - SubnetBuyback(NetUid), + AddStakeBurn(NetUid), } pub trait ProxyInterface { diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 88b6a3f0ec..7cfb224722 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2580,8 +2580,8 @@ mod dispatches { Self::do_set_voting_power_ema_alpha(netuid, alpha) } - /// --- Subnet buyback: the extrinsic is a combination of add_stake(add_stake_limit) and - /// burn_alpha. We buy alpha token first and immediately burn the acquired amount of alpha. + /// --- The extrinsic is a combination of add_stake(add_stake_limit) and burn_alpha. We buy + /// alpha token first and immediately burn the acquired amount of alpha (aka Subnet buyback). #[pallet::call_index(132)] #[pallet::weight(( Weight::from_parts(368_000_000, 8556) @@ -2590,14 +2590,14 @@ mod dispatches { DispatchClass::Normal, Pays::Yes ))] - pub fn subnet_buyback( + pub fn add_stake_burn( origin: T::RuntimeOrigin, hotkey: T::AccountId, netuid: NetUid, amount: TaoCurrency, limit: Option, ) -> DispatchResult { - Self::do_subnet_buyback(origin, hotkey, netuid, amount, limit) + Self::do_add_stake_burn(origin, hotkey, netuid, amount, limit) } } } diff --git a/pallets/subtensor/src/macros/errors.rs b/pallets/subtensor/src/macros/errors.rs index f74a7657d8..7d50373f19 100644 --- a/pallets/subtensor/src/macros/errors.rs +++ b/pallets/subtensor/src/macros/errors.rs @@ -280,7 +280,7 @@ mod errors { PrecisionLoss, /// Deprecated call. Deprecated, - /// Subnet buyback exceeded the operation rate limit - SubnetBuybackRateLimitExceeded, + /// "Add stake and burn" exceeded the operation rate limit + AddStakeBurnRateLimitExceeded, } } diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs index 9f0c2bdfd5..65c33aee87 100644 --- a/pallets/subtensor/src/macros/events.rs +++ b/pallets/subtensor/src/macros/events.rs @@ -517,8 +517,8 @@ mod events { alpha: AlphaCurrency, }, - /// Subnet buyback event: alpha token was purchased and burned. - SubnetBuyback { + /// "Add stake and burn" event: alpha token was purchased and burned. + AddStakeBurn { /// The subnet ID netuid: NetUid, /// hotky account ID diff --git a/pallets/subtensor/src/staking/recycle_alpha.rs b/pallets/subtensor/src/staking/recycle_alpha.rs index 4dd362028e..b77982fa31 100644 --- a/pallets/subtensor/src/staking/recycle_alpha.rs +++ b/pallets/subtensor/src/staking/recycle_alpha.rs @@ -136,7 +136,7 @@ impl Pallet { Ok(()) } - pub(crate) fn do_subnet_buyback( + pub(crate) fn do_add_stake_burn( origin: T::RuntimeOrigin, hotkey: T::AccountId, netuid: NetUid, @@ -146,12 +146,12 @@ impl Pallet { Self::ensure_subnet_owner(origin.clone(), netuid)?; let current_block = Self::get_current_block_as_u64(); - let last_block = Self::get_rate_limited_last_block(&RateLimitKey::SubnetBuyback(netuid)); - let rate_limit = TransactionType::SubnetBuyback.rate_limit_on_subnet::(netuid); + let last_block = Self::get_rate_limited_last_block(&RateLimitKey::AddStakeBurn(netuid)); + let rate_limit = TransactionType::AddStakeBurn.rate_limit_on_subnet::(netuid); ensure!( last_block.is_zero() || current_block.saturating_sub(last_block) >= rate_limit, - Error::::SubnetBuybackRateLimitExceeded + Error::::AddStakeBurnRateLimitExceeded ); let alpha = if let Some(limit) = limit { @@ -162,9 +162,9 @@ impl Pallet { Self::do_burn_alpha(origin, hotkey.clone(), alpha, netuid)?; - Self::set_rate_limited_last_block(&RateLimitKey::SubnetBuyback(netuid), current_block); + Self::set_rate_limited_last_block(&RateLimitKey::AddStakeBurn(netuid), current_block); - Self::deposit_event(Event::SubnetBuyback { + Self::deposit_event(Event::AddStakeBurn { netuid, hotkey, amount, diff --git a/pallets/subtensor/src/tests/recycle_alpha.rs b/pallets/subtensor/src/tests/recycle_alpha.rs index a49a029805..5cf589de97 100644 --- a/pallets/subtensor/src/tests/recycle_alpha.rs +++ b/pallets/subtensor/src/tests/recycle_alpha.rs @@ -620,7 +620,7 @@ fn test_burn_precision_loss() { } #[test] -fn test_subnet_buyback_success() { +fn test_add_stake_burn_success() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(533453); let coldkey_account_id = U256::from(55453); @@ -642,8 +642,8 @@ fn test_subnet_buyback_success() { TaoCurrency::ZERO ); - // Execute subnet_buyback - this stakes TAO to get Alpha, then burns the Alpha - assert_ok!(SubtensorModule::subnet_buyback( + // Execute add_stake_burn - this stakes TAO to get Alpha, then burns the Alpha + assert_ok!(SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, netuid, @@ -651,7 +651,7 @@ fn test_subnet_buyback_success() { None, )); - // After buyback, hotkey should have zero stake since alpha is burned immediately + // After "add stake and burn", hotkey should have zero stake since alpha is burned immediately assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), TaoCurrency::ZERO @@ -672,18 +672,18 @@ fn test_subnet_buyback_success() { ) })); - // Verify SubnetBuyback event was emitted + // Verify AddStakeBurn event was emitted assert!(System::events().iter().any(|e| { matches!( &e.event, - RuntimeEvent::SubtensorModule(Event::SubnetBuyback { .. }) + RuntimeEvent::SubtensorModule(Event::AddStakeBurn { .. }) ) })); }); } #[test] -fn test_subnet_buyback_with_limit_success() { +fn test_add_stake_burn_with_limit_success() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(533453); let coldkey_account_id = U256::from(55453); @@ -711,8 +711,8 @@ fn test_subnet_buyback_with_limit_success() { // With 100 TAO into 1000/1000 pool, price moves from 1.0 to ~1.21 let limit_price = TaoCurrency::from(2_000_000_000); // 2.0 TAO per Alpha - // Execute subnet_buyback with limit - assert_ok!(SubtensorModule::subnet_buyback( + // Execute add_stake_burn with limit + assert_ok!(SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, netuid, @@ -720,7 +720,7 @@ fn test_subnet_buyback_with_limit_success() { Some(limit_price), )); - // After buyback, hotkey should have zero stake since alpha is burned immediately + // After "add stake and burn", hotkey should have zero stake since alpha is burned immediately assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), TaoCurrency::ZERO @@ -753,7 +753,7 @@ fn test_subnet_buyback_with_limit_success() { } #[test] -fn test_subnet_buyback_non_owner_fails() { +fn test_add_stake_burn_non_owner_fails() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(2); @@ -772,9 +772,9 @@ fn test_subnet_buyback_non_owner_fails() { // Give non-owner some balance SubtensorModule::add_balance_to_coldkey_account(&non_owner_coldkey, amount); - // Non-owner trying to call subnet_buyback should fail with BadOrigin + // Non-owner trying to call add_stake_burn should fail with BadOrigin assert_noop!( - SubtensorModule::subnet_buyback( + SubtensorModule::add_stake_burn( RuntimeOrigin::signed(non_owner_coldkey), hotkey_account_id, netuid, @@ -787,7 +787,7 @@ fn test_subnet_buyback_non_owner_fails() { } #[test] -fn test_subnet_buyback_nonexistent_subnet_fails() { +fn test_add_stake_burn_nonexistent_subnet_fails() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(2); @@ -796,10 +796,10 @@ fn test_subnet_buyback_nonexistent_subnet_fails() { // Give some balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, amount); - // Try to call subnet_buyback on non-existent subnet + // Try to call add_stake_burn on non-existent subnet let nonexistent_netuid = NetUid::from(999); assert_noop!( - SubtensorModule::subnet_buyback( + SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, nonexistent_netuid, @@ -812,7 +812,7 @@ fn test_subnet_buyback_nonexistent_subnet_fails() { } #[test] -fn test_subnet_buyback_insufficient_balance_fails() { +fn test_add_stake_burn_insufficient_balance_fails() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(2); @@ -827,9 +827,9 @@ fn test_subnet_buyback_insufficient_balance_fails() { (amount * 10_000_000).into(), ); - // Try to call subnet_buyback without sufficient balance + // Try to call add_stake_burn without sufficient balance assert_noop!( - SubtensorModule::subnet_buyback( + SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, netuid, @@ -842,7 +842,7 @@ fn test_subnet_buyback_insufficient_balance_fails() { } #[test] -fn test_subnet_buyback_rate_limit_exceeded() { +fn test_add_stake_burn_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(533453); let coldkey_account_id = U256::from(55453); @@ -856,16 +856,16 @@ fn test_subnet_buyback_rate_limit_exceeded() { let alpha_in = AlphaCurrency::from(1_000_000_000_000); mock::setup_reserves(netuid, tao_reserve, alpha_in); - // Give coldkey sufficient balance for multiple buybacks + // Give coldkey sufficient balance for multiple "add stake and burn" operations. SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, amount * 10); assert_eq!( - SubtensorModule::get_rate_limited_last_block(&RateLimitKey::SubnetBuyback(netuid)), + SubtensorModule::get_rate_limited_last_block(&RateLimitKey::AddStakeBurn(netuid)), 0 ); - // First buyback should succeed - assert_ok!(SubtensorModule::subnet_buyback( + // First "add stake and burn" should succeed + assert_ok!(SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, netuid, @@ -874,27 +874,27 @@ fn test_subnet_buyback_rate_limit_exceeded() { )); assert_eq!( - SubtensorModule::get_rate_limited_last_block(&RateLimitKey::SubnetBuyback(netuid)), + SubtensorModule::get_rate_limited_last_block(&RateLimitKey::AddStakeBurn(netuid)), SubtensorModule::get_current_block_as_u64() ); - // Second buyback immediately after should fail due to rate limit + // Second "add stake and burn" immediately after should fail due to rate limit assert_noop!( - SubtensorModule::subnet_buyback( + SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, netuid, amount.into(), None, ), - Error::::SubnetBuybackRateLimitExceeded + Error::::AddStakeBurnRateLimitExceeded ); - // After stepping past the rate limit, buyback should succeed again - let rate_limit = TransactionType::SubnetBuyback.rate_limit_on_subnet::(netuid); + // After stepping past the rate limit, "add stake and burn" should succeed again + let rate_limit = TransactionType::AddStakeBurn.rate_limit_on_subnet::(netuid); step_block(rate_limit as u16); - assert_ok!(SubtensorModule::subnet_buyback( + assert_ok!(SubtensorModule::add_stake_burn( RuntimeOrigin::signed(coldkey_account_id), hotkey_account_id, netuid, diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index a5de73c417..0649b3b9e3 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -16,7 +16,7 @@ pub enum TransactionType { MechanismCountUpdate, MechanismEmission, MaxUidsTrimming, - SubnetBuyback, + AddStakeBurn, } impl TransactionType { @@ -45,7 +45,7 @@ impl TransactionType { (Tempo::::get(netuid) as u64).saturating_mul(epochs) } Self::SetSNOwnerHotkey => DefaultSetSNOwnerHotkeyRateLimit::::get(), - Self::SubnetBuyback => Tempo::::get(netuid) as u64, + Self::AddStakeBurn => Tempo::::get(netuid) as u64, _ => self.rate_limit::(), } @@ -143,7 +143,7 @@ impl From for u16 { TransactionType::MechanismCountUpdate => 7, TransactionType::MechanismEmission => 8, TransactionType::MaxUidsTrimming => 9, - TransactionType::SubnetBuyback => 10, + TransactionType::AddStakeBurn => 10, } } } @@ -161,7 +161,7 @@ impl From for TransactionType { 7 => TransactionType::MechanismCountUpdate, 8 => TransactionType::MechanismEmission, 9 => TransactionType::MaxUidsTrimming, - 10 => TransactionType::SubnetBuyback, + 10 => TransactionType::AddStakeBurn, _ => TransactionType::Unknown, } }