diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 3a0f7d02e8..66656d3589 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -779,14 +779,14 @@ impl BeaconState { &mut self, sync_committee: &SyncCommittee, ) -> Result, Error> { - sync_committee - .pubkeys - .iter() - .map(|pubkey| { + let mut indices = Vec::with_capacity(sync_committee.pubkeys.len()); + for pubkey in sync_committee.pubkeys.iter() { + indices.push( self.get_validator_index(pubkey)? - .ok_or(Error::PubkeyCacheInconsistent) - }) - .collect() + .ok_or(Error::PubkeyCacheInconsistent)?, + ) + } + Ok(indices) } /// Compute the sync committee indices for the next sync committee.