@@ -60,7 +60,8 @@ impl<T: Config> Pallet<T> {
6060 // ===========
6161
6262 let hotkeys: Vec < ( u16 , T :: AccountId ) > =
63- <Keys < T > as IterableStorageDoubleMap < u16 , u16 , T :: AccountId > >:: iter_prefix ( netuid) . collect ( ) ;
63+ <Keys < T > as IterableStorageDoubleMap < u16 , u16 , T :: AccountId > >:: iter_prefix ( netuid)
64+ . collect ( ) ;
6465 log:: trace!( "hotkeys: {:?}" , & hotkeys) ;
6566
6667 // Access network stake as normalized vector.
@@ -306,24 +307,35 @@ impl<T: Config> Pallet<T> {
306307
307308 // Column max-upscale EMA bonds for storage: max_i w_ij = 1.
308309 inplace_col_max_upscale ( & mut ema_bonds) ;
309- new_validator_permits. iter ( ) . zip ( validator_permits) . zip ( ema_bonds) . enumerate ( ) . for_each ( |( i, ( ( new_permit, validator_permit) , ema_bond) ) | {
310- // Set bonds only if uid retains validator permit, otherwise clear bonds.
311- if * new_permit {
312- let new_bonds_row: Vec < ( u16 , u16 ) > = ( 0 ..n)
313- . zip ( vec_fixed_proportions_to_u16 ( ema_bond. clone ( ) ) )
314- . collect ( ) ;
315- Bonds :: < T > :: insert ( netuid, i as u16 , new_bonds_row) ;
316- } else if validator_permit {
317- // Only overwrite the intersection.
318- let new_empty_bonds_row: Vec < ( u16 , u16 ) > = vec ! [ ] ;
319- Bonds :: < T > :: insert ( netuid, i as u16 , new_empty_bonds_row) ;
320- }
321- } ) ;
310+ new_validator_permits
311+ . iter ( )
312+ . zip ( validator_permits)
313+ . zip ( ema_bonds)
314+ . enumerate ( )
315+ . for_each ( |( i, ( ( new_permit, validator_permit) , ema_bond) ) | {
316+ // Set bonds only if uid retains validator permit, otherwise clear bonds.
317+ if * new_permit {
318+ let new_bonds_row: Vec < ( u16 , u16 ) > = ( 0 ..n)
319+ . zip ( vec_fixed_proportions_to_u16 ( ema_bond. clone ( ) ) )
320+ . collect ( ) ;
321+ Bonds :: < T > :: insert ( netuid, i as u16 , new_bonds_row) ;
322+ } else if validator_permit {
323+ // Only overwrite the intersection.
324+ let new_empty_bonds_row: Vec < ( u16 , u16 ) > = vec ! [ ] ;
325+ Bonds :: < T > :: insert ( netuid, i as u16 , new_empty_bonds_row) ;
326+ }
327+ } ) ;
322328
323- hotkeys. into_iter ( ) . map ( |( uid_i, hotkey) | {
324- ( hotkey, server_emission[ uid_i as usize ] , validator_emission[ uid_i as usize ] )
325- } )
326- . collect ( )
329+ hotkeys
330+ . into_iter ( )
331+ . map ( |( uid_i, hotkey) | {
332+ (
333+ hotkey,
334+ server_emission[ uid_i as usize ] ,
335+ validator_emission[ uid_i as usize ] ,
336+ )
337+ } )
338+ . collect ( )
327339 }
328340
329341 // Calculates reward consensus values, then updates rank, trust, consensus, incentive, dividend, pruning_score, emission and bonds, and
@@ -380,7 +392,8 @@ impl<T: Config> Pallet<T> {
380392 // ===========
381393
382394 let hotkeys: Vec < ( u16 , T :: AccountId ) > =
383- <Keys < T > as IterableStorageDoubleMap < u16 , u16 , T :: AccountId > >:: iter_prefix ( netuid) . collect ( ) ;
395+ <Keys < T > as IterableStorageDoubleMap < u16 , u16 , T :: AccountId > >:: iter_prefix ( netuid)
396+ . collect ( ) ;
384397 log:: trace!( "hotkeys: {:?}" , & hotkeys) ;
385398
386399 // Access network stake as normalized vector.
@@ -675,10 +688,16 @@ impl<T: Config> Pallet<T> {
675688 } ) ;
676689
677690 // Emission tuples ( hotkeys, server_emission, validator_emission )
678- hotkeys. into_iter ( ) . map ( |( uid_i, hotkey) | {
679- ( hotkey, server_emission[ uid_i as usize ] , validator_emission[ uid_i as usize ] )
680- } )
681- . collect ( )
691+ hotkeys
692+ . into_iter ( )
693+ . map ( |( uid_i, hotkey) | {
694+ (
695+ hotkey,
696+ server_emission[ uid_i as usize ] ,
697+ validator_emission[ uid_i as usize ] ,
698+ )
699+ } )
700+ . collect ( )
682701 }
683702
684703 pub fn get_float_rho ( netuid : u16 ) -> I32F32 {
@@ -690,25 +709,27 @@ impl<T: Config> Pallet<T> {
690709
691710 pub fn get_normalized_stake ( netuid : u16 ) -> Vec < I32F32 > {
692711 let n = Self :: get_subnetwork_n ( netuid) ;
693- let mut stake_64: Vec < I64F64 > = ( 0 ..n) . map ( |neuron_uid| I64F64 :: from_num (
694- Self :: get_stake_for_uid_and_subnetwork ( netuid, neuron_uid) ,
695- ) )
696- . collect ( ) ;
712+ let mut stake_64: Vec < I64F64 > = ( 0 ..n)
713+ . map ( |neuron_uid| {
714+ I64F64 :: from_num ( Self :: get_stake_for_uid_and_subnetwork ( netuid, neuron_uid) )
715+ } )
716+ . collect ( ) ;
697717 inplace_normalize_64 ( & mut stake_64) ;
698718 let stake: Vec < I32F32 > = vec_fixed64_to_fixed32 ( stake_64) ;
699719 stake
700720 }
701721
702722 pub fn get_block_at_registration ( netuid : u16 ) -> Vec < u64 > {
703723 let n = Self :: get_subnetwork_n ( netuid) ;
704- let block_at_registration: Vec < u64 > = ( 0 ..n) . map ( |neuron_uid| {
705- if Keys :: < T > :: contains_key ( netuid, neuron_uid) {
706- Self :: get_neuron_block_at_registration ( netuid, neuron_uid)
707- } else {
708- 0
709- }
710- } )
711- . collect ( ) ;
724+ let block_at_registration: Vec < u64 > = ( 0 ..n)
725+ . map ( |neuron_uid| {
726+ if Keys :: < T > :: contains_key ( netuid, neuron_uid) {
727+ Self :: get_neuron_block_at_registration ( netuid, neuron_uid)
728+ } else {
729+ 0
730+ }
731+ } )
732+ . collect ( ) ;
712733 block_at_registration
713734 }
714735
0 commit comments