Add some clarifying doc comments

This commit is contained in:
Alex Stokes 2019-01-15 21:20:09 -08:00
parent 01a20acb12
commit 306bcd6f8d
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086
2 changed files with 5 additions and 0 deletions

View File

@ -21,6 +21,7 @@ impl From<StatusFlagsDecodeError> for DecodeError {
}
}
/// Handles the serialization logic for the `status_flags` field of the `ValidatorRecord`.
fn status_flag_to_byte(flag: Option<StatusFlags>) -> u8 {
if let Some(flag) = flag {
match flag {
@ -32,6 +33,7 @@ fn status_flag_to_byte(flag: Option<StatusFlags>) -> u8 {
}
}
/// Handles the deserialization logic for the `status_flags` field of the `ValidatorRecord`.
fn status_flag_from_byte(flag: u8) -> Result<Option<StatusFlags>, StatusFlagsDecodeError> {
match flag {
0 => Ok(None),
@ -59,12 +61,14 @@ pub struct ValidatorRecord {
}
impl ValidatorRecord {
/// This predicate indicates if the validator represented by this record is considered "active" at `slot`.
pub fn is_active_at(&self, slot: u64) -> bool {
self.activation_slot <= slot && slot < self.exit_slot
}
}
impl Default for ValidatorRecord {
/// Yields a "default" `ValidatorRecord`. Primarily used for testing.
fn default() -> Self {
Self {
pubkey: PublicKey::default(),

View File

@ -2,6 +2,7 @@
/// For now, we avoid defining a newtype and just have flat functions here.
use super::validator_record::*;
/// Given an indexed sequence of `validators`, return the indices corresponding to validators that are active at `slot`.
pub fn get_active_validator_indices(validators: &[ValidatorRecord], slot: u64) -> Vec<usize> {
validators
.iter()