@@ -560,29 +560,31 @@ pub fn migrate_populate_staking_hotkeys<T: Config>() -> Weight {
560560 let mut storage_writes: u64 = 0 ;
561561
562562 // Iterate through all Owner entries
563- Stake :: < T > :: iter ( ) . for_each ( |( hotkey, coldkey, _stake ) | {
563+ Stake :: < T > :: iter ( ) . for_each ( |( hotkey, coldkey, stake ) | {
564564 storage_reads = storage_reads. saturating_add ( 1 ) ; // Read from Owner storage
565- let mut hotkeys = StakingHotkeys :: < T > :: get ( & coldkey) ;
566- storage_reads = storage_reads. saturating_add ( 1 ) ; // Read from StakingHotkeys storage
567-
568- // Add the hotkey if it's not already in the vector
569- if !hotkeys. contains ( & hotkey) {
570- hotkeys. push ( hotkey) ;
571- keys_touched = keys_touched. saturating_add ( 1 ) ;
572-
573- // Update longest hotkey vector info
574- if longest_hotkey_vector < hotkeys. len ( ) {
575- longest_hotkey_vector = hotkeys. len ( ) ;
576- longest_coldkey = Some ( coldkey. clone ( ) ) ;
565+ if stake > 0 {
566+ let mut hotkeys = StakingHotkeys :: < T > :: get ( & coldkey) ;
567+ storage_reads = storage_reads. saturating_add ( 1 ) ; // Read from StakingHotkeys storage
568+
569+ // Add the hotkey if it's not already in the vector
570+ if !hotkeys. contains ( & hotkey) {
571+ hotkeys. push ( hotkey) ;
572+ keys_touched = keys_touched. saturating_add ( 1 ) ;
573+
574+ // Update longest hotkey vector info
575+ if longest_hotkey_vector < hotkeys. len ( ) {
576+ longest_hotkey_vector = hotkeys. len ( ) ;
577+ longest_coldkey = Some ( coldkey. clone ( ) ) ;
578+ }
579+
580+ // Update the StakingHotkeys storage
581+ StakingHotkeys :: < T > :: insert ( & coldkey, hotkeys) ;
582+ storage_writes = storage_writes. saturating_add ( 1 ) ; // Write to StakingHotkeys storage
577583 }
578-
579- // Update the StakingHotkeys storage
580- StakingHotkeys :: < T > :: insert ( & coldkey, hotkeys) ;
581- storage_writes = storage_writes. saturating_add ( 1 ) ; // Write to StakingHotkeys storage
584+
585+ // Accrue weight for reads and writes
586+ weight = weight. saturating_add ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 1 ) ) ;
582587 }
583-
584- // Accrue weight for reads and writes
585- weight = weight. saturating_add ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 1 ) ) ;
586588 } ) ;
587589
588590 // Log migration results
0 commit comments