@@ -4,7 +4,7 @@ use eth2::types::{
4
4
self as api_types, ExecutionOptimisticFinalizedResponse , ValidatorBalanceData , ValidatorData ,
5
5
ValidatorId , ValidatorStatus ,
6
6
} ;
7
- use std:: sync:: Arc ;
7
+ use std:: { collections :: HashSet , sync:: Arc } ;
8
8
9
9
pub fn get_beacon_state_validators < T : BeaconChainTypes > (
10
10
state_id : StateId ,
@@ -18,6 +18,8 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
18
18
|state, execution_optimistic, finalized| {
19
19
let epoch = state. current_epoch ( ) ;
20
20
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) ) ;
21
23
22
24
Ok ( (
23
25
state
@@ -27,13 +29,9 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
27
29
. enumerate ( )
28
30
// filter by validator id(s) if provided
29
31
. 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 ) )
37
35
} )
38
36
} )
39
37
// filter by status(es) if provided and map the result
@@ -83,6 +81,9 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
83
81
. map_state_and_execution_optimistic_and_finalized (
84
82
& chain,
85
83
|state, execution_optimistic, finalized| {
84
+ let ids_filter_set: Option < HashSet < & ValidatorId > > =
85
+ optional_ids. map ( |f| HashSet :: from_iter ( f. iter ( ) ) ) ;
86
+
86
87
Ok ( (
87
88
state
88
89
. validators ( )
@@ -91,13 +92,9 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
91
92
. enumerate ( )
92
93
// filter by validator id(s) if provided
93
94
. 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 ) )
101
98
} )
102
99
} )
103
100
. map ( |( index, ( _, balance) ) | ValidatorBalanceData {
0 commit comments