Implement generalised error ParameterError
This commit is contained in:
parent
815180d88c
commit
27581c0ff4
@ -1,5 +1,5 @@
|
|||||||
use super::Hash256;
|
use super::Hash256;
|
||||||
use super::TransitionError;
|
use super::ParameterError;
|
||||||
|
|
||||||
/// This function is used to select the hashes used in
|
/// This function is used to select the hashes used in
|
||||||
/// the signing of an AttestationRecord.
|
/// the signing of an AttestationRecord.
|
||||||
@ -18,22 +18,22 @@ pub fn attestation_parent_hashes(
|
|||||||
attestation_slot: &u64,
|
attestation_slot: &u64,
|
||||||
current_hashes: &Vec<Hash256>,
|
current_hashes: &Vec<Hash256>,
|
||||||
oblique_hashes: &Vec<Hash256>)
|
oblique_hashes: &Vec<Hash256>)
|
||||||
-> Result<Vec<Hash256>, TransitionError>
|
-> Result<Vec<Hash256>, ParameterError>
|
||||||
{
|
{
|
||||||
// This cast places a limit on cycle_length. If you change it, check math
|
// This cast places a limit on cycle_length. If you change it, check math
|
||||||
// for overflow.
|
// for overflow.
|
||||||
let cycle_length: u64 = *cycle_length as u64;
|
let cycle_length: u64 = *cycle_length as u64;
|
||||||
|
|
||||||
if current_hashes.len() as u64 != (cycle_length * 2) {
|
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")));
|
"current_hashes.len() must equal cycle_length * 2")));
|
||||||
}
|
}
|
||||||
if attestation_slot >= block_slot {
|
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")));
|
"attestation_slot must be less than block_slot")));
|
||||||
}
|
}
|
||||||
if oblique_hashes.len() as u64 > cycle_length {
|
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")));
|
"oblique_hashes.len() must be <= cycle_length * 2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ pub fn attestation_parent_hashes(
|
|||||||
let attestation_distance = block_slot - attestation_slot;
|
let attestation_distance = block_slot - attestation_slot;
|
||||||
|
|
||||||
if attestation_distance > cycle_length {
|
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")));
|
"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)
|
let end = start.checked_add(cycle_length)
|
||||||
.and_then(|x| x.checked_sub(oblique_hashes.len() as u64))
|
.and_then(|x| x.checked_sub(oblique_hashes.len() as u64))
|
||||||
.ok_or(TransitionError::IntWrapping)?;
|
.ok_or(ParameterError::IntWrapping)?;
|
||||||
|
|
||||||
|
|
||||||
let mut hashes = Vec::new();
|
let mut hashes = Vec::new();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::super::utils::types::Hash256;
|
use super::super::utils::types::Hash256;
|
||||||
|
use super::super::utils::errors::ParameterError;
|
||||||
|
|
||||||
mod attestation_parent_hashes;
|
mod attestation_parent_hashes;
|
||||||
mod shuffling;
|
mod shuffling;
|
||||||
@ -6,12 +7,6 @@ mod shuffling;
|
|||||||
pub use self::attestation_parent_hashes::attestation_parent_hashes;
|
pub use self::attestation_parent_hashes::attestation_parent_hashes;
|
||||||
pub use self::shuffling::shuffle;
|
pub use self::shuffling::shuffle;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum TransitionError {
|
|
||||||
IntWrapping,
|
|
||||||
OutOfBounds,
|
|
||||||
InvalidInput(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Collection of custom errors
|
// Collection of custom errors
|
||||||
|
|
||||||
#[derive(Debug,PartialEq)]
|
#[derive(Debug,PartialEq)]
|
||||||
pub enum AttestationValidationError {
|
pub enum AttestationValidationError {
|
||||||
SlotTooHigh,
|
SlotTooHigh,
|
||||||
SlotTooLow(String),
|
SlotTooLow(String),
|
||||||
IncorrectBitField,
|
IncorrectBitField,
|
||||||
@ -9,4 +9,9 @@ pub enum AttestationValidationError {
|
|||||||
AggregateSignatureFail
|
AggregateSignatureFail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,PartialEq)]
|
||||||
|
pub enum ParameterError {
|
||||||
|
IntWrapping,
|
||||||
|
OutOfBounds,
|
||||||
|
InvalidInput(String),
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user