@@ -4,7 +4,7 @@ use eth2::types::{
44 self as api_types, ExecutionOptimisticFinalizedResponse , ValidatorBalanceData , ValidatorData ,
55 ValidatorId , ValidatorStatus ,
66} ;
7- use std:: sync:: Arc ;
7+ use std:: { collections :: HashSet , sync:: Arc } ;
88
99pub fn get_beacon_state_validators < T : BeaconChainTypes > (
1010 state_id : StateId ,
@@ -18,6 +18,8 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
1818 |state, execution_optimistic, finalized| {
1919 let epoch = state. current_epoch ( ) ;
2020 let far_future_epoch = chain. spec . far_future_epoch ;
21+ let ids_filter_set: Option < HashSet < & ValidatorId > > =
22+ query_ids. as_ref ( ) . map ( |f| HashSet :: from_iter ( f) ) ;
2123
2224 Ok ( (
2325 state
@@ -27,13 +29,9 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
2729 . enumerate ( )
2830 // filter by validator id(s) if provided
2931 . filter ( |( index, ( validator, _) ) | {
30- query_ids. as_ref ( ) . map_or ( true , |ids| {
31- ids. iter ( ) . any ( |id| match id {
32- ValidatorId :: PublicKey ( pubkey) => & validator. pubkey == pubkey,
33- ValidatorId :: Index ( param_index) => {
34- * param_index == * index as u64
35- }
36- } )
32+ ids_filter_set. as_ref ( ) . map_or ( true , |ids_set| {
33+ ids_set. contains ( & ValidatorId :: PublicKey ( validator. pubkey ) )
34+ || ids_set. contains ( & ValidatorId :: Index ( * index as u64 ) )
3735 } )
3836 } )
3937 // filter by status(es) if provided and map the result
@@ -83,6 +81,9 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
8381 . map_state_and_execution_optimistic_and_finalized (
8482 & chain,
8583 |state, execution_optimistic, finalized| {
84+ let ids_filter_set: Option < HashSet < & ValidatorId > > =
85+ optional_ids. map ( |f| HashSet :: from_iter ( f. iter ( ) ) ) ;
86+
8687 Ok ( (
8788 state
8889 . validators ( )
@@ -91,13 +92,9 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
9192 . enumerate ( )
9293 // filter by validator id(s) if provided
9394 . filter ( |( index, ( validator, _) ) | {
94- optional_ids. map_or ( true , |ids| {
95- ids. iter ( ) . any ( |id| match id {
96- ValidatorId :: PublicKey ( pubkey) => & validator. pubkey == pubkey,
97- ValidatorId :: Index ( param_index) => {
98- * param_index == * index as u64
99- }
100- } )
95+ ids_filter_set. as_ref ( ) . map_or ( true , |ids_set| {
96+ ids_set. contains ( & ValidatorId :: PublicKey ( validator. pubkey ) )
97+ || ids_set. contains ( & ValidatorId :: Index ( * index as u64 ) )
10198 } )
10299 } )
103100 . map ( |( index, ( _, balance) ) | ValidatorBalanceData {
0 commit comments