@@ -131,8 +131,9 @@ impl<T: Config> Pallet<T> {
131
131
log:: debug!( "alpha_stake: {:?}" , alpha_stake) ;
132
132
133
133
// Step 2: Get the global tao stake for the hotkey
134
- let tao_stake =
135
- I64F64 :: saturating_from_num ( Self :: get_tao_inherited_for_hotkey_on_subnet ( hotkey, netuid) ) ;
134
+ let tao_stake = I64F64 :: saturating_from_num ( Self :: get_tao_inherited_for_hotkey_on_subnet (
135
+ hotkey, netuid,
136
+ ) ) ;
136
137
log:: debug!( "tao_stake: {:?}" , tao_stake) ;
137
138
138
139
// Step 3: Combine alpha and tao stakes
@@ -223,99 +224,97 @@ impl<T: Config> Pallet<T> {
223
224
/// # Note
224
225
/// This function uses saturating arithmetic to prevent overflows.
225
226
pub fn get_tao_inherited_for_hotkey_on_subnet ( hotkey : & T :: AccountId , netuid : u16 ) -> u64 {
227
+ let initial_tao: I96F32 = I96F32 :: saturating_from_num (
228
+ Self :: get_stake_for_hotkey_on_subnet ( hotkey, Self :: get_root_netuid ( ) ) ,
229
+ ) ;
230
+
231
+ // Initialize variables to track alpha allocated to children and inherited from parents.
232
+ let mut tao_to_children: I96F32 = I96F32 :: saturating_from_num ( 0 ) ;
233
+ let mut tao_from_parents: I96F32 = I96F32 :: saturating_from_num ( 0 ) ;
234
+
235
+ // Step 2: Retrieve the lists of parents and children for the hotkey on the subnet.
236
+ let parents: Vec < ( u64 , T :: AccountId ) > = Self :: get_parents ( hotkey, netuid) ;
237
+ let children: Vec < ( u64 , T :: AccountId ) > = Self :: get_children ( hotkey, netuid) ;
238
+ log:: trace!(
239
+ "Parents for hotkey {:?} on subnet {}: {:?}" ,
240
+ hotkey,
241
+ netuid,
242
+ parents
243
+ ) ;
244
+ log:: trace!(
245
+ "Children for hotkey {:?} on subnet {}: {:?}" ,
246
+ hotkey,
247
+ netuid,
248
+ children
249
+ ) ;
250
+
251
+ // Step 3: Calculate the total tao allocated to children.
252
+ for ( proportion, _) in children {
253
+ // Convert the proportion to a normalized value between 0 and 1.
254
+ let normalized_proportion: I96F32 = I96F32 :: saturating_from_num ( proportion)
255
+ . safe_div ( I96F32 :: saturating_from_num ( u64:: MAX ) ) ;
256
+ log:: trace!(
257
+ "Normalized proportion for child: {:?}" ,
258
+ normalized_proportion
259
+ ) ;
226
260
227
- let initial_tao: I96F32 =
228
- I96F32 :: saturating_from_num ( Self :: get_stake_for_hotkey_on_subnet ( hotkey, Self :: get_root_netuid ( ) ) ) ;
229
-
230
- // Initialize variables to track alpha allocated to children and inherited from parents.
231
- let mut tao_to_children: I96F32 = I96F32 :: saturating_from_num ( 0 ) ;
232
- let mut tao_from_parents: I96F32 = I96F32 :: saturating_from_num ( 0 ) ;
233
-
234
- // Step 2: Retrieve the lists of parents and children for the hotkey on the subnet.
235
- let parents: Vec < ( u64 , T :: AccountId ) > = Self :: get_parents ( hotkey, netuid) ;
236
- let children: Vec < ( u64 , T :: AccountId ) > = Self :: get_children ( hotkey, netuid) ;
237
- log:: trace!(
238
- "Parents for hotkey {:?} on subnet {}: {:?}" ,
239
- hotkey,
240
- netuid,
241
- parents
242
- ) ;
243
- log:: trace!(
244
- "Children for hotkey {:?} on subnet {}: {:?}" ,
245
- hotkey,
246
- netuid,
247
- children
248
- ) ;
249
-
250
- // Step 3: Calculate the total tao allocated to children.
251
- for ( proportion, _) in children {
252
- // Convert the proportion to a normalized value between 0 and 1.
253
- let normalized_proportion: I96F32 = I96F32 :: saturating_from_num ( proportion)
254
- . safe_div ( I96F32 :: saturating_from_num ( u64:: MAX ) ) ;
255
- log:: trace!(
256
- "Normalized proportion for child: {:?}" ,
257
- normalized_proportion
258
- ) ;
259
-
260
- // Calculate the amount of tao to be allocated to this child.
261
- let tao_proportion_to_child: I96F32 =
262
- I96F32 :: saturating_from_num ( initial_tao) . saturating_mul ( normalized_proportion) ;
263
- log:: trace!( "Tao proportion to child: {:?}" , tao_proportion_to_child) ;
264
-
265
- // Add this child's allocation to the total tao allocated to children.
266
- tao_to_children = tao_to_children. saturating_add ( tao_proportion_to_child) ;
267
- }
268
- log:: trace!( "Total tao allocated to children: {:?}" , tao_to_children) ;
269
-
270
- // Step 4: Calculate the total tao inherited from parents.
271
- for ( proportion, parent) in parents {
272
- // Retrieve the parent's total stake on this subnet.
273
- let parent_tao: I96F32 =
274
- I96F32 :: saturating_from_num ( Self :: get_stake_for_hotkey_on_subnet ( & parent, Self :: get_root_netuid ( ) ) ) ;
275
- log:: trace!(
276
- "Parent tao for parent {:?} on subnet {}: {:?}" ,
277
- parent,
278
- netuid,
279
- parent_tao
280
- ) ;
281
-
282
- // Convert the proportion to a normalized value between 0 and 1.
283
- let normalized_proportion: I96F32 = I96F32 :: saturating_from_num ( proportion)
284
- . safe_div ( I96F32 :: saturating_from_num ( u64:: MAX ) ) ;
285
- log:: trace!(
286
- "Normalized proportion from parent: {:?}" ,
287
- normalized_proportion
288
- ) ;
289
-
290
- // Calculate the amount of tao to be inherited from this parent.
291
- let tao_proportion_from_parent: I96F32 =
292
- I96F32 :: saturating_from_num ( parent_tao) . saturating_mul ( normalized_proportion) ;
293
- log:: trace!(
294
- "Tao proportion from parent: {:?}" ,
261
+ // Calculate the amount of tao to be allocated to this child.
262
+ let tao_proportion_to_child: I96F32 =
263
+ I96F32 :: saturating_from_num ( initial_tao) . saturating_mul ( normalized_proportion) ;
264
+ log:: trace!( "Tao proportion to child: {:?}" , tao_proportion_to_child) ;
265
+
266
+ // Add this child's allocation to the total tao allocated to children.
267
+ tao_to_children = tao_to_children. saturating_add ( tao_proportion_to_child) ;
268
+ }
269
+ log:: trace!( "Total tao allocated to children: {:?}" , tao_to_children) ;
270
+
271
+ // Step 4: Calculate the total tao inherited from parents.
272
+ for ( proportion, parent) in parents {
273
+ // Retrieve the parent's total stake on this subnet.
274
+ let parent_tao: I96F32 = I96F32 :: saturating_from_num (
275
+ Self :: get_stake_for_hotkey_on_subnet ( & parent, Self :: get_root_netuid ( ) ) ,
276
+ ) ;
277
+ log:: trace!(
278
+ "Parent tao for parent {:?} on subnet {}: {:?}" ,
279
+ parent,
280
+ netuid,
281
+ parent_tao
282
+ ) ;
283
+
284
+ // Convert the proportion to a normalized value between 0 and 1.
285
+ let normalized_proportion: I96F32 = I96F32 :: saturating_from_num ( proportion)
286
+ . safe_div ( I96F32 :: saturating_from_num ( u64:: MAX ) ) ;
287
+ log:: trace!(
288
+ "Normalized proportion from parent: {:?}" ,
289
+ normalized_proportion
290
+ ) ;
291
+
292
+ // Calculate the amount of tao to be inherited from this parent.
293
+ let tao_proportion_from_parent: I96F32 =
294
+ I96F32 :: saturating_from_num ( parent_tao) . saturating_mul ( normalized_proportion) ;
295
+ log:: trace!(
296
+ "Tao proportion from parent: {:?}" ,
295
297
tao_proportion_from_parent
296
- ) ;
297
-
298
- // Add this parent's contribution to the total tao inherited from parents.
299
- tao_from_parents = tao_from_parents. saturating_add ( tao_proportion_from_parent) ;
300
- }
301
- log:: trace!(
302
- "Total tao inherited from parents: {:?}" ,
303
- tao_from_parents
304
- ) ;
305
-
306
- // Step 5: Calculate the final inherited tao for the hotkey.
307
- let finalized_tao: I96F32 = initial_tao
308
- . saturating_sub ( tao_to_children) // Subtract tao allocated to children
309
- . saturating_add ( tao_from_parents) ; // Add tao inherited from parents
310
- log:: trace!(
311
- "Finalized tao for hotkey {:?} on subnet {}: {:?}" ,
312
- hotkey,
313
- netuid,
314
- finalized_tao
315
- ) ;
316
-
317
- // Step 6: Return the final inherited tao value.
318
- finalized_tao. saturating_to_num :: < u64 > ( )
298
+ ) ;
299
+
300
+ // Add this parent's contribution to the total tao inherited from parents.
301
+ tao_from_parents = tao_from_parents. saturating_add ( tao_proportion_from_parent) ;
302
+ }
303
+ log:: trace!( "Total tao inherited from parents: {:?}" , tao_from_parents) ;
304
+
305
+ // Step 5: Calculate the final inherited tao for the hotkey.
306
+ let finalized_tao: I96F32 = initial_tao
307
+ . saturating_sub ( tao_to_children) // Subtract tao allocated to children
308
+ . saturating_add ( tao_from_parents) ; // Add tao inherited from parents
309
+ log:: trace!(
310
+ "Finalized tao for hotkey {:?} on subnet {}: {:?}" ,
311
+ hotkey,
312
+ netuid,
313
+ finalized_tao
314
+ ) ;
315
+
316
+ // Step 6: Return the final inherited tao value.
317
+ finalized_tao. saturating_to_num :: < u64 > ( )
319
318
}
320
319
321
320
pub fn get_inherited_for_hotkey_on_subnet ( hotkey : & T :: AccountId , netuid : u16 ) -> u64 {
0 commit comments