diff --git a/lighthouse/db/memory_db.rs b/lighthouse/db/memory_db.rs index 2f8ffe30da..c912b7c683 100644 --- a/lighthouse/db/memory_db.rs +++ b/lighthouse/db/memory_db.rs @@ -28,7 +28,7 @@ impl MemoryDB { pub fn open() -> Self { let db: DBHashMap = HashMap::new(); let mut known_columns: ColumnHashSet = HashSet::new(); - for col in COLUMNS.iter() { + for col in &COLUMNS { known_columns.insert(col.to_string()); } Self { diff --git a/lighthouse/db/stores/pow_chain_store.rs b/lighthouse/db/stores/pow_chain_store.rs index d428054764..f1f050a390 100644 --- a/lighthouse/db/stores/pow_chain_store.rs +++ b/lighthouse/db/stores/pow_chain_store.rs @@ -21,7 +21,7 @@ impl PoWChainStore { pub fn put_block_hash(&self, hash: &[u8]) -> Result<(), DBError> { - self.db.put(DB_COLUMN, hash, &vec![0]) + self.db.put(DB_COLUMN, hash, &[0]) } pub fn block_hash_exists(&self, hash: &[u8]) diff --git a/lighthouse/db/stores/validator_store.rs b/lighthouse/db/stores/validator_store.rs index e3c604b3ac..173eeee96d 100644 --- a/lighthouse/db/stores/validator_store.rs +++ b/lighthouse/db/stores/validator_store.rs @@ -42,7 +42,7 @@ impl ValidatorStore { } } - fn prefix_bytes(&self, key_prefix: KeyPrefixes) + fn prefix_bytes(&self, key_prefix: &KeyPrefixes) -> Vec { match key_prefix { @@ -50,7 +50,7 @@ impl ValidatorStore { } } - fn get_db_key_for_index(&self, key_prefix: KeyPrefixes, index: usize) + fn get_db_key_for_index(&self, key_prefix: &KeyPrefixes, index: usize) -> Vec { let mut buf = BytesMut::with_capacity(6 + 8); @@ -62,16 +62,16 @@ impl ValidatorStore { pub fn put_public_key_by_index(&self, index: usize, public_key: &PublicKey) -> Result<(), ValidatorStoreError> { - let key = self.get_db_key_for_index(KeyPrefixes::PublicKey, index); + let key = self.get_db_key_for_index(&KeyPrefixes::PublicKey, index); let val = public_key.as_bytes(); self.db.put(DB_COLUMN, &key[..], &val[..]) - .map_err(|e| ValidatorStoreError::from(e)) + .map_err(ValidatorStoreError::from) } pub fn get_public_key_by_index(&self, index: usize) -> Result, ValidatorStoreError> { - let key = self.get_db_key_for_index(KeyPrefixes::PublicKey, index); + let key = self.get_db_key_for_index(&KeyPrefixes::PublicKey, index); let val = self.db.get(DB_COLUMN, &key[..])?; match val { None => Ok(None), @@ -129,7 +129,7 @@ mod tests { let db = Arc::new(MemoryDB::open()); let store = ValidatorStore::new(db.clone()); - let key = store.get_db_key_for_index(KeyPrefixes::PublicKey, 42); + let key = store.get_db_key_for_index(&KeyPrefixes::PublicKey, 42); db.put(DB_COLUMN, &key[..], "cats".as_bytes()).unwrap(); assert_eq!(store.get_public_key_by_index(42), diff --git a/lighthouse/state/attestation_record/mod.rs b/lighthouse/state/attestation_record/mod.rs index d96a451fdd..5751bcd245 100644 --- a/lighthouse/state/attestation_record/mod.rs +++ b/lighthouse/state/attestation_record/mod.rs @@ -3,10 +3,10 @@ use super::ssz; use super::utils; -mod attestation_record; +mod structs; mod ssz_splitter; -pub use self::attestation_record::{ +pub use self::structs::{ AttestationRecord, MIN_SSZ_ATTESTION_RECORD_LENGTH, }; diff --git a/lighthouse/state/attestation_record/ssz_splitter.rs b/lighthouse/state/attestation_record/ssz_splitter.rs index e1c2054586..e9e1b5ff81 100644 --- a/lighthouse/state/attestation_record/ssz_splitter.rs +++ b/lighthouse/state/attestation_record/ssz_splitter.rs @@ -24,8 +24,8 @@ pub fn split_all_attestations<'a>(full_ssz: &'a [u8], index: usize) /// Given some ssz slice, find the bounds of one serialized AttestationRecord /// and return a slice pointing to that. -pub fn split_one_attestation<'a>(full_ssz: &'a [u8], index: usize) - -> Result<(&'a [u8], usize), AttestationSplitError> +pub fn split_one_attestation(full_ssz: &[u8], index: usize) + -> Result<(&[u8], usize), AttestationSplitError> { if full_ssz.len() < MIN_LENGTH { return Err(AttestationSplitError::TooShort); diff --git a/lighthouse/state/attestation_record/attestation_record.rs b/lighthouse/state/attestation_record/structs.rs similarity index 100% rename from lighthouse/state/attestation_record/attestation_record.rs rename to lighthouse/state/attestation_record/structs.rs diff --git a/lighthouse/state/block/mod.rs b/lighthouse/state/block/mod.rs index 20467eca7f..04b70e6dd5 100644 --- a/lighthouse/state/block/mod.rs +++ b/lighthouse/state/block/mod.rs @@ -4,8 +4,8 @@ use super::ssz; use super::utils; use super::attestation_record; -mod block; +mod structs; mod ssz_block; -pub use self::block::Block; +pub use self::structs::Block; pub use self::ssz_block::SszBlock; diff --git a/lighthouse/state/block/ssz_block.rs b/lighthouse/state/block/ssz_block.rs index a90ff13510..1d4fb1c72a 100644 --- a/lighthouse/state/block/ssz_block.rs +++ b/lighthouse/state/block/ssz_block.rs @@ -3,7 +3,7 @@ use super::ssz::decode::{ Decodable, }; use super::utils::hash::canonical_hash; -use super::block::{ +use super::structs::{ MIN_SSZ_BLOCK_LENGTH, MAX_SSZ_BLOCK_LENGTH, }; @@ -146,7 +146,7 @@ impl<'a> SszBlock<'a> { #[cfg(test)] mod tests { use super::*; - use super::super::block::Block; + use super::super::structs::Block; use super::super::attestation_record::AttestationRecord; use super::super::ssz::SszStream; use super::super::utils::types::Hash256; diff --git a/lighthouse/state/block/block.rs b/lighthouse/state/block/structs.rs similarity index 100% rename from lighthouse/state/block/block.rs rename to lighthouse/state/block/structs.rs diff --git a/lighthouse/state/chain_config.rs b/lighthouse/state/chain_config.rs index 7dde3751cb..750081aad7 100644 --- a/lighthouse/state/chain_config.rs +++ b/lighthouse/state/chain_config.rs @@ -8,7 +8,7 @@ pub struct ChainConfig { /* * Presently this is just some arbitrary time in Sept 2018. */ -const GENESIS_TIME: u64 = 1537488655; +const GENESIS_TIME: u64 = 1_537_488_655; impl ChainConfig { pub fn standard() -> Self { diff --git a/lighthouse/state/common/delegation/block_hash.rs b/lighthouse/state/common/delegation/block_hash.rs index 092709a217..3d0939d29c 100644 --- a/lighthouse/state/common/delegation/block_hash.rs +++ b/lighthouse/state/common/delegation/block_hash.rs @@ -6,10 +6,10 @@ use super::utils::types::Hash256; */ pub fn get_block_hash( - active_state_recent_block_hashes: &Vec, - current_block_slot: &u64, - slot: &u64, - cycle_length: &u64, // convert from standard u8 + active_state_recent_block_hashes: &[Hash256], + current_block_slot: u64, + slot: u64, + cycle_length: u64, // convert from standard u8 ) -> Result { // active_state must have at 2*cycle_length hashes assert_error!( @@ -19,16 +19,16 @@ pub fn get_block_hash( )) ); - let state_start_slot = (*current_block_slot) + let state_start_slot = (current_block_slot) .checked_sub(cycle_length * 2) .unwrap_or(0); assert_error!( - (state_start_slot <= *slot) && (*slot < *current_block_slot), + (state_start_slot <= slot) && (slot < current_block_slot), ParameterError::InvalidInput(String::from("incorrect slot number")) ); - let index = 2 * cycle_length + (*slot) - *current_block_slot; // should always be positive + let index = 2 * cycle_length + slot - current_block_slot; // should always be positive Ok(active_state_recent_block_hashes[index as usize]) } @@ -47,13 +47,16 @@ mod tests { block_hashes.push(Hash256::random()); } - let result = get_block_hash(&block_hashes, &block_slot, &slot, &cycle_length).unwrap(); + let result = get_block_hash( + &block_hashes, + block_slot, + slot, + cycle_length) + .unwrap(); assert_eq!( result, block_hashes[(2 * cycle_length + slot - block_slot) as usize] ); - - println!("{:?}", result); } }