@@ -364,6 +364,7 @@ impl<T: Config> Pallet<T> {
364
364
ChildKeys :: < T > :: remove ( old_hotkey, netuid) ;
365
365
// Insert the same child entries for the new hotkey
366
366
ChildKeys :: < T > :: insert ( new_hotkey, netuid, my_children. clone ( ) ) ;
367
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
367
368
for ( _, child_key_i) in my_children {
368
369
// For each child, update their parent list
369
370
let mut child_parents: Vec < ( u64 , T :: AccountId ) > =
@@ -376,6 +377,7 @@ impl<T: Config> Pallet<T> {
376
377
}
377
378
// Update the child's parent list
378
379
ParentKeys :: < T > :: insert ( child_key_i, netuid, child_parents) ;
380
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
379
381
}
380
382
}
381
383
@@ -388,6 +390,7 @@ impl<T: Config> Pallet<T> {
388
390
ParentKeys :: < T > :: remove ( old_hotkey, netuid) ;
389
391
// Insert the same parent entries for the new hotkey
390
392
ParentKeys :: < T > :: insert ( new_hotkey, netuid, parents. clone ( ) ) ;
393
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
391
394
for ( _, parent_key_i) in parents {
392
395
// For each parent, update their children list
393
396
let mut parent_children: Vec < ( u64 , T :: AccountId ) > =
@@ -400,11 +403,39 @@ impl<T: Config> Pallet<T> {
400
403
}
401
404
// Update the parent's children list
402
405
ChildKeys :: < T > :: insert ( parent_key_i, netuid, parent_children) ;
406
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
403
407
}
404
408
}
405
409
406
- // 14. Swap Stake Delta for all coldkeys.
407
- // DEPRECATED
410
+ // 14. Swap PendingChildKeys.
411
+ // PendingChildKeys( netuid, parent ) --> Vec<(proportion,child), cool_down_block>
412
+ for netuid in Self :: get_all_subnet_netuids ( ) {
413
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
414
+ if PendingChildKeys :: < T > :: contains_key ( netuid, old_hotkey) {
415
+ let ( children, cool_down_block) = PendingChildKeys :: < T > :: get ( netuid, old_hotkey) ;
416
+ PendingChildKeys :: < T > :: remove ( netuid, old_hotkey) ;
417
+ PendingChildKeys :: < T > :: insert ( netuid, new_hotkey, ( children, cool_down_block) ) ;
418
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
419
+ }
420
+
421
+ // Also check for others with our hotkey as a child
422
+ for ( hotkey, ( children, cool_down_block) ) in PendingChildKeys :: < T > :: iter_prefix ( netuid)
423
+ {
424
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
425
+
426
+ if let Some ( potential_idx) =
427
+ children. iter ( ) . position ( |( _, child) | * child == * old_hotkey)
428
+ {
429
+ let mut new_children = children. clone ( ) ;
430
+ let entry_to_remove = new_children. remove ( potential_idx) ;
431
+ new_children. push ( ( entry_to_remove. 0 , new_hotkey. clone ( ) ) ) ; // Keep the proportion.
432
+
433
+ PendingChildKeys :: < T > :: remove ( netuid, hotkey. clone ( ) ) ;
434
+ PendingChildKeys :: < T > :: insert ( netuid, hotkey, ( new_children, cool_down_block) ) ;
435
+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 2 ) ) ;
436
+ }
437
+ }
438
+ }
408
439
409
440
// Return successful after swapping all the relevant terms.
410
441
Ok ( ( ) )
0 commit comments