@@ -138,8 +138,10 @@ impl<T: Config> Pallet<T> {
138138 for netuid_i in subnets. iter ( ) {
139139 // Get alpha out.
140140 let alpha_out_i: I96F32 = * alpha_out. get ( netuid_i) . unwrap_or ( & asfloat ! ( 0 ) ) ;
141+ log:: debug!( "alpha_out_i: {:?}" , alpha_out_i) ;
141142 // Calculate the owner cut.
142143 let owner_cut_i: I96F32 = alpha_out_i. saturating_mul ( cut_percent) ;
144+ log:: debug!( "owner_cut_i: {:?}" , owner_cut_i) ;
143145 // Save owner cut.
144146 * owner_cuts. entry ( * netuid_i) . or_insert ( asfloat ! ( 0 ) ) = owner_cut_i;
145147 // Save new alpha_out.
@@ -155,24 +157,33 @@ impl<T: Config> Pallet<T> {
155157 for netuid_i in subnets. iter ( ) {
156158 // Get remaining alpha out.
157159 let alpha_out_i: I96F32 = * alpha_out. get ( netuid_i) . unwrap_or ( & asfloat ! ( 0.0 ) ) ;
160+ log:: debug!( "alpha_out_i: {:?}" , alpha_out_i) ;
158161 // Get total TAO on root.
159162 let root_tao: I96F32 = asfloat ! ( SubnetTAO :: <T >:: get( 0 ) ) ;
163+ log:: debug!( "root_tao: {:?}" , root_tao) ;
160164 // Get total ALPHA on subnet.
161165 let alpha_issuance: I96F32 = asfloat ! ( Self :: get_alpha_issuance( * netuid_i) ) ;
166+ log:: debug!( "alpha_issuance: {:?}" , alpha_issuance) ;
162167 // Get tao_weight
163168 let tao_weight: I96F32 = root_tao. saturating_mul ( Self :: get_tao_weight ( ) ) ;
169+ log:: debug!( "tao_weight: {:?}" , tao_weight) ;
164170 // Get root proportional dividends.
165171 let root_proportion: I96F32 = tao_weight
166172 . checked_div ( tao_weight. saturating_add ( alpha_issuance) )
167173 . unwrap_or ( asfloat ! ( 0.0 ) ) ;
174+ log:: debug!( "root_proportion: {:?}" , root_proportion) ;
168175 // Get root proportion of alpha_out dividends.
169176 let root_alpha: I96F32 = root_proportion
170177 . saturating_mul ( alpha_out_i) // Total alpha emission per block remaining.
171178 . saturating_mul ( asfloat ! ( 0.5 ) ) ; // 50% to validators.
172179 // Remove root alpha from alpha_out.
180+ log:: debug!( "root_alpha: {:?}" , root_alpha) ;
181+ // Get pending alpha as original alpha_out - root_alpha.
173182 let pending_alpha: I96F32 = alpha_out_i. saturating_sub ( root_alpha) ;
183+ log:: debug!( "pending_alpha: {:?}" , pending_alpha) ;
174184 // Sell root emission through the pool.
175185 let root_tao: u64 = Self :: swap_alpha_for_tao ( * netuid_i, tou64 ! ( root_alpha) ) ;
186+ log:: debug!( "root_tao: {:?}" , root_tao) ;
176187 // Accumulate alpha emission in pending.
177188 PendingAlphaSwapped :: < T > :: mutate ( * netuid_i, |total| {
178189 * total = total. saturating_add ( tou64 ! ( root_alpha) ) ;
@@ -238,6 +249,11 @@ impl<T: Config> Pallet<T> {
238249 BlocksSinceLastStep :: < T > :: mutate ( netuid, |total| * total = total. saturating_add ( 1 ) ) ;
239250 }
240251 }
252+
253+ // --- 8. Apply pending childkeys of this subnet for the next epoch
254+ for netuid in subnets. iter ( ) {
255+ Self :: do_set_pending_children ( * netuid) ;
256+ }
241257 }
242258
243259 pub fn drain_pending_emission (
@@ -261,6 +277,7 @@ impl<T: Config> Pallet<T> {
261277 // Run the epoch.
262278 let hotkey_emission: Vec < ( T :: AccountId , u64 , u64 ) > =
263279 Self :: epoch ( netuid, pending_alpha. saturating_add ( pending_swapped) ) ;
280+ log:: debug!( "hotkey_emission: {:?}" , hotkey_emission) ;
264281
265282 // Accumulate emission of dividends and incentive per hotkey.
266283 let mut incentives: BTreeMap < T :: AccountId , u64 > = BTreeMap :: new ( ) ;
@@ -282,8 +299,10 @@ impl<T: Config> Pallet<T> {
282299 . or_insert ( asfloat ! ( parent_div) ) ;
283300 }
284301 }
302+ log:: debug!( "incentives: {:?}" , incentives) ;
303+ log:: debug!( "dividends: {:?}" , dividends) ;
285304
286- // Accumulate root divs and alpha_divs. For each hotkye we compute their
305+ // Accumulate root divs and alpha_divs. For each hotkey we compute their
287306 // local and root dividend proportion based on their alpha_stake/root_stake
288307 let mut total_root_divs: I96F32 = asfloat ! ( 0 ) ;
289308 let mut root_dividends: BTreeMap < T :: AccountId , I96F32 > = BTreeMap :: new ( ) ;
@@ -300,19 +319,15 @@ impl<T: Config> Pallet<T> {
300319 let root_alpha: I96F32 = root_stake. saturating_mul ( Self :: get_tao_weight ( ) ) ;
301320 // Get total from root and local
302321 let total_alpha: I96F32 = alpha_stake. saturating_add ( root_alpha) ;
303- // Compute alpha prop.
304- let alpha_prop: I96F32 = alpha_stake. checked_div ( total_alpha) . unwrap_or ( zero) ;
305322 // Copmute root prop.
306323 let root_prop: I96F32 = root_alpha. checked_div ( total_alpha) . unwrap_or ( zero) ;
307- // Compute alpha dividends
308- let alpha_divs: I96F32 = dividend. saturating_mul ( alpha_prop) ;
309324 // Compute root dividends
310325 let root_divs: I96F32 = dividend. saturating_mul ( root_prop) ;
311326 // Record the root dividends.
312327 alpha_dividends
313328 . entry ( hotkey. clone ( ) )
314- . and_modify ( |e| * e = e. saturating_add ( alpha_divs ) )
315- . or_insert ( alpha_divs ) ;
329+ . and_modify ( |e| * e = e. saturating_add ( dividend ) )
330+ . or_insert ( dividend ) ;
316331 // Record the alpha_dividends.
317332 root_dividends
318333 . entry ( hotkey. clone ( ) )
@@ -321,6 +336,8 @@ impl<T: Config> Pallet<T> {
321336 // Accumulate total root divs.
322337 total_root_divs = total_root_divs. saturating_add ( root_divs) ;
323338 }
339+ log:: debug!( "alpha_dividends: {:?}" , alpha_dividends) ;
340+ log:: debug!( "root_dividends: {:?}" , root_dividends) ;
324341
325342 // Compute root divs as TAO. Here we take
326343 let mut tao_dividends: BTreeMap < T :: AccountId , I96F32 > = BTreeMap :: new ( ) ;
@@ -335,6 +352,7 @@ impl<T: Config> Pallet<T> {
335352 . and_modify ( |e| * e = root_tao)
336353 . or_insert ( root_tao) ;
337354 }
355+ log:: debug!( "tao_dividends: {:?}" , tao_dividends) ;
338356
339357 // Distribute the owner cut.
340358 if let Ok ( owner_coldkey) = SubnetOwner :: < T > :: try_get ( netuid) {
@@ -363,6 +381,8 @@ impl<T: Config> Pallet<T> {
363381 // Distribute alpha divs.
364382 let _ = AlphaDividendsPerSubnet :: < T > :: clear_prefix ( netuid, u32:: MAX , None ) ;
365383 for ( hotkey, mut alpha_divs) in alpha_dividends {
384+ log:: debug!( "hotkey: {:?} alpha_divs: {:?}" , hotkey, alpha_divs) ;
385+
366386 // Get take prop
367387 let alpha_take: I96F32 =
368388 Self :: get_hotkey_take_float ( & hotkey) . saturating_mul ( alpha_divs) ;
@@ -386,6 +406,7 @@ impl<T: Config> Pallet<T> {
386406 // Distribute root tao divs.
387407 let _ = TaoDividendsPerSubnet :: < T > :: clear_prefix ( netuid, u32:: MAX , None ) ;
388408 for ( hotkey, mut root_tao) in tao_dividends {
409+ log:: debug!( "hotkey: {:?} root_tao: {:?}" , hotkey, root_tao) ;
389410 // Get take prop
390411 let tao_take: I96F32 = Self :: get_hotkey_take_float ( & hotkey) . saturating_mul ( root_tao) ;
391412 // Remove take prop from root_tao
0 commit comments