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