Skip to content

Commit 675111c

Browse files
authored
Merge pull request #2294 from opentensor/fix-merge-conflicts-12-15-2025
Fix merge conflicts 12/15/2025
2 parents 25ab745 + c7a81e2 commit 675111c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ impl<T: Config> Pallet<T> {
124124
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
125125
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
126126
let mut excess_tao: BTreeMap<NetUid, U96F32> = BTreeMap::new();
127+
let tao_block_emission: U96F32 = U96F32::saturating_from_num(
128+
Self::get_block_emission()
129+
.unwrap_or(TaoCurrency::ZERO)
130+
.to_u64(),
131+
);
127132

128133
// Only calculate for subnets that we are emitting to.
129134
for (&netuid_i, &tao_emission_i) in subnet_emissions.iter() {
@@ -142,8 +147,9 @@ impl<T: Config> Pallet<T> {
142147
let alpha_out_i: U96F32 = alpha_emission_i;
143148
let mut alpha_in_i: U96F32 = tao_emission_i.safe_div_or(price_i, U96F32::from_num(0.0));
144149

145-
if alpha_in_i > alpha_emission_i {
146-
alpha_in_i = alpha_emission_i;
150+
let alpha_injection_cap: U96F32 = alpha_emission_i.min(tao_block_emission);
151+
if alpha_in_i > alpha_injection_cap {
152+
alpha_in_i = alpha_injection_cap;
147153
tao_in_i = alpha_in_i.saturating_mul(price_i);
148154
}
149155

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,3 +3980,39 @@ fn test_root_proportion() {
39803980
assert_eq!(actual_root_proportion, expected_root_prop);
39813981
});
39823982
}
3983+
3984+
#[test]
3985+
fn test_get_subnet_terms_alpha_emissions_cap() {
3986+
new_test_ext(1).execute_with(|| {
3987+
let owner_hotkey = U256::from(10);
3988+
let owner_coldkey = U256::from(11);
3989+
let netuid = add_dynamic_network(&owner_hotkey, &owner_coldkey);
3990+
let tao_block_emission: U96F32 = U96F32::saturating_from_num(
3991+
SubtensorModule::get_block_emission()
3992+
.unwrap_or(TaoCurrency::ZERO)
3993+
.to_u64(),
3994+
);
3995+
3996+
// price = 1.0
3997+
// tao_block_emission = 1000000000
3998+
// tao_block_emission == alpha_emission_i
3999+
// alpha_in_i <= alpha_injection_cap
4000+
let emissions1 = U96F32::from_num(100_000_000);
4001+
4002+
let subnet_emissions1 = BTreeMap::from([(netuid, emissions1)]);
4003+
let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions1);
4004+
4005+
assert_eq!(alpha_in.get(&netuid).copied().unwrap(), emissions1);
4006+
4007+
// price = 1.0
4008+
// tao_block_emission = 1000000000
4009+
// tao_block_emission == alpha_emission_i
4010+
// alpha_in_i > alpha_injection_cap
4011+
let emissions2 = U96F32::from_num(10_000_000_000u64);
4012+
4013+
let subnet_emissions2 = BTreeMap::from([(netuid, emissions2)]);
4014+
let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions2);
4015+
4016+
assert_eq!(alpha_in.get(&netuid).copied().unwrap(), tao_block_emission);
4017+
});
4018+
}

0 commit comments

Comments
 (0)