@@ -128,16 +128,16 @@ impl<T: Config> Pallet<T> {
128
128
// Step 1: Get stake of hotkey (neuron)
129
129
let alpha_stake =
130
130
I64F64 :: saturating_from_num ( Self :: get_inherited_for_hotkey_on_subnet ( hotkey, netuid) ) ;
131
- log:: trace !( "alpha_stake: {:?}" , alpha_stake) ;
131
+ log:: debug !( "alpha_stake: {:?}" , alpha_stake) ;
132
132
133
133
// Step 2: Get the global tao stake for the hotkey
134
134
let tao_stake =
135
- I64F64 :: saturating_from_num ( Self :: get_inherited_for_hotkey_on_subnet ( hotkey, 0 ) ) ;
136
- log:: trace !( "tao_stake: {:?}" , tao_stake) ;
135
+ I64F64 :: saturating_from_num ( Self :: get_tao_inherited_for_hotkey_on_subnet ( hotkey, netuid ) ) ;
136
+ log:: debug !( "tao_stake: {:?}" , tao_stake) ;
137
137
138
138
// Step 3: Combine alpha and tao stakes
139
139
let total_stake = alpha_stake. saturating_add ( tao_stake. saturating_mul ( tao_weight) ) ;
140
- log:: trace !( "total_stake: {:?}" , total_stake) ;
140
+ log:: debug !( "total_stake: {:?}" , total_stake) ;
141
141
142
142
( total_stake, alpha_stake, tao_stake)
143
143
}
@@ -173,8 +173,8 @@ impl<T: Config> Pallet<T> {
173
173
. map ( |uid| {
174
174
if Keys :: < T > :: contains_key ( netuid, uid) {
175
175
let hotkey: T :: AccountId = Keys :: < T > :: get ( netuid, uid) ;
176
- I64F64 :: saturating_from_num ( Self :: get_inherited_for_hotkey_on_subnet (
177
- & hotkey, 0 ,
176
+ I64F64 :: saturating_from_num ( Self :: get_tao_inherited_for_hotkey_on_subnet (
177
+ & hotkey, netuid ,
178
178
) )
179
179
} else {
180
180
I64F64 :: saturating_from_num ( 0 )
@@ -222,6 +222,102 @@ impl<T: Config> Pallet<T> {
222
222
///
223
223
/// # Note
224
224
/// This function uses saturating arithmetic to prevent overflows.
225
+ pub fn get_tao_inherited_for_hotkey_on_subnet ( hotkey : & T :: AccountId , netuid : u16 ) -> u64 {
226
+
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: {:?}" ,
295
+ 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 > ( )
319
+ }
320
+
225
321
pub fn get_inherited_for_hotkey_on_subnet ( hotkey : & T :: AccountId , netuid : u16 ) -> u64 {
226
322
// Step 1: Retrieve the initial total stake (alpha) for the hotkey on the specified subnet.
227
323
let initial_alpha: I96F32 =
0 commit comments