@@ -5,7 +5,7 @@ use types::{
55 NUM_FLAG_INDICES , TIMELY_HEAD_FLAG_INDEX , TIMELY_SOURCE_FLAG_INDEX ,
66 TIMELY_TARGET_FLAG_INDEX ,
77 } ,
8- BeaconState , BeaconStateError , ChainSpec , Epoch , EthSpec , ParticipationFlags ,
8+ BeaconState , BeaconStateError , ChainSpec , Epoch , EthSpec , ParticipationFlags , RelativeEpoch ,
99} ;
1010
1111#[ derive( PartialEq , Debug ) ]
@@ -176,16 +176,22 @@ fn get_epoch_participation<T: EthSpec>(
176176 epoch : Epoch ,
177177 spec : & ChainSpec ,
178178) -> Result < EpochParticipation , BeaconStateError > {
179- let epoch_participation = if epoch == state. current_epoch ( ) {
180- state. current_epoch_participation ( ) ?
179+ let epoch_participation;
180+ let active_validator_indices;
181+
182+ if epoch == state. current_epoch ( ) {
183+ active_validator_indices =
184+ state. get_cached_active_validator_indices ( RelativeEpoch :: Current ) ?;
185+ epoch_participation = state. current_epoch_participation ( ) ?
181186 } else if epoch == state. previous_epoch ( ) {
182- state. previous_epoch_participation ( ) ?
187+ active_validator_indices =
188+ state. get_cached_active_validator_indices ( RelativeEpoch :: Previous ) ?;
189+ epoch_participation = state. previous_epoch_participation ( ) ?
183190 } else {
184191 return Err ( BeaconStateError :: EpochOutOfBounds ) ;
185192 } ;
186193
187194 // It's possible this Vec is larger than necessary due to slashed validators.
188- let active_validator_indices = state. get_active_validator_indices ( epoch, spec) ?;
189195 let mut unslashed_participating_indices =
190196 HashMap :: with_capacity ( active_validator_indices. len ( ) ) ;
191197 let mut total_flag_balances = [ 0 ; NUM_FLAG_INDICES ] ;
@@ -200,7 +206,7 @@ fn get_epoch_participation<T: EthSpec>(
200206 None
201207 } ;
202208
203- for val_index in active_validator_indices {
209+ for & val_index in active_validator_indices {
204210 let val_balance = state. get_effective_balance ( val_index) ?;
205211 total_active_balance. safe_add_assign ( val_balance) ?;
206212
0 commit comments