@@ -19,6 +19,7 @@ fn get_account_id_from_ss58<T: Config>(ss58_str: &str) -> Result<T::AccountId, c
1919fn migrate_pending_emissions_including_null_stake < T : Config > (
2020 old_hotkey : & T :: AccountId ,
2121 new_hotkey : & T :: AccountId ,
22+ migration_account : & T :: AccountId ,
2223) -> Weight {
2324 let mut weight = T :: DbWeight :: get ( ) . reads ( 0 ) ;
2425 let null_account = & DefaultAccount :: < T > :: get ( ) ;
@@ -30,10 +31,10 @@ fn migrate_pending_emissions_including_null_stake<T: Config>(
3031 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
3132
3233 // Get the stake for the 0x000 key
33- let null_stake = Stake :: < T > :: get ( & old_hotkey, null_account) ;
34+ let null_stake = Stake :: < T > :: get ( old_hotkey, null_account) ;
3435 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
3536 // Remove
36- Stake :: < T > :: remove ( & old_hotkey, null_account) ;
37+ Stake :: < T > :: remove ( old_hotkey, null_account) ;
3738 weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
3839
3940 let new_total_coldkey_stake =
@@ -45,29 +46,35 @@ fn migrate_pending_emissions_including_null_stake<T: Config>(
4546 }
4647 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
4748
48- let new_total_hotkey_stake = TotalHotkeyStake :: < T > :: get ( old_hotkey ) . saturating_sub ( null_stake ) ;
49- if new_total_hotkey_stake == 0 {
50- TotalHotkeyStake :: < T > :: remove ( old_hotkey ) ;
51- } else {
52- TotalHotkeyStake :: < T > :: insert ( old_hotkey , new_total_hotkey_stake ) ;
53- }
49+ let new_staking_hotkeys = StakingHotkeys :: < T > :: get ( null_account ) ;
50+ let new_staking_hotkeys = new_staking_hotkeys
51+ . into_iter ( )
52+ . filter ( |hk| hk != old_hotkey )
53+ . collect :: < Vec < _ > > ( ) ;
54+ StakingHotkeys :: < T > :: insert ( null_account , new_staking_hotkeys ) ;
5455 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
5556
56- // Remove the stake from the total stake and total issuance (since it is re-emitted)
57- TotalStake :: < T > :: put ( TotalStake :: < T > :: get ( ) . saturating_sub ( null_stake) ) ;
58- TotalIssuance :: < T > :: put ( TotalIssuance :: < T > :: get ( ) . saturating_sub ( null_stake) ) ;
59- weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
57+ // Insert the stake from the null account to the MIGRATION account under the OLD hotkey
58+ Stake :: < T > :: insert ( old_hotkey, migration_account, null_stake) ;
59+ TotalColdkeyStake :: < T > :: insert (
60+ migration_account,
61+ TotalColdkeyStake :: < T > :: get ( migration_account) . saturating_add ( null_stake) ,
62+ ) ;
63+ let mut new_staking_hotkeys = StakingHotkeys :: < T > :: get ( migration_account) ;
64+ if !new_staking_hotkeys. contains ( old_hotkey) {
65+ new_staking_hotkeys. push ( old_hotkey. clone ( ) ) ;
66+ }
67+ StakingHotkeys :: < T > :: insert ( migration_account, new_staking_hotkeys) ;
68+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 3 ) ) ;
6069
6170 // Get the pending emissions for the NEW hotkey
6271 let pending_emissions_new: u64 = PendingdHotkeyEmission :: < T > :: get ( new_hotkey) ;
6372 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
6473
65- // Add stake to the pending emissions for the new hotkey and the old hotkey
74+ // Add the pending emissions for the new hotkey and the old hotkey
6675 PendingdHotkeyEmission :: < T > :: insert (
6776 new_hotkey,
68- pending_emissions_new
69- . saturating_add ( pending_emissions_old)
70- . saturating_add ( null_stake) ,
77+ pending_emissions_new. saturating_add ( pending_emissions_old) ,
7178 ) ;
7279 weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
7380
@@ -80,19 +87,28 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
8087
8188 let taostats_old_hotkey = "5Hddm3iBFD2GLT5ik7LZnT3XJUnRnN8PoeCFgGQgawUVKNm8" ;
8289 let taostats_new_hotkey = "5GKH9FPPnWSUoeeTJp19wVtd84XqFW4pyK2ijV2GsFbhTrP1" ;
90+ let migration_coldkey = "5D65DoFbapkYzJK17VRQo3HFs7FmMeicbaQern28UNDPypCT" ;
8391
8492 let taostats_old_hk_account = get_account_id_from_ss58 :: < T > ( taostats_old_hotkey) ;
8593 let taostats_new_hk_account = get_account_id_from_ss58 :: < T > ( taostats_new_hotkey) ;
86-
87- match ( taostats_old_hk_account, taostats_new_hk_account) {
88- ( Ok ( taostats_old_hk_acct) , Ok ( taostats_new_hk_acct) ) => {
94+ let migration_ck_account = get_account_id_from_ss58 :: < T > ( migration_coldkey) ;
95+
96+ match (
97+ taostats_old_hk_account,
98+ taostats_new_hk_account,
99+ migration_ck_account. clone ( ) ,
100+ ) {
101+ ( Ok ( taostats_old_hk_acct) , Ok ( taostats_new_hk_acct) , Ok ( migration_ck_account) ) => {
89102 weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
90103 & taostats_old_hk_acct,
91104 & taostats_new_hk_acct,
105+ & migration_ck_account,
92106 ) ) ;
107+ log:: info!( "Migrated pending emissions from taostats old hotkey to new hotkey" ) ;
93108 }
94109 _ => {
95110 log:: warn!( "Failed to get account id from ss58 for taostats hotkeys" ) ;
111+ return weight;
96112 }
97113 }
98114
@@ -102,15 +118,22 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
102118 let datura_old_hk_account = get_account_id_from_ss58 :: < T > ( datura_old_hotkey) ;
103119 let datura_new_hk_account = get_account_id_from_ss58 :: < T > ( datura_new_hotkey) ;
104120
105- match ( datura_old_hk_account, datura_new_hk_account) {
106- ( Ok ( datura_old_hk_acct) , Ok ( datura_new_hk_acct) ) => {
121+ match (
122+ datura_old_hk_account,
123+ datura_new_hk_account,
124+ migration_ck_account,
125+ ) {
126+ ( Ok ( datura_old_hk_acct) , Ok ( datura_new_hk_acct) , Ok ( migration_ck_account) ) => {
107127 weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
108128 & datura_old_hk_acct,
109129 & datura_new_hk_acct,
130+ & migration_ck_account,
110131 ) ) ;
132+ log:: info!( "Migrated pending emissions from datura old hotkey to new hotkey" ) ;
111133 }
112134 _ => {
113135 log:: warn!( "Failed to get account id from ss58 for datura hotkeys" ) ;
136+ return weight;
114137 }
115138 }
116139
0 commit comments