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); } 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); + }); +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 35272d9817..9686a224b5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -237,7 +237,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,