From 11f3db6ce1c3387f6e687f56cd6bab4d26f60d9d Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 11 Dec 2025 16:51:14 -0500 Subject: [PATCH 1/5] commit Cargo.lock --- pallets/subtensor/src/coinbase/run_coinbase.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 3b82ec86d5..a3862f72f3 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -124,6 +124,11 @@ impl Pallet { let mut alpha_in: BTreeMap = BTreeMap::new(); let mut alpha_out: BTreeMap = BTreeMap::new(); let mut excess_tao: BTreeMap = BTreeMap::new(); + let tao_block_emission: U96F32 = U96F32::saturating_from_num( + Self::get_block_emission() + .unwrap_or(TaoCurrency::ZERO) + .to_u64(), + ); // Only calculate for subnets that we are emitting to. for (&netuid_i, &tao_emission_i) in subnet_emissions.iter() { @@ -142,8 +147,9 @@ impl Pallet { let alpha_out_i: U96F32 = alpha_emission_i; let mut alpha_in_i: U96F32 = tao_emission_i.safe_div_or(price_i, U96F32::from_num(0.0)); - if alpha_in_i > alpha_emission_i { - alpha_in_i = alpha_emission_i; + let alpha_injection_cap: U96F32 = alpha_emission_i.min(tao_block_emission); + if alpha_in_i > alpha_injection_cap { + alpha_in_i = alpha_injection_cap; tao_in_i = alpha_in_i.saturating_mul(price_i); } From d75c79f7e8cbc51d674d1e64a52ecaa6e24be033 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 12 Dec 2025 00:46:07 -0500 Subject: [PATCH 2/5] bump spec --- runtime/src/lib.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 35272d9817..de785ada36 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -19,15 +19,15 @@ extern crate alloc; use codec::{Compact, Decode, Encode}; use ethereum::AuthorizationList; use frame_support::{ - PalletId, dispatch::DispatchResult, genesis_builder_helper::{build_state, get_preset}, pallet_prelude::Get, - traits::{Contains, InsideBoth, LinearStoragePrice, fungible::HoldConsideration}, + traits::{fungible::HoldConsideration, Contains, InsideBoth, LinearStoragePrice}, + PalletId, }; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use pallet_commitments::{CanCommit, OnMetadataCommitment}; -use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives}; +use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_registry::CanRegisterIdentity; pub use pallet_shield; use pallet_subtensor::rpc_info::{ @@ -49,18 +49,19 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_babe::BabeConfiguration; use sp_consensus_babe::BabeEpochConfiguration; use sp_core::{ - H160, H256, OpaqueMetadata, U256, crypto::{ByteArray, KeyTypeId}, + OpaqueMetadata, H160, H256, U256, }; -use sp_runtime::Cow; use sp_runtime::generic::Era; +use sp_runtime::Cow; use sp_runtime::{ - AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, generic, impl_opaque_keys, + generic, impl_opaque_keys, traits::{ AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, One, PostDispatchInfoOf, UniqueSaturatedInto, Verify, }, transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, + AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, }; use sp_std::cmp::Ordering; use sp_std::prelude::*; @@ -68,23 +69,24 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use subtensor_precompiles::Precompiles; -use subtensor_runtime_common::{AlphaCurrency, TaoCurrency, time::*, *}; +use subtensor_runtime_common::{time::*, AlphaCurrency, TaoCurrency, *}; use subtensor_swap_interface::{Order, SwapHandler}; // A few exports that help ease life for downstream crates. pub use frame_support::{ - StorageValue, construct_runtime, parameter_types, + construct_runtime, parameter_types, traits::{ - ConstBool, ConstU8, ConstU32, ConstU64, ConstU128, FindAuthor, InstanceFilter, + ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, FindAuthor, InstanceFilter, KeyOwnerProofSystem, OnFinalize, OnTimestampSet, PrivilegeCmp, Randomness, StorageInfo, }, weights::{ - IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, + IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, }, + StorageValue, }; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; @@ -237,7 +239,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 361, + spec_version: 362, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 5e0f925327edd38a12c02d7763667606251e52cd Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 12 Dec 2025 00:58:08 -0500 Subject: [PATCH 3/5] cargo fmt --- runtime/src/lib.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index de785ada36..9686a224b5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -19,15 +19,15 @@ extern crate alloc; use codec::{Compact, Decode, Encode}; use ethereum::AuthorizationList; use frame_support::{ + PalletId, dispatch::DispatchResult, genesis_builder_helper::{build_state, get_preset}, pallet_prelude::Get, - traits::{fungible::HoldConsideration, Contains, InsideBoth, LinearStoragePrice}, - PalletId, + traits::{Contains, InsideBoth, LinearStoragePrice, fungible::HoldConsideration}, }; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use pallet_commitments::{CanCommit, OnMetadataCommitment}; -use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives}; use pallet_registry::CanRegisterIdentity; pub use pallet_shield; use pallet_subtensor::rpc_info::{ @@ -49,19 +49,18 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_babe::BabeConfiguration; use sp_consensus_babe::BabeEpochConfiguration; use sp_core::{ + H160, H256, OpaqueMetadata, U256, crypto::{ByteArray, KeyTypeId}, - OpaqueMetadata, H160, H256, U256, }; -use sp_runtime::generic::Era; use sp_runtime::Cow; +use sp_runtime::generic::Era; use sp_runtime::{ - generic, impl_opaque_keys, + AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, generic, impl_opaque_keys, traits::{ AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, One, PostDispatchInfoOf, UniqueSaturatedInto, Verify, }, transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, - AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, }; use sp_std::cmp::Ordering; use sp_std::prelude::*; @@ -69,24 +68,23 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use subtensor_precompiles::Precompiles; -use subtensor_runtime_common::{time::*, AlphaCurrency, TaoCurrency, *}; +use subtensor_runtime_common::{AlphaCurrency, TaoCurrency, time::*, *}; use subtensor_swap_interface::{Order, SwapHandler}; // A few exports that help ease life for downstream crates. pub use frame_support::{ - construct_runtime, parameter_types, + StorageValue, construct_runtime, parameter_types, traits::{ - ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, FindAuthor, InstanceFilter, + ConstBool, ConstU8, ConstU32, ConstU64, ConstU128, FindAuthor, InstanceFilter, KeyOwnerProofSystem, OnFinalize, OnTimestampSet, PrivilegeCmp, Randomness, StorageInfo, }, weights::{ + IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, - IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, }, - StorageValue, }; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; From e960bbfb3f7e5a467253d7038c00c282854c9fba Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Fri, 12 Dec 2025 14:33:14 +0300 Subject: [PATCH 4/5] Add test for get_subnet_terms --- pallets/subtensor/src/tests/coinbase.rs | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index c7ad008c04..1498e0b423 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -3919,3 +3919,39 @@ fn test_pending_emission_start_call_not_done() { ); }); } + +#[test] +fn test_get_subnet_terms_alpha_emissions_cap() { + new_test_ext(1).execute_with(|| { + let owner_hotkey = U256::from(10); + let owner_coldkey = U256::from(11); + let netuid = add_dynamic_network(&owner_hotkey, &owner_coldkey); + let tao_block_emission: U96F32 = U96F32::saturating_from_num( + SubtensorModule::get_block_emission() + .unwrap_or(TaoCurrency::ZERO) + .to_u64(), + ); + + // price = 1.0 + // tao_block_emission = 1000000000 + // tao_block_emission == alpha_emission_i + // alpha_in_i <= alpha_injection_cap + let emissions1 = U96F32::from_num(100_000_000); + + let subnet_emissions1 = BTreeMap::from([(netuid, emissions1)]); + let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions1); + + assert_eq!(alpha_in.get(&netuid).copied().unwrap(), emissions1); + + // price = 1.0 + // tao_block_emission = 1000000000 + // tao_block_emission == alpha_emission_i + // alpha_in_i > alpha_injection_cap + let emissions2 = U96F32::from_num(10_000_000_000u64); + + let subnet_emissions2 = BTreeMap::from([(netuid, emissions2)]); + let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions2); + + assert_eq!(alpha_in.get(&netuid).copied().unwrap(), tao_block_emission); + }); +} From c7a81e2e88488233f5964b00f28d5b544464186b Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 15 Dec 2025 17:47:59 -0500 Subject: [PATCH 5/5] cargo fmt --- runtime/src/lib.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index f84bb49c55..9f54a46b54 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -19,15 +19,15 @@ extern crate alloc; use codec::{Compact, Decode, Encode}; use ethereum::AuthorizationList; use frame_support::{ + PalletId, dispatch::DispatchResult, genesis_builder_helper::{build_state, get_preset}, pallet_prelude::Get, - traits::{fungible::HoldConsideration, Contains, InsideBoth, LinearStoragePrice}, - PalletId, + traits::{Contains, InsideBoth, LinearStoragePrice, fungible::HoldConsideration}, }; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use pallet_commitments::{CanCommit, OnMetadataCommitment}; -use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives}; use pallet_registry::CanRegisterIdentity; pub use pallet_shield; use pallet_subtensor::rpc_info::{ @@ -49,19 +49,18 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_babe::BabeConfiguration; use sp_consensus_babe::BabeEpochConfiguration; use sp_core::{ + H160, H256, OpaqueMetadata, U256, crypto::{ByteArray, KeyTypeId}, - OpaqueMetadata, H160, H256, U256, }; -use sp_runtime::generic::Era; use sp_runtime::Cow; +use sp_runtime::generic::Era; use sp_runtime::{ - generic, impl_opaque_keys, + AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, generic, impl_opaque_keys, traits::{ AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, One, PostDispatchInfoOf, UniqueSaturatedInto, Verify, }, transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, - AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, }; use sp_std::cmp::Ordering; use sp_std::prelude::*; @@ -69,24 +68,23 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use subtensor_precompiles::Precompiles; -use subtensor_runtime_common::{time::*, AlphaCurrency, TaoCurrency, *}; +use subtensor_runtime_common::{AlphaCurrency, TaoCurrency, time::*, *}; use subtensor_swap_interface::{Order, SwapHandler}; // A few exports that help ease life for downstream crates. pub use frame_support::{ - construct_runtime, parameter_types, + StorageValue, construct_runtime, parameter_types, traits::{ - ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, FindAuthor, InstanceFilter, + ConstBool, ConstU8, ConstU32, ConstU64, ConstU128, FindAuthor, InstanceFilter, KeyOwnerProofSystem, OnFinalize, OnTimestampSet, PrivilegeCmp, Randomness, StorageInfo, }, weights::{ + IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, }, - IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, }, - StorageValue, }; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall;