Fix clippy lints

This commit is contained in:
Paul Hauner 2018-10-16 15:24:50 +11:00
parent c3d88a7e80
commit fa705229aa
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
3 changed files with 22 additions and 11 deletions

View File

@ -80,8 +80,6 @@ impl Decodable for SpecialRecord {
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -186,7 +186,7 @@ impl<T> BeaconBlockValidationContext<T>
* The presence of oblique hashes in the first attestation would indicate that the proposer * The presence of oblique hashes in the first attestation would indicate that the proposer
* of the previous block is attesting to some other block than the one they produced. * of the previous block is attesting to some other block than the one they produced.
*/ */
if first_attestation.oblique_parent_hashes.len() > 0 { if !first_attestation.oblique_parent_hashes.is_empty() {
return Err(SszBeaconBlockValidationError::ProposerAttestationHasObliqueHashes); return Err(SszBeaconBlockValidationError::ProposerAttestationHasObliqueHashes);
} }
@ -274,10 +274,12 @@ impl<T> BeaconBlockValidationContext<T>
.filter_map(|attestation_ssz| { .filter_map(|attestation_ssz| {
/* /*
* If some thread has set the `failure` variable to `Some(error)` the abandon * If some thread has set the `failure` variable to `Some(error)` the abandon
* attestation serialization and validation. * attestation serialization and validation. Also, fail early if the lock has been
* poisoned.
*/ */
if let Some(_) = *failure.read().unwrap() { match failure.read() {
return None; Ok(ref option) if option.is_none() => (),
_ => return None
} }
/* /*
* If there has not been a failure yet, attempt to serialize and validate the * If there has not been a failure yet, attempt to serialize and validate the
@ -288,8 +290,12 @@ impl<T> BeaconBlockValidationContext<T>
* Deserialization failed, therefore the block is invalid. * Deserialization failed, therefore the block is invalid.
*/ */
Err(e) => { Err(e) => {
let mut failure = failure.write().unwrap(); /*
*failure = Some(SszBeaconBlockValidationError::from(e)); * If the failure lock isn't poisoned, set it to some error.
*/
if let Ok(mut f) = failure.write() {
*f = Some(SszBeaconBlockValidationError::from(e));
}
None None
} }
/* /*
@ -301,8 +307,12 @@ impl<T> BeaconBlockValidationContext<T>
* Attestation validation failed with some error. * Attestation validation failed with some error.
*/ */
Err(e) => { Err(e) => {
let mut failure = failure.write().unwrap(); /*
*failure = Some(SszBeaconBlockValidationError::from(e)); * If the failure lock isn't poisoned, set it to some error.
*/
if let Ok(mut f) = failure.write() {
*f = Some(SszBeaconBlockValidationError::from(e));
}
None None
} }
/* /*

View File

@ -10,6 +10,9 @@ use super::{
}; };
use super::BLOCKS_DB_COLUMN as DB_COLUMN; use super::BLOCKS_DB_COLUMN as DB_COLUMN;
type BeaconBlockHash = Vec<u8>;
type BeaconBlockSsz = Vec<u8>;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum BeaconBlockAtSlotError { pub enum BeaconBlockAtSlotError {
UnknownBeaconBlock, UnknownBeaconBlock,
@ -65,7 +68,7 @@ impl<T: ClientDB> BeaconBlockStore<T> {
/// ///
/// If a block is found, a tuple of (block_hash, serialized_block) is returned. /// If a block is found, a tuple of (block_hash, serialized_block) is returned.
pub fn block_at_slot(&self, head_hash: &[u8], slot: u64) pub fn block_at_slot(&self, head_hash: &[u8], slot: u64)
-> Result<Option<(Vec<u8>, Vec<u8>)>, BeaconBlockAtSlotError> -> Result<Option<(BeaconBlockHash, BeaconBlockSsz)>, BeaconBlockAtSlotError>
{ {
match self.get_serialized_block(head_hash)? { match self.get_serialized_block(head_hash)? {
None => Err(BeaconBlockAtSlotError::UnknownBeaconBlock), None => Err(BeaconBlockAtSlotError::UnknownBeaconBlock),