From 9a6ecc46657305f4f07e1974e896918244b2a9e7 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sat, 30 Mar 2019 19:58:19 +1100 Subject: [PATCH] Add clippy suggestions --- .../src/attestation_producer/mod.rs | 13 ++++------ validator_client/src/block_producer/mod.rs | 25 ++++++++----------- validator_client/src/duties/grpc.rs | 5 ++-- validator_client/src/duties/mod.rs | 2 +- validator_client/src/service.rs | 9 +++---- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/validator_client/src/attestation_producer/mod.rs b/validator_client/src/attestation_producer/mod.rs index db9028c403..0fbc7bcbaa 100644 --- a/validator_client/src/attestation_producer/mod.rs +++ b/validator_client/src/attestation_producer/mod.rs @@ -2,7 +2,7 @@ mod beacon_node_attestation; mod grpc; use std::sync::Arc; -use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot}; +use types::{ChainSpec, Domain, Fork}; //TODO: Move these higher up in the crate use super::block_producer::{BeaconNodeError, PublishOutcome, ValidatorEvent}; use crate::signer::Signer; @@ -50,19 +50,16 @@ impl<'a, B: BeaconNodeAttestation, S: Signer> AttestationProducer<'a, B, S> { } Err(e) => error!(log, "Attestation production error"; "Error" => format!("{:?}", e)), Ok(ValidatorEvent::SignerRejection(_slot)) => { - error!(log, "Attestation production error"; "Error" => format!("Signer could not sign the attestation")) + error!(log, "Attestation production error"; "Error" => "Signer could not sign the attestation".to_string()) } Ok(ValidatorEvent::SlashableAttestationNotProduced(_slot)) => { - error!(log, "Attestation production error"; "Error" => format!("Rejected the attestation as it could have been slashed")) - } - Ok(ValidatorEvent::BeaconNodeUnableToProduceAttestation(_slot)) => { - error!(log, "Attestation production error"; "Error" => format!("Beacon node was unable to produce an attestation")) + error!(log, "Attestation production error"; "Error" => "Rejected the attestation as it could have been slashed".to_string()) } Ok(ValidatorEvent::PublishAttestationFailed) => { - error!(log, "Attestation production error"; "Error" => format!("Beacon node was unable to publish an attestation")) + error!(log, "Attestation production error"; "Error" => "Beacon node was unable to publish an attestation".to_string()) } Ok(ValidatorEvent::InvalidAttestation) => { - error!(log, "Attestation production error"; "Error" => format!("The signed attestation was invalid")) + error!(log, "Attestation production error"; "Error" => "The signed attestation was invalid".to_string()) } Ok(v) => { warn!(log, "Unknown result for attestation production"; "Error" => format!("{:?}",v)) diff --git a/validator_client/src/block_producer/mod.rs b/validator_client/src/block_producer/mod.rs index dc7f6c3eed..8b4f5abda0 100644 --- a/validator_client/src/block_producer/mod.rs +++ b/validator_client/src/block_producer/mod.rs @@ -27,8 +27,6 @@ pub enum ValidatorEvent { SlashableAttestationNotProduced(Slot), /// The Beacon Node was unable to produce a block at that slot. BeaconNodeUnableToProduceBlock(Slot), - /// The Beacon Node was unable to produce an attestation at that slot. - BeaconNodeUnableToProduceAttestation(Slot), /// The signer failed to sign the message. SignerRejection(Slot), /// Publishing an attestation failed. @@ -61,13 +59,13 @@ impl<'a, B: BeaconNodeBlock, S: Signer> BlockProducer<'a, B, S> { } Err(e) => error!(log, "Block production error"; "Error" => format!("{:?}", e)), Ok(ValidatorEvent::SignerRejection(_slot)) => { - error!(log, "Block production error"; "Error" => format!("Signer Could not sign the block")) + error!(log, "Block production error"; "Error" => "Signer Could not sign the block".to_string()) } Ok(ValidatorEvent::SlashableBlockNotProduced(_slot)) => { - error!(log, "Block production error"; "Error" => format!("Rejected the block as it could have been slashed")) + error!(log, "Block production error"; "Error" => "Rejected the block as it could have been slashed".to_string()) } Ok(ValidatorEvent::BeaconNodeUnableToProduceBlock(_slot)) => { - error!(log, "Block production error"; "Error" => format!("Beacon node was unable to produce a block")) + error!(log, "Block production error"; "Error" => "Beacon node was unable to produce a block".to_string()) } Ok(v) => { warn!(log, "Unknown result for block production"; "Error" => format!("{:?}",v)) @@ -88,16 +86,13 @@ impl<'a, B: BeaconNodeBlock, S: Signer> BlockProducer<'a, B, S> { pub fn produce_block(&mut self) -> Result { let epoch = self.slot.epoch(self.spec.slots_per_epoch); - let randao_reveal = { - let message = epoch.hash_tree_root(); - let randao_reveal = match self.signer.sign_message( - &message, - self.spec.get_domain(epoch, Domain::Randao, &self.fork), - ) { - None => return Ok(ValidatorEvent::SignerRejection(self.slot)), - Some(signature) => signature, - }; - randao_reveal + let message = epoch.hash_tree_root(); + let randao_reveal = match self.signer.sign_message( + &message, + self.spec.get_domain(epoch, Domain::Randao, &self.fork), + ) { + None => return Ok(ValidatorEvent::SignerRejection(self.slot)), + Some(signature) => signature, }; if let Some(block) = self diff --git a/validator_client/src/duties/grpc.rs b/validator_client/src/duties/grpc.rs index ab87b602e0..954ee194e7 100644 --- a/validator_client/src/duties/grpc.rs +++ b/validator_client/src/duties/grpc.rs @@ -1,11 +1,12 @@ use super::beacon_node_duties::{BeaconNodeDuties, BeaconNodeDutiesError}; use super::epoch_duties::{EpochDuties, EpochDuty}; -use grpcio::CallOption; +// to use if we manually specify a timeout +//use grpcio::CallOption; use protos::services::{GetDutiesRequest, Validators}; use protos::services_grpc::ValidatorServiceClient; use ssz::ssz_encode; use std::collections::HashMap; -use std::time::Duration; +// use std::time::Duration; use types::{AttestationDuty, Epoch, PublicKey, Slot}; impl BeaconNodeDuties for ValidatorServiceClient { diff --git a/validator_client/src/duties/mod.rs b/validator_client/src/duties/mod.rs index d52cc32544..7db4672e30 100644 --- a/validator_client/src/duties/mod.rs +++ b/validator_client/src/duties/mod.rs @@ -69,7 +69,7 @@ impl DutiesManager { // duties have changed //TODO: Duties could be large here. Remove from display and avoid the clone. self.duties_map.write()?.insert(epoch, duties.clone()); - return Ok(UpdateOutcome::DutiesChanged(epoch, duties)); + Ok(UpdateOutcome::DutiesChanged(epoch, duties)) } /// A future wrapping around `update()`. This will perform logic based upon the update diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index 91c91e0b10..ce9e352665 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -157,7 +157,7 @@ impl Service { let current_slot = slot_clock .present_slot() - .map_err(|e| ErrorKind::SlotClockError(e))? + .map_err(ErrorKind::SlotClockError)? .expect("Genesis must be in the future"); /* Generate the duties manager */ @@ -289,8 +289,7 @@ impl Service { std::thread::spawn(move || { // the return value is a future which returns ready. // built to be compatible with the tokio runtime. - let _empty = cloned_manager.run_update(current_epoch.clone(), cloned_log.clone()); - dbg!("Duties Thread Ended"); + let _empty = cloned_manager.run_update(current_epoch, cloned_log.clone()); }); } @@ -303,7 +302,7 @@ impl Service { // spawns a thread to produce a beacon block let signers = self.duties_manager.signers.clone(); // this is an arc let fork = self.fork.clone(); - let slot = self.current_slot.clone(); + let slot = self.current_slot; let spec = self.spec.clone(); let beacon_node = self.beacon_block_client.clone(); let log = self.log.clone(); @@ -318,7 +317,6 @@ impl Service { signer, }; block_producer.handle_produce_block(log); - dbg!("Block produce Thread Ended"); }); } if work_type.attestation_duty.is_some() { @@ -340,7 +338,6 @@ impl Service { signer, }; attestation_producer.handle_produce_attestation(log); - dbg!("Attestation Thread Ended"); }); } }