@@ -206,33 +206,42 @@ impl<T: Config> Pallet<T> {
206
206
Delegates :: < T > :: insert ( new_hotkey, old_delegate_take) ;
207
207
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
208
208
}
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.
210
219
let all_netuids: Vec < u16 > = Self :: get_all_subnet_netuids ( ) ;
211
220
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.
213
222
// IsNetworkMember( hotkey, netuid ) -> bool -- is the hotkey a subnet member.
214
223
let is_network_member: bool = IsNetworkMember :: < T > :: get ( old_hotkey, netuid) ;
215
224
IsNetworkMember :: < T > :: remove ( old_hotkey, netuid) ;
216
225
IsNetworkMember :: < T > :: insert ( new_hotkey, netuid, is_network_member) ;
217
226
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
218
227
219
- // 9 .2 Swap Uids + Keys.
228
+ // 10 .2 Swap Uids + Keys.
220
229
// Keys( netuid, hotkey ) -> uid -- the uid the hotkey has in the network if it is a member.
221
230
// Uids( netuid, hotkey ) -> uid -- the uids that the hotkey has.
222
231
if is_network_member {
223
- // 9 .2.1 Swap the UIDS
232
+ // 10 .2.1 Swap the UIDS
224
233
if let Ok ( old_uid) = Uids :: < T > :: try_get ( netuid, old_hotkey) {
225
234
Uids :: < T > :: remove ( netuid, old_hotkey) ;
226
235
Uids :: < T > :: insert ( netuid, new_hotkey, old_uid) ;
227
236
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
228
237
229
- // 9 .2.2 Swap the keys.
238
+ // 10 .2.2 Swap the keys.
230
239
Keys :: < T > :: insert ( netuid, old_uid, new_hotkey. clone ( ) ) ;
231
240
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 0 , 1 ) ) ;
232
241
}
233
242
}
234
243
235
- // 9 .3 Swap Prometheus.
244
+ // 10 .3 Swap Prometheus.
236
245
// Prometheus( netuid, hotkey ) -> prometheus -- the prometheus data that a hotkey has in the network.
237
246
if is_network_member {
238
247
if let Ok ( old_prometheus_info) = Prometheus :: < T > :: try_get ( netuid, old_hotkey) {
@@ -242,7 +251,7 @@ impl<T: Config> Pallet<T> {
242
251
}
243
252
}
244
253
245
- // 9 .4. Swap axons.
254
+ // 10 .4. Swap axons.
246
255
// Axons( netuid, hotkey ) -> axon -- the axon that the hotkey has.
247
256
if is_network_member {
248
257
if let Ok ( old_axon_info) = Axons :: < T > :: try_get ( netuid, old_hotkey) {
@@ -252,7 +261,7 @@ impl<T: Config> Pallet<T> {
252
261
}
253
262
}
254
263
255
- // 9 .5 Swap WeightCommits
264
+ // 10 .5 Swap WeightCommits
256
265
// WeightCommits( hotkey ) --> Vec<u64> -- the weight commits for the hotkey.
257
266
if is_network_member {
258
267
if let Ok ( old_weight_commits) = WeightCommits :: < T > :: try_get ( netuid, old_hotkey) {
@@ -262,7 +271,7 @@ impl<T: Config> Pallet<T> {
262
271
}
263
272
}
264
273
265
- // 9 .6. Swap the subnet loaded emission.
274
+ // 10 .6. Swap the subnet loaded emission.
266
275
// LoadedEmission( netuid ) --> Vec<(hotkey, u64)> -- the loaded emission for the subnet.
267
276
if is_network_member {
268
277
if let Some ( mut old_loaded_emission) = LoadedEmission :: < T > :: get ( netuid) {
@@ -277,7 +286,7 @@ impl<T: Config> Pallet<T> {
277
286
}
278
287
}
279
288
280
- // 9 .7. Swap neuron TLS certificates.
289
+ // 10 .7. Swap neuron TLS certificates.
281
290
// NeuronCertificates( netuid, hotkey ) -> Vec<u8> -- the neuron certificate for the hotkey.
282
291
if is_network_member {
283
292
if let Ok ( old_neuron_certificates) =
@@ -290,7 +299,7 @@ impl<T: Config> Pallet<T> {
290
299
}
291
300
}
292
301
293
- // 10 . Swap Stake.
302
+ // 11 . Swap Stake.
294
303
// Stake( hotkey, coldkey ) -> stake -- the stake that the hotkey controls on behalf of the coldkey.
295
304
let stakes: Vec < ( T :: AccountId , u64 ) > = Stake :: < T > :: iter_prefix ( old_hotkey) . collect ( ) ;
296
305
// Clear the entire old prefix here.
@@ -320,7 +329,7 @@ impl<T: Config> Pallet<T> {
320
329
weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
321
330
}
322
331
323
- // 11 . Swap ChildKeys.
332
+ // 12 . Swap ChildKeys.
324
333
// ChildKeys( parent, netuid ) --> Vec<(proportion,child)> -- the child keys of the parent.
325
334
for netuid in Self :: get_all_subnet_netuids ( ) {
326
335
// Get the children of the old hotkey for this subnet
@@ -331,7 +340,7 @@ impl<T: Config> Pallet<T> {
331
340
ChildKeys :: < T > :: insert ( new_hotkey, netuid, my_children) ;
332
341
}
333
342
334
- // 12 . Swap ParentKeys.
343
+ // 13 . Swap ParentKeys.
335
344
// ParentKeys( child, netuid ) --> Vec<(proportion,parent)> -- the parent keys of the child.
336
345
for netuid in Self :: get_all_subnet_netuids ( ) {
337
346
// Get the parents of the old hotkey for this subnet
@@ -355,6 +364,19 @@ impl<T: Config> Pallet<T> {
355
364
}
356
365
}
357
366
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
+
358
380
// Return successful after swapping all the relevant terms.
359
381
Ok ( ( ) )
360
382
}
0 commit comments