Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - CommitteeCache.initialized: fail early if possible #4556

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading