From 25d1ddfbb0c50155cab86eb42db542eee2fe076a Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sat, 30 Mar 2019 16:34:43 +1100 Subject: [PATCH] Renames BeaconBlockNode to BeaconNodeBlock for future consistency --- .../attestation_grpc_client.rs | 45 ------------------- validator_client/src/attester_service/mod.rs | 7 ++- .../src/block_producer/beacon_block_node.rs | 33 -------------- validator_client/src/block_producer/grpc.rs | 21 ++++----- validator_client/src/block_producer/mod.rs | 16 +++---- validator_client/src/service.rs | 2 +- 6 files changed, 21 insertions(+), 103 deletions(-) delete mode 100644 validator_client/src/attester_service/attestation_grpc_client.rs delete mode 100644 validator_client/src/block_producer/beacon_block_node.rs diff --git a/validator_client/src/attester_service/attestation_grpc_client.rs b/validator_client/src/attester_service/attestation_grpc_client.rs deleted file mode 100644 index 502e51cac..000000000 --- a/validator_client/src/attester_service/attestation_grpc_client.rs +++ /dev/null @@ -1,45 +0,0 @@ -use protos::services_grpc::AttestationServiceClient; -use std::sync::Arc; - -use attester::{BeaconNode, BeaconNodeError, PublishOutcome}; -use protos::services::ProduceAttestationDataRequest; -use types::{Attestation, AttestationData, Slot}; - -pub struct AttestationGrpcClient { - client: Arc, -} - -impl AttestationGrpcClient { - pub fn new(client: Arc) -> Self { - Self { client } - } -} -/* -impl BeaconNode for AttestationGrpcClient { - fn produce_attestation_data( - &self, - slot: Slot, - shard: u64, - ) -> Result, BeaconNodeError> { - let mut req = ProduceAttestationDataRequest::new(); - req.set_slot(slot.as_u64()); - req.set_shard(shard); - - let reply = self - .client - .produce_attestation_data(&req) - .map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?; - - // TODO: return correct Attestation - Err(BeaconNodeError::DecodeFailure) - } - - fn publish_attestation( - &self, - attestation: Attestation, - ) -> Result { - // TODO: return correct PublishOutcome - Err(BeaconNodeError::DecodeFailure) - } -} -*/ diff --git a/validator_client/src/attester_service/mod.rs b/validator_client/src/attester_service/mod.rs index c14669445..1695ec0fb 100644 --- a/validator_client/src/attester_service/mod.rs +++ b/validator_client/src/attester_service/mod.rs @@ -1,4 +1,5 @@ -mod attestation_grpc_client; +mod grpc; +/* use attester::{Attester, BeaconNode, DutiesReader, PollOutcome as AttesterPollOutcome, Signer}; use slog::{error, info, warn, Logger}; use slot_clock::SlotClock; @@ -6,10 +7,8 @@ use std::time::Duration; pub use self::attestation_grpc_client::AttestationGrpcClient; -pub struct AttesterService {} -/* pub struct AttesterService { - // pub attester: Attester, + pub attester: Attester, pub poll_interval_millis: u64, pub log: Logger, } diff --git a/validator_client/src/block_producer/beacon_block_node.rs b/validator_client/src/block_producer/beacon_block_node.rs deleted file mode 100644 index 5a581a4a7..000000000 --- a/validator_client/src/block_producer/beacon_block_node.rs +++ /dev/null @@ -1,33 +0,0 @@ -use types::{BeaconBlock, Signature, Slot}; -#[derive(Debug, PartialEq, Clone)] -pub enum BeaconBlockNodeError { - RemoteFailure(String), - DecodeFailure, -} - -#[derive(Debug, PartialEq, Clone)] -pub enum PublishOutcome { - ValidBlock, - InvalidBlock(String), -} - -/// Defines the methods required to produce and publish blocks on a Beacon Node. Abstracts the -/// actual beacon node. -pub trait BeaconBlockNode: Send + Sync { - /// Request that the node produces a block. - /// - /// Returns Ok(None) if the Beacon Node is unable to produce at the given slot. - fn produce_beacon_block( - &self, - slot: Slot, - randao_reveal: &Signature, - ) -> Result, BeaconBlockNodeError>; - - /// Request that the node publishes a block. - /// - /// Returns `true` if the publish was successful. - fn publish_beacon_block( - &self, - block: BeaconBlock, - ) -> Result; -} diff --git a/validator_client/src/block_producer/grpc.rs b/validator_client/src/block_producer/grpc.rs index 23477ece1..ab0d5d421 100644 --- a/validator_client/src/block_producer/grpc.rs +++ b/validator_client/src/block_producer/grpc.rs @@ -1,4 +1,4 @@ -use super::beacon_block_node::*; +use super::beacon_node_block::*; use protos::services::{ BeaconBlock as GrpcBeaconBlock, ProduceBeaconBlockRequest, PublishBeaconBlockRequest, }; @@ -19,7 +19,7 @@ impl BeaconBlockGrpcClient { } } -impl BeaconBlockNode for BeaconBlockGrpcClient { +impl BeaconNodeBlock for BeaconBlockGrpcClient { /// Request a Beacon Node (BN) to produce a new block at the supplied slot. /// /// Returns `None` if it is not possible to produce at the supplied slot. For example, if the @@ -28,7 +28,7 @@ impl BeaconBlockNode for BeaconBlockGrpcClient { &self, slot: Slot, randao_reveal: &Signature, - ) -> Result, BeaconBlockNodeError> { + ) -> Result, BeaconNodeError> { // request a beacon block from the node let mut req = ProduceBeaconBlockRequest::new(); req.set_slot(slot.as_u64()); @@ -38,15 +38,15 @@ impl BeaconBlockNode for BeaconBlockGrpcClient { let reply = self .client .produce_beacon_block(&req) - .map_err(|err| BeaconBlockNodeError::RemoteFailure(format!("{:?}", err)))?; + .map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?; // format the reply if reply.has_block() { let block = reply.get_block(); let ssz = block.get_ssz(); - let (block, _i) = BeaconBlock::ssz_decode(&ssz, 0) - .map_err(|_| BeaconBlockNodeError::DecodeFailure)?; + let (block, _i) = + BeaconBlock::ssz_decode(&ssz, 0).map_err(|_| BeaconNodeError::DecodeFailure)?; Ok(Some(block)) } else { @@ -58,10 +58,7 @@ impl BeaconBlockNode for BeaconBlockGrpcClient { /// /// Generally, this will be called after a `produce_beacon_block` call with a block that has /// been completed (signed) by the validator client. - fn publish_beacon_block( - &self, - block: BeaconBlock, - ) -> Result { + fn publish_beacon_block(&self, block: BeaconBlock) -> Result { let mut req = PublishBeaconBlockRequest::new(); let ssz = ssz_encode(&block); @@ -74,10 +71,10 @@ impl BeaconBlockNode for BeaconBlockGrpcClient { let reply = self .client .publish_beacon_block(&req) - .map_err(|err| BeaconBlockNodeError::RemoteFailure(format!("{:?}", err)))?; + .map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?; if reply.get_success() { - Ok(PublishOutcome::ValidBlock) + Ok(PublishOutcome::Valid) } else { // TODO: distinguish between different errors Ok(PublishOutcome::InvalidBlock("Publish failed".to_string())) diff --git a/validator_client/src/block_producer/mod.rs b/validator_client/src/block_producer/mod.rs index 7def97e03..09ce9bffa 100644 --- a/validator_client/src/block_producer/mod.rs +++ b/validator_client/src/block_producer/mod.rs @@ -1,7 +1,7 @@ -mod beacon_block_node; +mod beacon_node_block; mod grpc; -use self::beacon_block_node::{BeaconBlockNode, BeaconBlockNodeError}; +use self::beacon_node_block::{BeaconNodeBlock, BeaconNodeError}; pub use self::grpc::BeaconBlockGrpcClient; use crate::signer::Signer; use slog::{error, info}; @@ -11,7 +11,7 @@ use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot}; #[derive(Debug, PartialEq)] pub enum Error { - BeaconBlockNodeError(BeaconBlockNodeError), + BeaconNodeError(BeaconNodeError), } #[derive(Debug, PartialEq)] @@ -28,7 +28,7 @@ pub enum ValidatorEvent { /// This struct contains the logic for requesting and signing beacon blocks for a validator. The /// validator can abstractly sign via the Signer trait object. -pub struct BlockProducer<'a, B: BeaconBlockNode, S: Signer> { +pub struct BlockProducer<'a, B: BeaconNodeBlock, S: Signer> { /// The current fork. pub fork: Fork, /// The current slot to produce a block for. @@ -41,7 +41,7 @@ pub struct BlockProducer<'a, B: BeaconBlockNode, S: Signer> { pub signer: &'a S, } -impl<'a, B: BeaconBlockNode, S: Signer> BlockProducer<'a, B, S> { +impl<'a, B: BeaconNodeBlock, S: Signer> BlockProducer<'a, B, S> { /// Handle outputs and results from block production. pub fn handle_produce_block(&mut self, log: slog::Logger) { match self.produce_block() { @@ -147,9 +147,9 @@ impl<'a, B: BeaconBlockNode, S: Signer> BlockProducer<'a, B, S> { } } -impl From for Error { - fn from(e: BeaconBlockNodeError) -> Error { - Error::BeaconBlockNodeError(e) +impl From for Error { + fn from(e: BeaconNodeError) -> Error { + Error::BeaconNodeError(e) } } diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index 621fb03a3..fd24744ac 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -8,7 +8,7 @@ /// When a validator needs to either produce a block or sign an attestation, it requests the /// data from the beacon node and performs the signing before publishing the block to the beacon /// node. -use crate::attester_service::{AttestationGrpcClient, AttesterService}; +//use crate::attester_service::{AttestationGrpcClient, AttesterService}; use crate::block_producer::{BeaconBlockGrpcClient, BlockProducer}; use crate::config::Config as ValidatorConfig; use crate::duties::{BeaconNodeDuties, DutiesManager, EpochDutiesMap, UpdateOutcome};