Skip to content

Commit

Permalink
CommitteeCache.initialized: fail early if possible (sigp#4556)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu authored and Woodpile37 committed Jan 6, 2024
1 parent 3b8baee commit d40c073
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 d40c073

Please sign in to comment.