@@ -206,33 +206,42 @@ impl<T: Config> Pallet<T> {
206206 Delegates :: < T > :: insert ( new_hotkey, old_delegate_take) ;
207207 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
208208 }
209- // 9. Swap all subnet specific info.
209+
210+ // 9. swap PendingdHotkeyEmission
211+ if PendingdHotkeyEmission :: < T > :: contains_key ( old_hotkey) {
212+ let old_pending_hotkey_emission = PendingdHotkeyEmission :: < T > :: get ( old_hotkey) ;
213+ PendingdHotkeyEmission :: < T > :: remove ( old_hotkey) ;
214+ PendingdHotkeyEmission :: < T > :: insert ( new_hotkey, old_pending_hotkey_emission) ;
215+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
216+ }
217+
218+ // 10. Swap all subnet specific info.
210219 let all_netuids: Vec < u16 > = Self :: get_all_subnet_netuids ( ) ;
211220 for netuid in all_netuids {
212- // 9 .1 Remove the previous hotkey and insert the new hotkey from membership.
221+ // 10 .1 Remove the previous hotkey and insert the new hotkey from membership.
213222 // IsNetworkMember( hotkey, netuid ) -> bool -- is the hotkey a subnet member.
214223 let is_network_member: bool = IsNetworkMember :: < T > :: get ( old_hotkey, netuid) ;
215224 IsNetworkMember :: < T > :: remove ( old_hotkey, netuid) ;
216225 IsNetworkMember :: < T > :: insert ( new_hotkey, netuid, is_network_member) ;
217226 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
218227
219- // 9 .2 Swap Uids + Keys.
228+ // 10 .2 Swap Uids + Keys.
220229 // Keys( netuid, hotkey ) -> uid -- the uid the hotkey has in the network if it is a member.
221230 // Uids( netuid, hotkey ) -> uid -- the uids that the hotkey has.
222231 if is_network_member {
223- // 9 .2.1 Swap the UIDS
232+ // 10 .2.1 Swap the UIDS
224233 if let Ok ( old_uid) = Uids :: < T > :: try_get ( netuid, old_hotkey) {
225234 Uids :: < T > :: remove ( netuid, old_hotkey) ;
226235 Uids :: < T > :: insert ( netuid, new_hotkey, old_uid) ;
227236 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
228237
229- // 9 .2.2 Swap the keys.
238+ // 10 .2.2 Swap the keys.
230239 Keys :: < T > :: insert ( netuid, old_uid, new_hotkey. clone ( ) ) ;
231240 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 0 , 1 ) ) ;
232241 }
233242 }
234243
235- // 9 .3 Swap Prometheus.
244+ // 10 .3 Swap Prometheus.
236245 // Prometheus( netuid, hotkey ) -> prometheus -- the prometheus data that a hotkey has in the network.
237246 if is_network_member {
238247 if let Ok ( old_prometheus_info) = Prometheus :: < T > :: try_get ( netuid, old_hotkey) {
@@ -242,7 +251,7 @@ impl<T: Config> Pallet<T> {
242251 }
243252 }
244253
245- // 9 .4. Swap axons.
254+ // 10 .4. Swap axons.
246255 // Axons( netuid, hotkey ) -> axon -- the axon that the hotkey has.
247256 if is_network_member {
248257 if let Ok ( old_axon_info) = Axons :: < T > :: try_get ( netuid, old_hotkey) {
@@ -252,7 +261,7 @@ impl<T: Config> Pallet<T> {
252261 }
253262 }
254263
255- // 9 .5 Swap WeightCommits
264+ // 10 .5 Swap WeightCommits
256265 // WeightCommits( hotkey ) --> Vec<u64> -- the weight commits for the hotkey.
257266 if is_network_member {
258267 if let Ok ( old_weight_commits) = WeightCommits :: < T > :: try_get ( netuid, old_hotkey) {
@@ -262,7 +271,7 @@ impl<T: Config> Pallet<T> {
262271 }
263272 }
264273
265- // 9 .6. Swap the subnet loaded emission.
274+ // 10 .6. Swap the subnet loaded emission.
266275 // LoadedEmission( netuid ) --> Vec<(hotkey, u64)> -- the loaded emission for the subnet.
267276 if is_network_member {
268277 if let Some ( mut old_loaded_emission) = LoadedEmission :: < T > :: get ( netuid) {
@@ -277,7 +286,7 @@ impl<T: Config> Pallet<T> {
277286 }
278287 }
279288
280- // 9 .7. Swap neuron TLS certificates.
289+ // 10 .7. Swap neuron TLS certificates.
281290 // NeuronCertificates( netuid, hotkey ) -> Vec<u8> -- the neuron certificate for the hotkey.
282291 if is_network_member {
283292 if let Ok ( old_neuron_certificates) =
@@ -290,7 +299,7 @@ impl<T: Config> Pallet<T> {
290299 }
291300 }
292301
293- // 10 . Swap Stake.
302+ // 11 . Swap Stake.
294303 // Stake( hotkey, coldkey ) -> stake -- the stake that the hotkey controls on behalf of the coldkey.
295304 let stakes: Vec < ( T :: AccountId , u64 ) > = Stake :: < T > :: iter_prefix ( old_hotkey) . collect ( ) ;
296305 // Clear the entire old prefix here.
@@ -320,7 +329,7 @@ impl<T: Config> Pallet<T> {
320329 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
321330 }
322331
323- // 11 . Swap ChildKeys.
332+ // 12 . Swap ChildKeys.
324333 // ChildKeys( parent, netuid ) --> Vec<(proportion,child)> -- the child keys of the parent.
325334 for netuid in Self :: get_all_subnet_netuids ( ) {
326335 // Get the children of the old hotkey for this subnet
@@ -331,7 +340,7 @@ impl<T: Config> Pallet<T> {
331340 ChildKeys :: < T > :: insert ( new_hotkey, netuid, my_children) ;
332341 }
333342
334- // 12 . Swap ParentKeys.
343+ // 13 . Swap ParentKeys.
335344 // ParentKeys( child, netuid ) --> Vec<(proportion,parent)> -- the parent keys of the child.
336345 for netuid in Self :: get_all_subnet_netuids ( ) {
337346 // Get the parents of the old hotkey for this subnet
@@ -355,6 +364,19 @@ impl<T: Config> Pallet<T> {
355364 }
356365 }
357366
367+ // 14. Swap Stake Delta for all coldkeys.
368+ for ( coldkey, stake_delta) in StakeDeltaSinceLastEmissionDrain :: < T > :: iter_prefix ( old_hotkey)
369+ {
370+ let new_stake_delta = StakeDeltaSinceLastEmissionDrain :: < T > :: get ( new_hotkey, & coldkey) ;
371+ StakeDeltaSinceLastEmissionDrain :: < T > :: insert (
372+ new_hotkey,
373+ & coldkey,
374+ new_stake_delta. saturating_add ( stake_delta) ,
375+ ) ;
376+ StakeDeltaSinceLastEmissionDrain :: < T > :: remove ( old_hotkey, & coldkey) ;
377+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
378+ }
379+
358380 // Return successful after swapping all the relevant terms.
359381 Ok ( ( ) )
360382 }
0 commit comments