From fa705229aaa214c5ee52e76dba8aab665d524010 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 16 Oct 2018 15:24:50 +1100 Subject: [PATCH] Fix clippy lints --- beacon_chain/types/src/special_record.rs | 2 -- .../validation/src/block_validation.rs | 26 +++++++++++++------ .../db/src/stores/beacon_block_store.rs | 5 +++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/beacon_chain/types/src/special_record.rs b/beacon_chain/types/src/special_record.rs index 8a8ada0bd..9189728df 100644 --- a/beacon_chain/types/src/special_record.rs +++ b/beacon_chain/types/src/special_record.rs @@ -80,8 +80,6 @@ impl Decodable for SpecialRecord { } - - #[cfg(test)] mod tests { use super::*; diff --git a/beacon_chain/validation/src/block_validation.rs b/beacon_chain/validation/src/block_validation.rs index 43c7138a6..8c2c28b1a 100644 --- a/beacon_chain/validation/src/block_validation.rs +++ b/beacon_chain/validation/src/block_validation.rs @@ -186,7 +186,7 @@ impl BeaconBlockValidationContext * 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. */ - if first_attestation.oblique_parent_hashes.len() > 0 { + if !first_attestation.oblique_parent_hashes.is_empty() { return Err(SszBeaconBlockValidationError::ProposerAttestationHasObliqueHashes); } @@ -274,10 +274,12 @@ impl BeaconBlockValidationContext .filter_map(|attestation_ssz| { /* * 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() { - return None; + match failure.read() { + Ok(ref option) if option.is_none() => (), + _ => return None } /* * If there has not been a failure yet, attempt to serialize and validate the @@ -288,8 +290,12 @@ impl BeaconBlockValidationContext * Deserialization failed, therefore the block is invalid. */ 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 } /* @@ -301,8 +307,12 @@ impl BeaconBlockValidationContext * Attestation validation failed with some error. */ 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 } /* diff --git a/lighthouse/db/src/stores/beacon_block_store.rs b/lighthouse/db/src/stores/beacon_block_store.rs index 80c29c5a7..2caf225a0 100644 --- a/lighthouse/db/src/stores/beacon_block_store.rs +++ b/lighthouse/db/src/stores/beacon_block_store.rs @@ -10,6 +10,9 @@ use super::{ }; use super::BLOCKS_DB_COLUMN as DB_COLUMN; +type BeaconBlockHash = Vec; +type BeaconBlockSsz = Vec; + #[derive(Clone, Debug, PartialEq)] pub enum BeaconBlockAtSlotError { UnknownBeaconBlock, @@ -65,7 +68,7 @@ impl BeaconBlockStore { /// /// 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) - -> Result, Vec)>, BeaconBlockAtSlotError> + -> Result, BeaconBlockAtSlotError> { match self.get_serialized_block(head_hash)? { None => Err(BeaconBlockAtSlotError::UnknownBeaconBlock),