Skip to content

Commit

Permalink
Add some panic documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nibhar authored and hrxi committed May 1, 2024
1 parent 5703786 commit cbb72c8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions primitives/src/slots_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ impl Validators {
}

/// Calculates the slot band of the validator that owns the given slot.
///
/// ## Panic
/// This function requires the slot to be within bounds. If it is not this function will panic.
pub fn get_band_from_slot(&self, slot: u16) -> u16 {
assert!(slot < Policy::SLOTS);

Expand All @@ -151,11 +154,17 @@ impl Validators {
}

/// Returns the validator given the slot number.
///
/// ## Panic
/// This function requires the slot_number to be within bounds. If it is not this function will panic.
pub fn get_validator_by_slot_number(&self, slot_number: u16) -> &Validator {
&self.validators[self.get_band_from_slot(slot_number) as usize]
}

/// Returns the validator given the slot band.
///
/// ## Panic
/// This function requires the slot_band to be within bounds. If it is not this function will panic.
pub fn get_validator_by_slot_band(&self, slot_band: u16) -> &Validator {
&self.validators[slot_band as usize]
}
Expand Down

0 comments on commit cbb72c8

Please sign in to comment.