@@ -13,7 +13,6 @@ struct EpochParticipation {
1313 unslashed_participating_indices : HashMap < usize , ParticipationFlags > ,
1414 total_flag_balances : [ u64 ; NUM_FLAG_INDICES ] ,
1515 total_active_balance : u64 ,
16- eligible_indices_opt : Option < Vec < usize > > ,
1716}
1817
1918#[ derive( PartialEq , Debug ) ]
@@ -22,6 +21,7 @@ pub struct ParticipationCache {
2221 current_epoch_participation : EpochParticipation ,
2322 previous_epoch : Epoch ,
2423 previous_epoch_participation : EpochParticipation ,
24+ eligible_indices : Vec < usize > ,
2525}
2626
2727impl ParticipationCache {
@@ -37,14 +37,12 @@ impl ParticipationCache {
3737 current_epoch_participation : get_epoch_participation ( state, current_epoch, spec) ?,
3838 previous_epoch,
3939 previous_epoch_participation : get_epoch_participation ( state, previous_epoch, spec) ?,
40+ eligible_indices : state. get_eligible_validator_indices ( ) ?,
4041 } )
4142 }
4243
43- pub fn eligible_validator_indices ( & self ) -> Result < & [ usize ] , BeaconStateError > {
44- self . previous_epoch_participation
45- . eligible_indices_opt
46- . as_deref ( )
47- . ok_or ( BeaconStateError :: EpochOutOfBounds )
44+ pub fn eligible_validator_indices ( & self ) -> & [ usize ] {
45+ & self . eligible_indices
4846 }
4947
5048 pub fn previous_epoch_total_active_balance ( & self ) -> u64 {
@@ -182,11 +180,11 @@ fn get_epoch_participation<T: EthSpec>(
182180 if epoch == state. current_epoch ( ) {
183181 active_validator_indices =
184182 state. get_cached_active_validator_indices ( RelativeEpoch :: Current ) ?;
185- epoch_participation = state. current_epoch_participation ( ) ?
183+ epoch_participation = state. current_epoch_participation ( ) ?;
186184 } else if epoch == state. previous_epoch ( ) {
187185 active_validator_indices =
188186 state. get_cached_active_validator_indices ( RelativeEpoch :: Previous ) ?;
189- epoch_participation = state. previous_epoch_participation ( ) ?
187+ epoch_participation = state. previous_epoch_participation ( ) ?;
190188 } else {
191189 return Err ( BeaconStateError :: EpochOutOfBounds ) ;
192190 } ;
@@ -196,26 +194,11 @@ fn get_epoch_participation<T: EthSpec>(
196194 HashMap :: with_capacity ( active_validator_indices. len ( ) ) ;
197195 let mut total_flag_balances = [ 0 ; NUM_FLAG_INDICES ] ;
198196 let mut total_active_balance = 0 ;
199- let mut eligible_indices_opt = if epoch == state. previous_epoch ( ) {
200- // This Vec might be the wrong size since it'll be filled with the *previous* epoch values,
201- // no current epoch values.
202- //
203- // The difference should be fairly small and there's little impact otherwise.
204- Some ( Vec :: with_capacity ( active_validator_indices. len ( ) ) )
205- } else {
206- None
207- } ;
208197
209198 for & val_index in active_validator_indices {
210199 let val_balance = state. get_effective_balance ( val_index) ?;
211200 total_active_balance. safe_add_assign ( val_balance) ?;
212201
213- if let Some ( eligible_indices) = & mut eligible_indices_opt {
214- if state. is_eligible_validator ( val_index) ? {
215- eligible_indices. push ( val_index)
216- }
217- }
218-
219202 if !state. get_validator ( val_index) ?. slashed {
220203 // Iterate through all the flags and increment total balances.
221204 total_flag_balances
@@ -248,10 +231,11 @@ fn get_epoch_participation<T: EthSpec>(
248231 * balance = std:: cmp:: max ( * balance, spec. effective_balance_increment )
249232 }
250233
234+ unslashed_participating_indices. shrink_to_fit ( ) ;
235+
251236 Ok ( EpochParticipation {
252237 unslashed_participating_indices,
253238 total_flag_balances,
254239 total_active_balance,
255- eligible_indices_opt,
256240 } )
257241}
0 commit comments