Ran cargo fmt.

This commit is contained in:
Luke Anderson 2019-03-28 21:01:47 +11:00
parent 867af4bc6a
commit 87acaac8a0
No known key found for this signature in database
GPG Key ID: 44408169EC61E228
9 changed files with 38 additions and 51 deletions

View File

@ -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<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>,
LocalSigner,
>;
type TestingAttester =
Attester<DirectBeaconNode<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>, LocalSigner>;
/// A `BlockProducer` and `Attester` which sign using a common keypair.
///

View File

@ -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<U: BeaconNode, W: Signer> Attester<U, W> {
}
impl<B: BeaconNode, W: Signer> Attester<B, W> {
fn produce_attestation(&mut self, attestation_duty: AttestationDuty) -> Result<PollOutcome, Error> {
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<PollOutcome, Error> {
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<B: BeaconNode, W: Signer> Attester<B, W> {
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))
);
*/
}
}

View File

@ -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<Option<AttestationData>, BeaconNodeError>;
type PublishResult = Result<PublishOutcome, BeaconNodeError>;

View File

@ -1,4 +1,4 @@
use types::{AttestationData, Attestation, Signature, Slot};
use types::{Attestation, AttestationData, Signature, Slot};
#[derive(Debug, PartialEq, Clone)]
pub enum BeaconNodeError {

View File

@ -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<U: BeaconNode, W: Signer> {
impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
/// Returns a new instance where `last_processed_slot == 0`.
pub fn new(
spec: Arc<ChainSpec>,
beacon_node: Arc<U>,
signer: Arc<W>,
) -> Self {
pub fn new(spec: Arc<ChainSpec>, beacon_node: Arc<U>, signer: Arc<W>) -> Self {
Self {
last_processed_slot: None,
spec,
@ -72,7 +68,6 @@ impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
}
impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
/* 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<U: BeaconNode, W: Signer> BlockProducer<U, W> {
/// The slash-protection code is not yet implemented. There is zero protection against
/// slashing.
fn produce_block(&mut self, slot: Slot, fork: Fork) -> Result<PollOutcome, Error> {
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))));

View File

@ -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<AttestationServiceClient>,

View File

@ -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,
});
}

View File

@ -102,7 +102,7 @@ impl<U: BeaconNode> DutiesManager<U> {
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() {

View File

@ -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,