From 87acaac8a03b2735b20e64887c7d5e0a5627f55a Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Thu, 28 Mar 2019 21:01:47 +1100 Subject: [PATCH] Ran cargo fmt. --- .../test_harness/src/validator_harness/mod.rs | 8 ++-- eth2/attester/src/lib.rs | 37 +++++++++++-------- .../src/test_utils/simulated_beacon_node.rs | 2 +- eth2/attester/src/traits.rs | 2 +- eth2/block_proposer/src/lib.rs | 18 ++------- .../attestation_grpc_client.rs | 2 +- validator_client/src/duties/epoch_duties.rs | 2 +- validator_client/src/duties/mod.rs | 2 +- validator_client/src/service.rs | 16 +++----- 9 files changed, 38 insertions(+), 51 deletions(-) diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs index 074ede06a..43ad03ea7 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs @@ -2,13 +2,13 @@ mod direct_beacon_node; mod direct_duties; mod local_signer; +use crate::direct_beacon_node::DirectBeaconNode; use attester::PollOutcome as AttestationPollOutcome; use attester::{Attester, Error as AttestationPollError}; use beacon_chain::BeaconChain; use block_proposer::PollOutcome as BlockPollOutcome; use block_proposer::{BlockProducer, Error as BlockPollError}; use db::MemoryDB; -use crate::direct_beacon_node::DirectBeaconNode; use fork_choice::BitwiseLMDGhost; use local_signer::LocalSigner; use slot_clock::TestingSlotClock; @@ -32,10 +32,8 @@ type TestingBlockProducer = BlockProducer< LocalSigner, >; -type TestingAttester = Attester< - DirectBeaconNode>, - LocalSigner, ->; +type TestingAttester = + Attester>, LocalSigner>; /// A `BlockProducer` and `Attester` which sign using a common keypair. /// diff --git a/eth2/attester/src/lib.rs b/eth2/attester/src/lib.rs index 53d81e897..b5cdf5920 100644 --- a/eth2/attester/src/lib.rs +++ b/eth2/attester/src/lib.rs @@ -3,8 +3,10 @@ mod traits; use ssz::TreeHash; use std::sync::Arc; -use types::{AttestationData, AttestationDataAndCustodyBit, Attestation, Signature, - AggregateSignature, Slot, AttestationDuty, Bitfield}; +use types::{ + AggregateSignature, Attestation, AttestationData, AttestationDataAndCustodyBit, + AttestationDuty, Bitfield, Signature, Slot, +}; pub use self::traits::{ BeaconNode, BeaconNodeError, DutiesReader, DutiesReaderError, PublishOutcome, Signer, @@ -59,20 +61,28 @@ impl Attester { } impl Attester { - - fn produce_attestation(&mut self, attestation_duty: AttestationDuty) -> Result { - let attestation_data = match self.beacon_node.produce_attestation_data( - attestation_duty.slot, - attestation_duty.shard - )? { + fn produce_attestation( + &mut self, + attestation_duty: AttestationDuty, + ) -> Result { + let attestation_data = match self + .beacon_node + .produce_attestation_data(attestation_duty.slot, attestation_duty.shard)? + { Some(attestation_data) => attestation_data, - None => return Ok(PollOutcome::BeaconNodeUnableToProduceAttestation(attestation_duty.slot)), + None => { + return Ok(PollOutcome::BeaconNodeUnableToProduceAttestation( + attestation_duty.slot, + )) + } }; dbg!(&attestation_data); if !self.safe_to_produce(&attestation_data) { - return Ok(PollOutcome::SlashableAttestationNotProduced(attestation_duty.slot)); + return Ok(PollOutcome::SlashableAttestationNotProduced( + attestation_duty.slot, + )); } let signature = match self.sign_attestation_data(&attestation_data) { @@ -82,7 +92,6 @@ impl Attester { let mut agg_sig = AggregateSignature::new(); agg_sig.add(&signature); - let attestation = Attestation { aggregation_bitfield: Bitfield::new(), data: attestation_data, @@ -172,10 +181,7 @@ mod tests { let attest_epoch = attest_slot / spec.slots_per_epoch; let attest_shard = 12; - let mut attester = Attester::new( - beacon_node.clone(), - signer.clone(), - ); + let mut attester = Attester::new(beacon_node.clone(), signer.clone()); // Configure responses from the BeaconNode. beacon_node.set_next_produce_result(Ok(Some(AttestationData::random_for_test(&mut rng)))); @@ -220,6 +226,5 @@ mod tests { Ok(PollOutcome::ProducerDutiesUnknown(slot)) ); */ - } } diff --git a/eth2/attester/src/test_utils/simulated_beacon_node.rs b/eth2/attester/src/test_utils/simulated_beacon_node.rs index 8e6c7c31d..eed6a38b9 100644 --- a/eth2/attester/src/test_utils/simulated_beacon_node.rs +++ b/eth2/attester/src/test_utils/simulated_beacon_node.rs @@ -1,6 +1,6 @@ use crate::traits::{BeaconNode, BeaconNodeError, PublishOutcome}; use std::sync::RwLock; -use types::{AttestationData, Attestation, Slot}; +use types::{Attestation, AttestationData, Slot}; type ProduceResult = Result, BeaconNodeError>; type PublishResult = Result; diff --git a/eth2/attester/src/traits.rs b/eth2/attester/src/traits.rs index 1c6d38578..94d138ae0 100644 --- a/eth2/attester/src/traits.rs +++ b/eth2/attester/src/traits.rs @@ -1,4 +1,4 @@ -use types::{AttestationData, Attestation, Signature, Slot}; +use types::{Attestation, AttestationData, Signature, Slot}; #[derive(Debug, PartialEq, Clone)] pub enum BeaconNodeError { diff --git a/eth2/block_proposer/src/lib.rs b/eth2/block_proposer/src/lib.rs index 1d2a4af71..646391c38 100644 --- a/eth2/block_proposer/src/lib.rs +++ b/eth2/block_proposer/src/lib.rs @@ -4,7 +4,7 @@ mod traits; use slot_clock::SlotClock; use ssz::{SignedRoot, TreeHash}; use std::sync::Arc; -use types::{BeaconBlock, ChainSpec, Domain, Slot, Fork}; +use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot}; pub use self::traits::{ BeaconNode, BeaconNodeError, DutiesReader, DutiesReaderError, PublishOutcome, Signer, @@ -57,11 +57,7 @@ pub struct BlockProducer { impl BlockProducer { /// Returns a new instance where `last_processed_slot == 0`. - pub fn new( - spec: Arc, - beacon_node: Arc, - signer: Arc, - ) -> Self { + pub fn new(spec: Arc, beacon_node: Arc, signer: Arc) -> Self { Self { last_processed_slot: None, spec, @@ -72,7 +68,6 @@ impl BlockProducer { } impl BlockProducer { - /* No longer needed because we don't poll any more /// "Poll" to see if the validator is required to take any action. /// @@ -129,7 +124,6 @@ impl BlockProducer { /// The slash-protection code is not yet implemented. There is zero protection against /// slashing. fn produce_block(&mut self, slot: Slot, fork: Fork) -> Result { - let randao_reveal = { // TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`. let message = slot.epoch(self.spec.slots_per_epoch).hash_tree_root(); @@ -238,12 +232,8 @@ mod tests { let beacon_node = Arc::new(SimulatedBeaconNode::default()); let signer = Arc::new(LocalSigner::new(Keypair::random())); - - let mut block_proposer = BlockProducer::new( - spec.clone(), - beacon_node.clone(), - signer.clone(), - ); + let mut block_proposer = + BlockProducer::new(spec.clone(), beacon_node.clone(), signer.clone()); // Configure responses from the BeaconNode. beacon_node.set_next_produce_result(Ok(Some(BeaconBlock::random_for_test(&mut rng)))); diff --git a/validator_client/src/attester_service/attestation_grpc_client.rs b/validator_client/src/attester_service/attestation_grpc_client.rs index 97ec05899..05173d824 100644 --- a/validator_client/src/attester_service/attestation_grpc_client.rs +++ b/validator_client/src/attester_service/attestation_grpc_client.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use attester::{BeaconNode, BeaconNodeError, PublishOutcome}; use protos::services::ProduceAttestationDataRequest; -use types::{AttestationData, Attestation, Slot}; +use types::{Attestation, AttestationData, Slot}; pub struct AttestationGrpcClient { client: Arc, diff --git a/validator_client/src/duties/epoch_duties.rs b/validator_client/src/duties/epoch_duties.rs index 984dc6e00..47c9d96c4 100644 --- a/validator_client/src/duties/epoch_duties.rs +++ b/validator_client/src/duties/epoch_duties.rs @@ -44,7 +44,7 @@ impl EpochDuty { slot, shard: self.attestation_shard, committee_index: self.committee_index as usize, - validator_index: self.validator_index as usize + validator_index: self.validator_index as usize, }); } diff --git a/validator_client/src/duties/mod.rs b/validator_client/src/duties/mod.rs index 0b86e3ce9..de08f6ce7 100644 --- a/validator_client/src/duties/mod.rs +++ b/validator_client/src/duties/mod.rs @@ -102,7 +102,7 @@ impl DutiesManager { Ok(Some(work_type)) => current_work.push((validator_signer.clone(), work_type)), Ok(None) => {} // No work for this validator //TODO: This should really log an error, as we shouldn't end up with an err here. - Err(_) => {} // Unknown epoch or validator, no work + Err(_) => {} // Unknown epoch or validator, no work } } if current_work.is_empty() { diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index 86f310a06..36da36a1f 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -20,6 +20,7 @@ use slog::{debug, error, info, warn}; use slot_clock::{SlotClock, SystemTimeSlotClock}; use std::sync::Arc; use std::sync::RwLock; +use std::thread; use std::time::{Duration, Instant, SystemTime}; use tokio::prelude::*; use tokio::runtime::Builder; @@ -27,7 +28,6 @@ use tokio::timer::Interval; use tokio_timer::clock::Clock; use types::test_utils::generate_deterministic_keypairs; use types::{Epoch, Fork, Slot}; -use std::thread; //TODO: This service should be simplified in the future. Can be made more steamlined. @@ -268,17 +268,11 @@ impl Service { // available AttestationDuty info let attestation_duty = work_type.attestation_duty.expect("Cannot be None"); - let attester_grpc_client = - Arc::new( - AttestationGrpcClient::new( - service.attester_client.clone() - ) - ); + let attester_grpc_client = Arc::new(AttestationGrpcClient::new( + service.attester_client.clone(), + )); let signer = Arc::new(AttesterLocalSigner::new(keypair.clone())); - let attester = - Attester::new( - attester_grpc_client, - signer); + let attester = Attester::new(attester_grpc_client, signer); let mut attester_service = AttesterService { attester, poll_interval_millis: POLL_INTERVAL_MILLIS,