@@ -569,6 +569,13 @@ impl<T: Config> Pallet<T> {
569
569
hotkeys. push ( hotkey. clone ( ) ) ;
570
570
OwnedHotkeys :: < T > :: insert ( coldkey, hotkeys) ;
571
571
}
572
+
573
+ // Update StakingHotkeys map
574
+ let mut staking_hotkeys = StakingHotkeys :: < T > :: get ( coldkey) ;
575
+ if !staking_hotkeys. contains ( hotkey) {
576
+ staking_hotkeys. push ( hotkey. clone ( ) ) ;
577
+ StakingHotkeys :: < T > :: insert ( coldkey, staking_hotkeys) ;
578
+ }
572
579
}
573
580
}
574
581
@@ -648,6 +655,13 @@ impl<T: Config> Pallet<T> {
648
655
Stake :: < T > :: get ( hotkey, coldkey) . saturating_add ( increment) ,
649
656
) ;
650
657
TotalStake :: < T > :: put ( TotalStake :: < T > :: get ( ) . saturating_add ( increment) ) ;
658
+
659
+ // Update StakingHotkeys map
660
+ let mut staking_hotkeys = StakingHotkeys :: < T > :: get ( coldkey) ;
661
+ if !staking_hotkeys. contains ( hotkey) {
662
+ staking_hotkeys. push ( hotkey. clone ( ) ) ;
663
+ StakingHotkeys :: < T > :: insert ( coldkey, staking_hotkeys) ;
664
+ }
651
665
}
652
666
653
667
// Decreases the stake on the cold - hot pairing by the decrement while decreasing other counters.
@@ -668,6 +682,8 @@ impl<T: Config> Pallet<T> {
668
682
Stake :: < T > :: get ( hotkey, coldkey) . saturating_sub ( decrement) ,
669
683
) ;
670
684
TotalStake :: < T > :: put ( TotalStake :: < T > :: get ( ) . saturating_sub ( decrement) ) ;
685
+
686
+ // TODO: Tech debt: Remove StakingHotkeys entry if stake goes to 0
671
687
}
672
688
673
689
/// Empties the stake associated with a given coldkey-hotkey account pairing.
@@ -693,6 +709,11 @@ impl<T: Config> Pallet<T> {
693
709
TotalStake :: < T > :: mutate ( |stake| * stake = stake. saturating_sub ( current_stake) ) ;
694
710
TotalIssuance :: < T > :: mutate ( |issuance| * issuance = issuance. saturating_sub ( current_stake) ) ;
695
711
712
+ // Update StakingHotkeys map
713
+ let mut staking_hotkeys = StakingHotkeys :: < T > :: get ( coldkey) ;
714
+ staking_hotkeys. retain ( |h| h != hotkey) ;
715
+ StakingHotkeys :: < T > :: insert ( coldkey, staking_hotkeys) ;
716
+
696
717
current_stake
697
718
}
698
719
@@ -897,6 +918,25 @@ impl<T: Config> Pallet<T> {
897
918
}
898
919
}
899
920
921
+ // Unstake all delegate stake make by this coldkey to non-owned hotkeys
922
+ let staking_hotkeys = StakingHotkeys :: < T > :: get ( & current_coldkey) ;
923
+
924
+ // iterate over all staking hotkeys.
925
+ for hotkey in staking_hotkeys {
926
+ // Get the current stake
927
+ let current_stake: u64 =
928
+ Self :: get_stake_for_coldkey_and_hotkey ( & current_coldkey, & hotkey) ;
929
+
930
+ // Unstake all balance if there's any stake
931
+ if current_stake > 0 {
932
+ Self :: do_remove_stake (
933
+ RawOrigin :: Signed ( current_coldkey. clone ( ) ) . into ( ) ,
934
+ hotkey. clone ( ) ,
935
+ current_stake,
936
+ ) ?;
937
+ }
938
+ }
939
+
900
940
let total_balance = Self :: get_coldkey_balance ( & current_coldkey) ;
901
941
log:: info!( "Total Bank Balance: {:?}" , total_balance) ;
902
942
0 commit comments