From 27581c0ff4e191313af8257a402c7ac65b9a642c Mon Sep 17 00:00:00 2001 From: Age Date: Wed, 19 Sep 2018 16:25:39 +1000 Subject: [PATCH] Implement generalised error ParameterError --- .../state/transition/attestation_parent_hashes.rs | 14 +++++++------- lighthouse/state/transition/mod.rs | 7 +------ lighthouse/utils/errors.rs | 11 ++++++++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lighthouse/state/transition/attestation_parent_hashes.rs b/lighthouse/state/transition/attestation_parent_hashes.rs index 624d8c4437..f635972b2c 100644 --- a/lighthouse/state/transition/attestation_parent_hashes.rs +++ b/lighthouse/state/transition/attestation_parent_hashes.rs @@ -1,5 +1,5 @@ use super::Hash256; -use super::TransitionError; +use super::ParameterError; /// This function is used to select the hashes used in /// the signing of an AttestationRecord. @@ -18,22 +18,22 @@ pub fn attestation_parent_hashes( attestation_slot: &u64, current_hashes: &Vec, oblique_hashes: &Vec) - -> Result, TransitionError> + -> Result, ParameterError> { // This cast places a limit on cycle_length. If you change it, check math // for overflow. let cycle_length: u64 = *cycle_length as u64; if current_hashes.len() as u64 != (cycle_length * 2) { - return Err(TransitionError::InvalidInput(String::from( + return Err(ParameterError::InvalidInput(String::from( "current_hashes.len() must equal cycle_length * 2"))); } if attestation_slot >= block_slot { - return Err(TransitionError::InvalidInput(String::from( + return Err(ParameterError::InvalidInput(String::from( "attestation_slot must be less than block_slot"))); } if oblique_hashes.len() as u64 > cycle_length { - return Err(TransitionError::InvalidInput(String::from( + return Err(ParameterError::InvalidInput(String::from( "oblique_hashes.len() must be <= cycle_length * 2"))); } @@ -44,7 +44,7 @@ pub fn attestation_parent_hashes( let attestation_distance = block_slot - attestation_slot; if attestation_distance > cycle_length { - return Err(TransitionError::InvalidInput(String::from( + return Err(ParameterError::InvalidInput(String::from( "attestation_slot must be withing one cycle of block_slot"))); } @@ -63,7 +63,7 @@ pub fn attestation_parent_hashes( */ let end = start.checked_add(cycle_length) .and_then(|x| x.checked_sub(oblique_hashes.len() as u64)) - .ok_or(TransitionError::IntWrapping)?; + .ok_or(ParameterError::IntWrapping)?; let mut hashes = Vec::new(); diff --git a/lighthouse/state/transition/mod.rs b/lighthouse/state/transition/mod.rs index dd8967e652..f3da910276 100644 --- a/lighthouse/state/transition/mod.rs +++ b/lighthouse/state/transition/mod.rs @@ -1,4 +1,5 @@ use super::super::utils::types::Hash256; +use super::super::utils::errors::ParameterError; mod attestation_parent_hashes; mod shuffling; @@ -6,12 +7,6 @@ mod shuffling; pub use self::attestation_parent_hashes::attestation_parent_hashes; pub use self::shuffling::shuffle; -#[derive(Debug)] -pub enum TransitionError { - IntWrapping, - OutOfBounds, - InvalidInput(String), -} diff --git a/lighthouse/utils/errors.rs b/lighthouse/utils/errors.rs index 4f12cfbdd6..2a25b29b8e 100644 --- a/lighthouse/utils/errors.rs +++ b/lighthouse/utils/errors.rs @@ -1,7 +1,7 @@ -// Collection of custom errors +// Collection of custom errors #[derive(Debug,PartialEq)] -pub enum AttestationValidationError { +pub enum AttestationValidationError { SlotTooHigh, SlotTooLow(String), IncorrectBitField, @@ -9,4 +9,9 @@ pub enum AttestationValidationError { AggregateSignatureFail } - +#[derive(Debug,PartialEq)] +pub enum ParameterError { + IntWrapping, + OutOfBounds, + InvalidInput(String), +}