@@ -19,6 +19,7 @@ fn get_account_id_from_ss58<T: Config>(ss58_str: &str) -> Result<T::AccountId, c
19
19
fn migrate_pending_emissions_including_null_stake < T : Config > (
20
20
old_hotkey : & T :: AccountId ,
21
21
new_hotkey : & T :: AccountId ,
22
+ migration_account : & T :: AccountId ,
22
23
) -> Weight {
23
24
let mut weight = T :: DbWeight :: get ( ) . reads ( 0 ) ;
24
25
let null_account = & DefaultAccount :: < T > :: get ( ) ;
@@ -30,10 +31,10 @@ fn migrate_pending_emissions_including_null_stake<T: Config>(
30
31
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
31
32
32
33
// 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) ;
34
35
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
35
36
// Remove
36
- Stake :: < T > :: remove ( & old_hotkey, null_account) ;
37
+ Stake :: < T > :: remove ( old_hotkey, null_account) ;
37
38
weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
38
39
39
40
let new_total_coldkey_stake =
@@ -45,29 +46,35 @@ fn migrate_pending_emissions_including_null_stake<T: Config>(
45
46
}
46
47
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
47
48
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 ) ;
54
55
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
55
56
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 ) ) ;
60
69
61
70
// Get the pending emissions for the NEW hotkey
62
71
let pending_emissions_new: u64 = PendingdHotkeyEmission :: < T > :: get ( new_hotkey) ;
63
72
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
64
73
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
66
75
PendingdHotkeyEmission :: < T > :: insert (
67
76
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) ,
71
78
) ;
72
79
weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
73
80
@@ -80,19 +87,28 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
80
87
81
88
let taostats_old_hotkey = "5Hddm3iBFD2GLT5ik7LZnT3XJUnRnN8PoeCFgGQgawUVKNm8" ;
82
89
let taostats_new_hotkey = "5GKH9FPPnWSUoeeTJp19wVtd84XqFW4pyK2ijV2GsFbhTrP1" ;
90
+ let migration_coldkey = "5D65DoFbapkYzJK17VRQo3HFs7FmMeicbaQern28UNDPypCT" ;
83
91
84
92
let taostats_old_hk_account = get_account_id_from_ss58 :: < T > ( taostats_old_hotkey) ;
85
93
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) ) => {
89
102
weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
90
103
& taostats_old_hk_acct,
91
104
& taostats_new_hk_acct,
105
+ & migration_ck_account,
92
106
) ) ;
107
+ log:: info!( "Migrated pending emissions from taostats old hotkey to new hotkey" ) ;
93
108
}
94
109
_ => {
95
110
log:: warn!( "Failed to get account id from ss58 for taostats hotkeys" ) ;
111
+ return weight;
96
112
}
97
113
}
98
114
@@ -102,15 +118,22 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
102
118
let datura_old_hk_account = get_account_id_from_ss58 :: < T > ( datura_old_hotkey) ;
103
119
let datura_new_hk_account = get_account_id_from_ss58 :: < T > ( datura_new_hotkey) ;
104
120
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) ) => {
107
127
weight. saturating_accrue ( migrate_pending_emissions_including_null_stake :: < T > (
108
128
& datura_old_hk_acct,
109
129
& datura_new_hk_acct,
130
+ & migration_ck_account,
110
131
) ) ;
132
+ log:: info!( "Migrated pending emissions from datura old hotkey to new hotkey" ) ;
111
133
}
112
134
_ => {
113
135
log:: warn!( "Failed to get account id from ss58 for datura hotkeys" ) ;
136
+ return weight;
114
137
}
115
138
}
116
139
0 commit comments