Skip to content

Commit f778f91

Browse files
author
unconst
committed
small changes
1 parent 0d9be95 commit f778f91

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,22 @@ impl<T: Config> Pallet<T> {
4646
let subnets: Vec<u16> = Self::get_all_subnet_netuids();
4747
log::debug!("All subnet netuids: {:?}", subnets);
4848

49-
/// Calculates the total active weight and mechanism weights for emission distribution.
50-
/// For each subnet (except root), sums the SubnetTAO and a portion of the total stake at dynamic registration
51-
/// into mechanism-specific weights. The mechanism weights determine emission proportions.
52-
let mut total_active_weight: I96F32 = I96F32::from_num(0);
53-
let mut mechanism_weight: BTreeMap<u16, I96F32> = BTreeMap::new();
49+
// --- 2. Sum all the SubnetTAO associated with the same mechanism.
50+
// Mechanisms get emission based on the proportion of TAO across all their subnets
51+
let mut total_active_tao: I96F32 = I96F32::from_num(0);
52+
let mut mechanism_tao: BTreeMap<u16, I96F32> = BTreeMap::new();
5453
for netuid in subnets.iter() {
5554
if *netuid == 0 {
5655
continue;
5756
} // Skip root network
5857
let mechid = SubnetMechanism::<T>::get(*netuid);
5958
let subnet_tao = I96F32::from_num(SubnetTAO::<T>::get(*netuid));
60-
let tao_at_dynamic = I96F32::from_num( TotalStakeAtDynamic::<T>::get(*netuid) );
61-
let num_subnets = I96F32::from_num( Self::get_num_subnets() as u64 );
62-
let subnet_weight = subnet_tao.saturating_add( tao_at_dynamic.checked_div( num_subnets ).unwrap_or(I96F32::from_num( 0.0)) );
63-
let new_subnet_weight = subnet_weight
64-
.saturating_add(*mechanism_weight.entry(mechid).or_insert(I96F32::from_num(0)));
65-
*mechanism_weight.entry(mechid).or_insert(I96F32::from_num(0)) = new_subnet_weight;
66-
total_active_weight = total_active_weight.saturating_add(subnet_weight);
59+
let new_subnet_tao = subnet_tao
60+
.saturating_add(*mechanism_tao.entry(mechid).or_insert(I96F32::from_num(0)));
61+
*mechanism_tao.entry(mechid).or_insert(I96F32::from_num(0)) = new_subnet_tao;
62+
total_active_tao = total_active_tao.saturating_add(subnet_tao);
6763
}
68-
log::debug!("Mechanism TAO sums: {:?}", mechanism_weight);
64+
log::debug!("Mechanism TAO sums: {:?}", mechanism_tao);
6965

7066
// --- 3. Compute subnet emission values (amount of tao inflation this block).
7167
let mut tao_in_map: BTreeMap<u16, u64> = BTreeMap::new();
@@ -81,15 +77,15 @@ impl<T: Config> Pallet<T> {
8177
let subnet_tao: I96F32 = I96F32::from_num(SubnetTAO::<T>::get(*netuid));
8278
log::debug!("Subnet TAO (T_s) for netuid {:?}: {:?}", netuid, subnet_tao);
8379
// 3.3: Get the denominator as the sum of all TAO associated with a specific mechanism (T_m)
84-
let mech_tao: I96F32 = *mechanism_weight.get(&mechid).unwrap_or(&I96F32::from_num(0));
80+
let mech_tao: I96F32 = *mechanism_tao.get(&mechid).unwrap_or(&I96F32::from_num(0));
8581
log::debug!(
8682
"Mechanism TAO (T_m) for mechanism ID {:?}: {:?}",
8783
mechid,
8884
mech_tao
8985
);
9086
// 3.4: Compute the mechanism emission proportion: P_m = T_m / T_total
9187
let mech_proportion: I96F32 = mech_tao
92-
.checked_div(total_active_weight)
88+
.checked_div(total_active_tao)
9389
.unwrap_or(I96F32::from_num(0));
9490
log::debug!(
9591
"Mechanism proportion (P_m) for mechanism ID {:?}: {:?}",

0 commit comments

Comments
 (0)