Skip to content

Commit

Permalink
CommitteeCache.initialized: fail early if possible (#4556)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Aug 2, 2023
1 parent fcf51d6 commit b5e25ae
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions consensus/types/src/beacon_state/committee_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ impl CommitteeCache {
return Err(Error::ZeroSlotsPerEpoch);
}

// The use of `NonZeroUsize` reduces the maximum number of possible validators by one.
if state.validators().len() == usize::max_value() {
return Err(Error::TooManyValidators);
}

let active_validator_indices = get_active_validator_indices(state.validators(), epoch);

if active_validator_indices.is_empty() {
Expand All @@ -75,11 +80,6 @@ impl CommitteeCache {
)
.ok_or(Error::UnableToShuffle)?;

// The use of `NonZeroUsize` reduces the maximum number of possible validators by one.
if state.validators().len() == usize::max_value() {
return Err(Error::TooManyValidators);
}

let mut shuffling_positions = vec![<_>::default(); state.validators().len()];
for (i, &v) in shuffling.iter().enumerate() {
*shuffling_positions
Expand Down

0 comments on commit b5e25ae

Please sign in to comment.