@@ -167,17 +167,25 @@ impl<T: Config> Pallet<T> {
167
167
inplace_col_normalize ( & mut bonds) ; // sum_i b_ij = 1
168
168
log:: trace!( "B:\n {:?}\n " , & bonds) ;
169
169
170
- // Compute bonds delta column normalized.
171
- let mut bonds_delta: Vec < Vec < I32F32 > > = row_hadamard ( & weights, & active_stake) ; // ΔB = W◦S
172
- inplace_col_normalize ( & mut bonds_delta) ; // sum_i b_ij = 1
173
- log:: trace!( "ΔB:\n {:?}\n " , & bonds_delta) ;
174
170
// Compute the Exponential Moving Average (EMA) of bonds.
175
- let mut ema_bonds = Self :: compute_ema_bonds ( netuid, consensus. clone ( ) , bonds_delta, bonds) ;
171
+ // Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values.
172
+ let mut ema_bonds = if let Some ( clamped_bonds_alpha) =
173
+ Self :: compute_liquid_alpha ( netuid, consensus. clone ( ) )
174
+ {
175
+ // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values.
176
+ Self :: compute_ema_bonds_with_liquid_alpha ( & weights. clone ( ) , & bonds, clamped_bonds_alpha)
177
+ } else {
178
+ log:: trace!( "Using Bonds Moving Average" ) ;
179
+ // Compute the EMA of bonds using a normal alpha value.
180
+ Self :: compute_ema_bonds_normal ( & weights. clone ( ) , & bonds, netuid)
181
+ } ;
182
+
176
183
inplace_col_normalize ( & mut ema_bonds) ; // sum_i b_ij = 1
177
184
log:: trace!( "emaB:\n {:?}\n " , & ema_bonds) ;
178
185
179
- // Compute dividends: d_i = SUM(j) b_ij * inc_j
180
- let mut dividends: Vec < I32F32 > = matmul_transpose ( & ema_bonds, & incentive) ;
186
+ // # === Dividend Calculation===
187
+ let total_bonds_per_validator: Vec < I32F32 > = matmul_transpose ( & ema_bonds, & incentive) ;
188
+ let mut dividends: Vec < I32F32 > = vec_mul ( & total_bonds_per_validator, & active_stake) ;
181
189
inplace_normalize ( & mut dividends) ;
182
190
log:: trace!( "D:\n {:?}\n " , & dividends) ;
183
191
@@ -1112,22 +1120,15 @@ impl<T: Config> Pallet<T> {
1112
1120
}
1113
1121
}
1114
1122
1115
- /// Compute the Exponential Moving Average (EMA) of bonds based on the Liquid Alpha setting.
1123
+ /// Compute liquid alphas based on the Liquid Alpha setting.
1116
1124
///
1117
1125
/// # Args:
1118
1126
/// * `netuid` - The network ID.
1119
1127
/// * `consensus` - A vector of consensus values.
1120
- /// * `bonds_delta` - A vector of bond deltas.
1121
- /// * `bonds` - A vector of bonds.
1122
1128
///
1123
1129
/// # Returns:
1124
- /// A vector of EMA bonds.
1125
- pub fn compute_ema_bonds (
1126
- netuid : u16 ,
1127
- consensus : Vec < I32F32 > ,
1128
- bonds_delta : Vec < Vec < I32F32 > > ,
1129
- bonds : Vec < Vec < I32F32 > > ,
1130
- ) -> Vec < Vec < I32F32 > > {
1130
+ /// A vector of alphas
1131
+ pub fn compute_liquid_alpha ( netuid : u16 , consensus : Vec < I32F32 > ) -> Option < Vec < I32F32 > > {
1131
1132
// Check if Liquid Alpha is enabled, consensus is not empty, and contains non-zero values.
1132
1133
if LiquidAlphaOn :: < T > :: get ( netuid)
1133
1134
&& !consensus. is_empty ( )
@@ -1159,20 +1160,10 @@ impl<T: Config> Pallet<T> {
1159
1160
// Clamp the alpha values between alpha_high and alpha_low.
1160
1161
let clamped_alpha = Self :: clamp_alpha_values ( alpha, alpha_high, alpha_low) ;
1161
1162
1162
- // Compute the Exponential Moving Average (EMA) of bonds using the clamped alpha values.
1163
- Self :: compute_ema_bonds_with_liquid_alpha ( & bonds_delta, & bonds, clamped_alpha)
1164
- } else {
1165
- log:: trace!( "Using Bonds Moving Average" ) ;
1166
-
1167
- // Compute the EMA of bonds using a normal alpha value.
1168
- Self :: compute_ema_bonds_normal ( & bonds_delta, & bonds, netuid)
1163
+ return Some ( clamped_alpha) ;
1169
1164
}
1170
- } else {
1171
- log:: trace!( "Using Bonds Moving Average" ) ;
1172
-
1173
- // Compute the EMA of bonds using a normal alpha value.
1174
- Self :: compute_ema_bonds_normal ( & bonds_delta, & bonds, netuid)
1175
1165
}
1166
+ None
1176
1167
}
1177
1168
1178
1169
pub fn do_set_alpha_values (
0 commit comments