@@ -310,7 +310,7 @@ impl<T: Config> Pallet<T> {
310
310
311
311
// 6.3.2: Get dividend tuples for parents and self based on childkey relationships and child-take.
312
312
let dividend_tuples: Vec < ( T :: AccountId , u64 ) > =
313
- Self :: get_parent_dividends ( & hotkey, netuid, dividends) ;
313
+ Self :: get_dividends_distribution ( & hotkey, netuid, dividends) ;
314
314
log:: debug!(
315
315
"Dividend tuples for hotkey {:?} on netuid {:?}: {:?}" ,
316
316
hotkey,
@@ -460,9 +460,43 @@ impl<T: Config> Pallet<T> {
460
460
}
461
461
}
462
462
463
+ pub fn get_self_contribution ( hotkey : & T :: AccountId , netuid : u16 ) -> u64 {
464
+ // Get all childkeys for this hotkey.
465
+ let childkeys = Self :: get_children ( hotkey, netuid) ;
466
+ let mut remaining_proportion: I96F32 = I96F32 :: from_num ( 1.0 ) ;
467
+ for ( proportion, _) in childkeys {
468
+ remaining_proportion = remaining_proportion. saturating_sub (
469
+ I96F32 :: from_num ( proportion) // Normalize
470
+ . saturating_div ( I96F32 :: from_num ( u64:: MAX ) ) ,
471
+ ) ;
472
+ }
473
+
474
+ // Get TAO weight
475
+ let tao_weight: I96F32 = Self :: get_tao_weight ( ) ;
476
+
477
+ // Get the hotkey's stake including weight
478
+ let root_stake: I96F32 = I96F32 :: from_num ( Self :: get_stake_for_hotkey_on_subnet (
479
+ & hotkey,
480
+ Self :: get_root_netuid ( ) ,
481
+ ) ) ;
482
+ let alpha_stake: I96F32 =
483
+ I96F32 :: from_num ( Self :: get_stake_for_hotkey_on_subnet ( & hotkey, netuid) ) ;
484
+
485
+ // Calculate the
486
+ let alpha_contribution: I96F32 = alpha_stake. saturating_mul ( remaining_proportion) ;
487
+ let root_contribution: I96F32 = root_stake
488
+ . saturating_mul ( remaining_proportion)
489
+ . saturating_mul ( tao_weight) ;
490
+ let combined_contribution: I96F32 = alpha_contribution. saturating_add ( root_contribution) ;
491
+
492
+ // Return the combined contribution as a u64
493
+ combined_contribution. to_num :: < u64 > ( )
494
+ }
495
+
463
496
/// Returns a list of tuples for each parent associated with this hotkey including self
464
497
/// Each tuples contains the dividends owed to that hotkey given their parent proportion
465
498
/// The hotkey child take proportion is removed from this and added to the tuples for self.
499
+ /// The hotkey also gets a portion based on its own stake contribution, this is added to the childkey take.
466
500
///
467
501
/// # Arguments
468
502
/// * `hotkye` - The hotkey to distribute out from.
@@ -472,7 +506,7 @@ impl<T: Config> Pallet<T> {
472
506
/// # Returns
473
507
/// * dividend_tuples: `Vec<(T::AccountId, u64)>` - Vector of (hotkey, divs) for each parent including self.
474
508
///
475
- pub fn get_parent_dividends (
509
+ pub fn get_dividends_distribution (
476
510
hotkey : & T :: AccountId ,
477
511
netuid : u16 ,
478
512
dividends : u64 ,
@@ -485,19 +519,29 @@ impl<T: Config> Pallet<T> {
485
519
let childkey_take_proportion: I96F32 =
486
520
I96F32 :: from_num ( Self :: get_childkey_take ( hotkey, netuid) )
487
521
. saturating_div ( I96F32 :: from_num ( u16:: MAX ) ) ;
488
- let mut total_childkey_take: u64 = 0 ;
489
522
// NOTE: Only the validation emission should be split amongst parents.
490
523
491
524
// Initialize variables to track emission distribution
492
525
let mut to_parents: u64 = 0 ;
493
526
494
527
// Initialize variables to calculate total stakes from parents
495
528
let mut total_contribution: I96F32 = I96F32 :: from_num ( 0 ) ;
496
- let mut contributions : Vec < ( T :: AccountId , I96F32 ) > = Vec :: new ( ) ;
529
+ let mut parent_contributions : Vec < ( T :: AccountId , I96F32 ) > = Vec :: new ( ) ;
497
530
498
531
// Get the weights for root and alpha stakes in emission distribution
499
532
let tao_weight: I96F32 = Self :: get_tao_weight ( ) ;
500
533
534
+ // Get self contribution, removing any childkey proportions.
535
+ let self_contribution = Self :: get_self_contribution ( hotkey, netuid) ;
536
+ log:: debug!(
537
+ "Self contribution for hotkey {:?} on netuid {:?}: {:?}" ,
538
+ hotkey,
539
+ netuid,
540
+ self_contribution
541
+ ) ;
542
+ // Add self contribution to total contribution but not to the parent contributions.
543
+ total_contribution = total_contribution. saturating_add ( I96F32 :: from_num ( self_contribution) ) ;
544
+
501
545
// Calculate total root and alpha (subnet-specific) stakes from all parents
502
546
for ( proportion, parent) in Self :: get_parents ( hotkey, netuid) {
503
547
// Convert the parent's stake proportion to a fractional value
@@ -523,11 +567,12 @@ impl<T: Config> Pallet<T> {
523
567
// Add to the total stakes
524
568
total_contribution = total_contribution. saturating_add ( combined_contribution) ;
525
569
// Store the parent's contributions for later use
526
- contributions . push ( ( parent. clone ( ) , combined_contribution) ) ;
570
+ parent_contributions . push ( ( parent. clone ( ) , combined_contribution) ) ;
527
571
}
528
572
529
- // Distribute emission to parents based on their contributions
530
- for ( parent, contribution) in contributions {
573
+ // Distribute emission to parents based on their contributions.
574
+ // Deduct childkey take from parent contribution.
575
+ for ( parent, contribution) in parent_contributions {
531
576
// Sum up the total emission for this parent
532
577
let emission_factor: I96F32 = contribution
533
578
. checked_div ( total_contribution)
@@ -539,7 +584,6 @@ impl<T: Config> Pallet<T> {
539
584
let child_emission_take: u64 = childkey_take_proportion
540
585
. saturating_mul ( I96F32 :: from_num ( total_emission) )
541
586
. to_num :: < u64 > ( ) ;
542
- total_childkey_take = total_childkey_take. saturating_add ( child_emission_take) ;
543
587
let parent_total_emission = total_emission. saturating_sub ( child_emission_take) ;
544
588
545
589
// Add the parent's emission to the distribution list
@@ -548,7 +592,8 @@ impl<T: Config> Pallet<T> {
548
592
// Keep track of total emission distributed to parents
549
593
to_parents = to_parents. saturating_add ( parent_total_emission) ;
550
594
}
551
- // Calculate the final emission for the hotkey itself
595
+ // Calculate the final emission for the hotkey itself.
596
+ // This includes the take left from the parents and the self contribution.
552
597
let final_hotkey_emission = validating_emission
553
598
. to_num :: < u64 > ( )
554
599
. saturating_sub ( to_parents) ;
0 commit comments