Skip to content

Commit 8834a7c

Browse files
authored
Merge pull request #2281 from opentensor/alpha_injection_cap
Alpha injection cap
2 parents 52378dc + e960bbf commit 8834a7c

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
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
@@ -3919,3 +3919,39 @@ fn test_pending_emission_start_call_not_done() {
39193919
);
39203920
});
39213921
}
3922+
3923+
#[test]
3924+
fn test_get_subnet_terms_alpha_emissions_cap() {
3925+
new_test_ext(1).execute_with(|| {
3926+
let owner_hotkey = U256::from(10);
3927+
let owner_coldkey = U256::from(11);
3928+
let netuid = add_dynamic_network(&owner_hotkey, &owner_coldkey);
3929+
let tao_block_emission: U96F32 = U96F32::saturating_from_num(
3930+
SubtensorModule::get_block_emission()
3931+
.unwrap_or(TaoCurrency::ZERO)
3932+
.to_u64(),
3933+
);
3934+
3935+
// price = 1.0
3936+
// tao_block_emission = 1000000000
3937+
// tao_block_emission == alpha_emission_i
3938+
// alpha_in_i <= alpha_injection_cap
3939+
let emissions1 = U96F32::from_num(100_000_000);
3940+
3941+
let subnet_emissions1 = BTreeMap::from([(netuid, emissions1)]);
3942+
let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions1);
3943+
3944+
assert_eq!(alpha_in.get(&netuid).copied().unwrap(), emissions1);
3945+
3946+
// price = 1.0
3947+
// tao_block_emission = 1000000000
3948+
// tao_block_emission == alpha_emission_i
3949+
// alpha_in_i > alpha_injection_cap
3950+
let emissions2 = U96F32::from_num(10_000_000_000u64);
3951+
3952+
let subnet_emissions2 = BTreeMap::from([(netuid, emissions2)]);
3953+
let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions2);
3954+
3955+
assert_eq!(alpha_in.get(&netuid).copied().unwrap(), tao_block_emission);
3956+
});
3957+
}

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
237237
// `spec_version`, and `authoring_version` are the same between Wasm and native.
238238
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
239239
// the compatible custom types.
240-
spec_version: 361,
240+
spec_version: 362,
241241
impl_version: 1,
242242
apis: RUNTIME_API_VERSIONS,
243243
transaction_version: 1,

0 commit comments

Comments
 (0)