@@ -46,26 +46,22 @@ impl<T: Config> Pallet<T> {
46
46
let subnets: Vec < u16 > = Self :: get_all_subnet_netuids ( ) ;
47
47
log:: debug!( "All subnet netuids: {:?}" , subnets) ;
48
48
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 ( ) ;
54
53
for netuid in subnets. iter ( ) {
55
54
if * netuid == 0 {
56
55
continue ;
57
56
} // Skip root network
58
57
let mechid = SubnetMechanism :: < T > :: get ( * netuid) ;
59
58
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) ;
67
63
}
68
- log:: debug!( "Mechanism TAO sums: {:?}" , mechanism_weight ) ;
64
+ log:: debug!( "Mechanism TAO sums: {:?}" , mechanism_tao ) ;
69
65
70
66
// --- 3. Compute subnet emission values (amount of tao inflation this block).
71
67
let mut tao_in_map: BTreeMap < u16 , u64 > = BTreeMap :: new ( ) ;
@@ -81,15 +77,15 @@ impl<T: Config> Pallet<T> {
81
77
let subnet_tao: I96F32 = I96F32 :: from_num ( SubnetTAO :: < T > :: get ( * netuid) ) ;
82
78
log:: debug!( "Subnet TAO (T_s) for netuid {:?}: {:?}" , netuid, subnet_tao) ;
83
79
// 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 ) ) ;
85
81
log:: debug!(
86
82
"Mechanism TAO (T_m) for mechanism ID {:?}: {:?}" ,
87
83
mechid,
88
84
mech_tao
89
85
) ;
90
86
// 3.4: Compute the mechanism emission proportion: P_m = T_m / T_total
91
87
let mech_proportion: I96F32 = mech_tao
92
- . checked_div ( total_active_weight )
88
+ . checked_div ( total_active_tao )
93
89
. unwrap_or ( I96F32 :: from_num ( 0 ) ) ;
94
90
log:: debug!(
95
91
"Mechanism proportion (P_m) for mechanism ID {:?}: {:?}" ,
0 commit comments