Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ impl<T: Config> Pallet<T> {
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
let mut excess_tao: BTreeMap<NetUid, U96F32> = 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() {
Expand All @@ -142,8 +147,9 @@ impl<T: Config> Pallet<T> {
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);
}

Expand Down
36 changes: 36 additions & 0 deletions pallets/subtensor/src/tests/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading