Skip to content

Commit

Permalink
fail early if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Aug 2, 2023
1 parent dfcb336 commit b22d1d7
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 b22d1d7

Please sign in to comment.