From 24a27891b878de5f18ff5656ac1c777b673b3725 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 21 Jan 2019 18:41:07 +1100 Subject: [PATCH] Run rustfmt on entire codebase Signed-off-by: Paul Hauner --- .../attestation_validation/src/lib.rs | 6 +- beacon_chain/genesis/src/lib.rs | 2 +- beacon_chain/types/src/test_utils/mod.rs | 10 +-- beacon_chain/types/src/validator_record.rs | 6 +- beacon_chain/utils/bls/src/lib.rs | 2 +- .../validator_induction/src/inductor.rs | 69 ++++++++++++------- beacon_chain/validator_induction/src/lib.rs | 4 +- beacon_node/db/src/disk_db.rs | 3 +- .../db/src/stores/beacon_state_store.rs | 4 +- validator_client/src/block_producer/mod.rs | 2 +- .../src/block_producer/service.rs | 4 +- .../src/block_producer/test_node.rs | 6 +- validator_client/src/duties/grpc.rs | 14 ++-- validator_client/src/main.rs | 8 ++- 14 files changed, 90 insertions(+), 50 deletions(-) diff --git a/beacon_chain/attestation_validation/src/lib.rs b/beacon_chain/attestation_validation/src/lib.rs index 254d6134e0..825371ed09 100644 --- a/beacon_chain/attestation_validation/src/lib.rs +++ b/beacon_chain/attestation_validation/src/lib.rs @@ -14,9 +14,9 @@ mod justified_slot; mod shard_block; mod signature; -pub use crate::enums::{Invalid, Outcome, Error}; pub use crate::block_inclusion::validate_attestation_for_block; -pub use crate::justified_slot::validate_attestation_justified_slot; +pub use crate::enums::{Error, Invalid, Outcome}; pub use crate::justified_block::validate_attestation_justified_block_hash; -pub use crate::signature::validate_attestation_signature; +pub use crate::justified_slot::validate_attestation_justified_slot; pub use crate::shard_block::validate_attestation_data_shard_block_hash; +pub use crate::signature::validate_attestation_signature; diff --git a/beacon_chain/genesis/src/lib.rs b/beacon_chain/genesis/src/lib.rs index e590fa8be8..6f45863aa4 100644 --- a/beacon_chain/genesis/src/lib.rs +++ b/beacon_chain/genesis/src/lib.rs @@ -3,8 +3,8 @@ extern crate types; extern crate validator_induction; extern crate validator_shuffling; -mod beacon_state; mod beacon_block; +mod beacon_state; pub use crate::beacon_block::genesis_beacon_block; pub use crate::beacon_state::{genesis_beacon_state, Error as GenesisError}; diff --git a/beacon_chain/types/src/test_utils/mod.rs b/beacon_chain/types/src/test_utils/mod.rs index f3e382e6ef..eb54f2a53f 100644 --- a/beacon_chain/types/src/test_utils/mod.rs +++ b/beacon_chain/types/src/test_utils/mod.rs @@ -6,12 +6,13 @@ pub mod address; pub mod aggregate_signature; pub mod bitfield; pub mod hash256; -pub mod signature; -pub mod secret_key; pub mod public_key; +pub mod secret_key; +pub mod signature; pub trait TestRandom -where T: RngCore +where + T: RngCore, { fn random_for_test(rng: &mut T) -> Self; } @@ -35,7 +36,8 @@ impl TestRandom for usize { } impl TestRandom for Vec -where U: TestRandom +where + U: TestRandom, { fn random_for_test(rng: &mut T) -> Self { vec![ diff --git a/beacon_chain/types/src/validator_record.rs b/beacon_chain/types/src/validator_record.rs index 5f74d28d25..3f4a432616 100644 --- a/beacon_chain/types/src/validator_record.rs +++ b/beacon_chain/types/src/validator_record.rs @@ -1,5 +1,5 @@ use super::bls::PublicKey; -use super::{Hash256}; +use super::Hash256; use crate::test_utils::TestRandom; use rand::RngCore; use ssz::{Decodable, DecodeError, Encodable, SszStream}; @@ -40,7 +40,7 @@ pub struct ValidatorRecord { pub exit_count: u64, pub custody_commitment: Hash256, pub latest_custody_reseed_slot: u64, - pub penultimate_custody_reseed_slot: u64 + pub penultimate_custody_reseed_slot: u64, } impl ValidatorRecord { @@ -132,7 +132,7 @@ impl Decodable for ValidatorRecord { exit_count, custody_commitment, latest_custody_reseed_slot, - penultimate_custody_reseed_slot + penultimate_custody_reseed_slot, }, i, )) diff --git a/beacon_chain/utils/bls/src/lib.rs b/beacon_chain/utils/bls/src/lib.rs index 9d27d870ba..d7a3ff15dc 100644 --- a/beacon_chain/utils/bls/src/lib.rs +++ b/beacon_chain/utils/bls/src/lib.rs @@ -19,8 +19,8 @@ pub use self::bls_aggregates::AggregatePublicKey; pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97; use hashing::canonical_hash; -use std::default::Default; use ssz::ssz_encode; +use std::default::Default; fn extend_if_needed(hash: &mut Vec) { // NOTE: bls_aggregates crate demands 48 bytes, this may be removed as we get closer to production diff --git a/beacon_chain/validator_induction/src/inductor.rs b/beacon_chain/validator_induction/src/inductor.rs index 720e38fa4e..f00c9ec55f 100644 --- a/beacon_chain/validator_induction/src/inductor.rs +++ b/beacon_chain/validator_induction/src/inductor.rs @@ -1,19 +1,19 @@ -use bls::{verify_proof_of_possession}; -use types::{BeaconState, Deposit, ValidatorRecord, ValidatorStatus}; +use bls::verify_proof_of_possession; use spec::ChainSpec; +use types::{BeaconState, Deposit, ValidatorRecord, ValidatorStatus}; #[derive(Debug, PartialEq, Clone)] pub enum ValidatorInductionError { InvalidShard, InvaidProofOfPossession, - InvalidWithdrawalCredentials + InvalidWithdrawalCredentials, } pub fn process_deposit( state: &mut BeaconState, deposit: &Deposit, - spec: &ChainSpec) --> Result { + spec: &ChainSpec, +) -> Result { let deposit_input = &deposit.deposit_data.deposit_input; let deposit_data = &deposit.deposit_data; @@ -22,18 +22,22 @@ pub fn process_deposit( return Err(ValidatorInductionError::InvaidProofOfPossession); } - let validator_index = state.validator_registry.iter() + let validator_index = state + .validator_registry + .iter() .position(|validator| validator.pubkey == deposit_input.pubkey); match validator_index { Some(i) => { - if state.validator_registry[i].withdrawal_credentials == deposit_input.withdrawal_credentials { + if state.validator_registry[i].withdrawal_credentials + == deposit_input.withdrawal_credentials + { state.validator_balances[i] += deposit_data.value; return Ok(i); } Err(ValidatorInductionError::InvalidWithdrawalCredentials) - }, + } None => { let validator = ValidatorRecord { pubkey: deposit_input.pubkey.clone(), @@ -45,7 +49,7 @@ pub fn process_deposit( exit_count: 0, custody_commitment: deposit_input.custody_commitment, latest_custody_reseed_slot: 0, - penultimate_custody_reseed_slot: 0 + penultimate_custody_reseed_slot: 0, }; match min_empty_validator_index(state, spec) { @@ -53,7 +57,7 @@ pub fn process_deposit( state.validator_registry[i] = validator; state.validator_balances[i] = deposit_data.value; Ok(i) - }, + } None => { state.validator_registry.push(validator); state.validator_balances.push(deposit_data.value); @@ -64,14 +68,13 @@ pub fn process_deposit( } } -fn min_empty_validator_index( - state: &BeaconState, - spec: &ChainSpec -) -> Option { +fn min_empty_validator_index(state: &BeaconState, spec: &ChainSpec) -> Option { for i in 0..state.validator_registry.len() { if state.validator_balances[i] == 0 && state.validator_registry[i].latest_status_change_slot - + spec.zero_balance_validator_ttl <= state.slot { + + spec.zero_balance_validator_ttl + <= state.slot + { return Some(i); } } @@ -107,7 +110,10 @@ mod tests { (dep.deposit_data.deposit_input.pubkey == val.pubkey) & (dep.deposit_data.deposit_input.withdrawal_credentials == val.withdrawal_credentials) & (dep.deposit_data.deposit_input.randao_commitment == val.randao_commitment) - & (verify_proof_of_possession(&dep.deposit_data.deposit_input.proof_of_possession, &val.pubkey)) + & (verify_proof_of_possession( + &dep.deposit_data.deposit_input.proof_of_possession, + &val.pubkey, + )) } #[test] @@ -120,7 +126,10 @@ mod tests { let result = process_deposit(&mut state, &deposit, &spec); assert_eq!(result.unwrap(), 0); - assert!(deposit_equals_record(&deposit, &state.validator_registry[0])); + assert!(deposit_equals_record( + &deposit, + &state.validator_registry[0] + )); assert_eq!(state.validator_registry.len(), 1); assert_eq!(state.validator_balances.len(), 1); } @@ -135,7 +144,10 @@ mod tests { let result = process_deposit(&mut state, &deposit, &spec); deposit.deposit_data.value = DEPOSIT_GWEI; assert_eq!(result.unwrap(), i); - assert!(deposit_equals_record(&deposit, &state.validator_registry[i])); + assert!(deposit_equals_record( + &deposit, + &state.validator_registry[i] + )); assert_eq!(state.validator_registry.len(), i + 1); assert_eq!(state.validator_balances.len(), i + 1); } @@ -151,7 +163,8 @@ mod tests { deposit.deposit_data.value = DEPOSIT_GWEI; validator.pubkey = deposit.deposit_data.deposit_input.pubkey.clone(); - validator.withdrawal_credentials = deposit.deposit_data.deposit_input.withdrawal_credentials; + validator.withdrawal_credentials = + deposit.deposit_data.deposit_input.withdrawal_credentials; validator.randao_commitment = deposit.deposit_data.deposit_input.randao_commitment; state.validator_registry.push(validator); @@ -160,7 +173,10 @@ mod tests { let result = process_deposit(&mut state, &deposit, &spec); assert_eq!(result.unwrap(), 0); - assert!(deposit_equals_record(&deposit, &state.validator_registry[0])); + assert!(deposit_equals_record( + &deposit, + &state.validator_registry[0] + )); assert_eq!(state.validator_balances[0], DEPOSIT_GWEI * 2); assert_eq!(state.validator_registry.len(), 1); assert_eq!(state.validator_balances.len(), 1); @@ -183,7 +199,10 @@ mod tests { let result = process_deposit(&mut state, &deposit, &spec); assert_eq!(result.unwrap(), 0); - assert!(deposit_equals_record(&deposit, &state.validator_registry[0])); + assert!(deposit_equals_record( + &deposit, + &state.validator_registry[0] + )); assert_eq!(state.validator_balances[0], DEPOSIT_GWEI); assert_eq!(state.validator_registry.len(), 1); assert_eq!(state.validator_balances.len(), 1); @@ -195,11 +214,15 @@ mod tests { let mut deposit = get_deposit(); let spec = ChainSpec::foundation(); deposit.deposit_data.value = DEPOSIT_GWEI; - deposit.deposit_data.deposit_input.proof_of_possession = create_proof_of_possession(&Keypair::random()); + deposit.deposit_data.deposit_input.proof_of_possession = + create_proof_of_possession(&Keypair::random()); let result = process_deposit(&mut state, &deposit, &spec); - assert_eq!(result, Err(ValidatorInductionError::InvaidProofOfPossession)); + assert_eq!( + result, + Err(ValidatorInductionError::InvaidProofOfPossession) + ); assert_eq!(state.validator_registry.len(), 0); assert_eq!(state.validator_balances.len(), 0); } diff --git a/beacon_chain/validator_induction/src/lib.rs b/beacon_chain/validator_induction/src/lib.rs index f6dec3cfae..7119d6c2eb 100644 --- a/beacon_chain/validator_induction/src/lib.rs +++ b/beacon_chain/validator_induction/src/lib.rs @@ -1,8 +1,8 @@ extern crate bls; extern crate hashing; -extern crate types; extern crate spec; +extern crate types; mod inductor; -pub use crate::inductor::{ValidatorInductionError, process_deposit}; +pub use crate::inductor::{process_deposit, ValidatorInductionError}; diff --git a/beacon_node/db/src/disk_db.rs b/beacon_node/db/src/disk_db.rs index b084f483f0..9d8a71bc45 100644 --- a/beacon_node/db/src/disk_db.rs +++ b/beacon_node/db/src/disk_db.rs @@ -44,7 +44,8 @@ impl DiskDB { let db = match columns { None => DB::open(&options, db_path), Some(columns) => DB::open_cf(&options, db_path, columns), - }.expect("Unable to open local database");; + } + .expect("Unable to open local database");; Self { db } } diff --git a/beacon_node/db/src/stores/beacon_state_store.rs b/beacon_node/db/src/stores/beacon_state_store.rs index 122b225094..a54e192495 100644 --- a/beacon_node/db/src/stores/beacon_state_store.rs +++ b/beacon_node/db/src/stores/beacon_state_store.rs @@ -42,10 +42,10 @@ mod tests { use super::super::super::MemoryDB; use super::*; - use std::sync::Arc; use ssz::ssz_encode; - use types::Hash256; + use std::sync::Arc; use types::test_utils::{SeedableRng, TestRandom, XorShiftRng}; + use types::Hash256; test_crud_for_store!(BeaconStateStore, DB_COLUMN); diff --git a/validator_client/src/block_producer/mod.rs b/validator_client/src/block_producer/mod.rs index db65ee7896..aa4c088f32 100644 --- a/validator_client/src/block_producer/mod.rs +++ b/validator_client/src/block_producer/mod.rs @@ -137,9 +137,9 @@ impl From for Error { mod tests { use super::test_node::TestBeaconNode; use super::*; + use crate::duties::EpochDuties; use slot_clock::TestingSlotClock; use types::test_utils::{SeedableRng, TestRandom, XorShiftRng}; - use crate::duties::EpochDuties; // TODO: implement more thorough testing. // diff --git a/validator_client/src/block_producer/service.rs b/validator_client/src/block_producer/service.rs index aef1e3c287..222e54d47f 100644 --- a/validator_client/src/block_producer/service.rs +++ b/validator_client/src/block_producer/service.rs @@ -16,7 +16,9 @@ impl BlockProducerService { Err(error) => { error!(self.log, "Block producer poll error"; "error" => format!("{:?}", error)) } - Ok(BlockProducerPollOutcome::BlockProduced(slot)) => info!(self.log, "Produced block"; "slot" => slot), + Ok(BlockProducerPollOutcome::BlockProduced(slot)) => { + info!(self.log, "Produced block"; "slot" => slot) + } Ok(BlockProducerPollOutcome::SlashableBlockNotProduced(slot)) => { warn!(self.log, "Slashable block was not signed"; "slot" => slot) } diff --git a/validator_client/src/block_producer/test_node.rs b/validator_client/src/block_producer/test_node.rs index fdb179b5c1..36d47e3c3f 100644 --- a/validator_client/src/block_producer/test_node.rs +++ b/validator_client/src/block_producer/test_node.rs @@ -1,6 +1,6 @@ use super::traits::{BeaconNode, BeaconNodeError}; -use types::BeaconBlock; use std::sync::RwLock; +use types::BeaconBlock; type ProduceResult = Result, BeaconNodeError>; type PublishResult = Result; @@ -28,7 +28,7 @@ impl BeaconNode for TestBeaconNode { *self.produce_input.write().unwrap() = Some(slot); match *self.produce_result.read().unwrap() { Some(ref r) => r.clone(), - None => panic!("TestBeaconNode: produce_result == None") + None => panic!("TestBeaconNode: produce_result == None"), } } @@ -36,7 +36,7 @@ impl BeaconNode for TestBeaconNode { *self.publish_input.write().unwrap() = Some(block); match *self.publish_result.read().unwrap() { Some(ref r) => r.clone(), - None => panic!("TestBeaconNode: publish_result == None") + None => panic!("TestBeaconNode: publish_result == None"), } } } diff --git a/validator_client/src/duties/grpc.rs b/validator_client/src/duties/grpc.rs index 4ea9c6d41e..c5d817dd7b 100644 --- a/validator_client/src/duties/grpc.rs +++ b/validator_client/src/duties/grpc.rs @@ -1,12 +1,16 @@ -use super::EpochDuties; use super::traits::{BeaconNode, BeaconNodeError}; +use super::EpochDuties; use protos::services::ValidatorAssignmentRequest; use protos::services_grpc::BeaconBlockServiceClient; use ssz::ssz_encode; -use types::{PublicKey}; +use types::PublicKey; impl BeaconNode for BeaconBlockServiceClient { - fn request_shuffling(&self, epoch: u64, public_key: &PublicKey) -> Result, BeaconNodeError> { + fn request_shuffling( + &self, + epoch: u64, + public_key: &PublicKey, + ) -> Result, BeaconNodeError> { let mut req = ValidatorAssignmentRequest::new(); req.set_epoch(epoch); req.set_public_key(ssz_encode(public_key).to_vec()); @@ -24,7 +28,9 @@ impl BeaconNode for BeaconBlockServiceClient { None }; - let duties = EpochDuties { block_production_slot }; + let duties = EpochDuties { + block_production_slot, + }; Ok(Some(duties)) } else { diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index 187b40f04b..63d2137b2b 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -104,7 +104,13 @@ fn main() { let beacon_node = client.clone(); let pubkey = keypair.pk.clone(); thread::spawn(move || { - let manager = DutiesManager { duties_map, pubkey, spec, slot_clock, beacon_node }; + let manager = DutiesManager { + duties_map, + pubkey, + spec, + slot_clock, + beacon_node, + }; let mut duties_manager_service = DutiesManagerService { manager, poll_interval_millis,