Renames BeaconBlockNode to BeaconNodeBlock for future consistency

This commit is contained in:
Age Manning 2019-03-30 16:34:43 +11:00
parent bc305cacc2
commit 25d1ddfbb0
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
6 changed files with 21 additions and 103 deletions

View File

@ -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<AttestationServiceClient>,
}
impl AttestationGrpcClient {
pub fn new(client: Arc<AttestationServiceClient>) -> Self {
Self { client }
}
}
/*
impl BeaconNode for AttestationGrpcClient {
fn produce_attestation_data(
&self,
slot: Slot,
shard: u64,
) -> Result<Option<AttestationData>, 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<PublishOutcome, BeaconNodeError> {
// TODO: return correct PublishOutcome
Err(BeaconNodeError::DecodeFailure)
}
}
*/

View File

@ -1,4 +1,5 @@
mod attestation_grpc_client; mod grpc;
/*
use attester::{Attester, BeaconNode, DutiesReader, PollOutcome as AttesterPollOutcome, Signer}; use attester::{Attester, BeaconNode, DutiesReader, PollOutcome as AttesterPollOutcome, Signer};
use slog::{error, info, warn, Logger}; use slog::{error, info, warn, Logger};
use slot_clock::SlotClock; use slot_clock::SlotClock;
@ -6,10 +7,8 @@ use std::time::Duration;
pub use self::attestation_grpc_client::AttestationGrpcClient; pub use self::attestation_grpc_client::AttestationGrpcClient;
pub struct AttesterService {}
/*
pub struct AttesterService<U: BeaconNode, W: Signer> { pub struct AttesterService<U: BeaconNode, W: Signer> {
// pub attester: Attester<U, W>, pub attester: Attester<U, W>,
pub poll_interval_millis: u64, pub poll_interval_millis: u64,
pub log: Logger, pub log: Logger,
} }

View File

@ -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<Option<BeaconBlock>, BeaconBlockNodeError>;
/// Request that the node publishes a block.
///
/// Returns `true` if the publish was successful.
fn publish_beacon_block(
&self,
block: BeaconBlock,
) -> Result<PublishOutcome, BeaconBlockNodeError>;
}

View File

@ -1,4 +1,4 @@
use super::beacon_block_node::*; use super::beacon_node_block::*;
use protos::services::{ use protos::services::{
BeaconBlock as GrpcBeaconBlock, ProduceBeaconBlockRequest, PublishBeaconBlockRequest, 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. /// 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 /// 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, &self,
slot: Slot, slot: Slot,
randao_reveal: &Signature, randao_reveal: &Signature,
) -> Result<Option<BeaconBlock>, BeaconBlockNodeError> { ) -> Result<Option<BeaconBlock>, BeaconNodeError> {
// request a beacon block from the node // request a beacon block from the node
let mut req = ProduceBeaconBlockRequest::new(); let mut req = ProduceBeaconBlockRequest::new();
req.set_slot(slot.as_u64()); req.set_slot(slot.as_u64());
@ -38,15 +38,15 @@ impl BeaconBlockNode for BeaconBlockGrpcClient {
let reply = self let reply = self
.client .client
.produce_beacon_block(&req) .produce_beacon_block(&req)
.map_err(|err| BeaconBlockNodeError::RemoteFailure(format!("{:?}", err)))?; .map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
// format the reply // format the reply
if reply.has_block() { if reply.has_block() {
let block = reply.get_block(); let block = reply.get_block();
let ssz = block.get_ssz(); let ssz = block.get_ssz();
let (block, _i) = BeaconBlock::ssz_decode(&ssz, 0) let (block, _i) =
.map_err(|_| BeaconBlockNodeError::DecodeFailure)?; BeaconBlock::ssz_decode(&ssz, 0).map_err(|_| BeaconNodeError::DecodeFailure)?;
Ok(Some(block)) Ok(Some(block))
} else { } 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 /// Generally, this will be called after a `produce_beacon_block` call with a block that has
/// been completed (signed) by the validator client. /// been completed (signed) by the validator client.
fn publish_beacon_block( fn publish_beacon_block(&self, block: BeaconBlock) -> Result<PublishOutcome, BeaconNodeError> {
&self,
block: BeaconBlock,
) -> Result<PublishOutcome, BeaconBlockNodeError> {
let mut req = PublishBeaconBlockRequest::new(); let mut req = PublishBeaconBlockRequest::new();
let ssz = ssz_encode(&block); let ssz = ssz_encode(&block);
@ -74,10 +71,10 @@ impl BeaconBlockNode for BeaconBlockGrpcClient {
let reply = self let reply = self
.client .client
.publish_beacon_block(&req) .publish_beacon_block(&req)
.map_err(|err| BeaconBlockNodeError::RemoteFailure(format!("{:?}", err)))?; .map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
if reply.get_success() { if reply.get_success() {
Ok(PublishOutcome::ValidBlock) Ok(PublishOutcome::Valid)
} else { } else {
// TODO: distinguish between different errors // TODO: distinguish between different errors
Ok(PublishOutcome::InvalidBlock("Publish failed".to_string())) Ok(PublishOutcome::InvalidBlock("Publish failed".to_string()))

View File

@ -1,7 +1,7 @@
mod beacon_block_node; mod beacon_node_block;
mod grpc; mod grpc;
use self::beacon_block_node::{BeaconBlockNode, BeaconBlockNodeError}; use self::beacon_node_block::{BeaconNodeBlock, BeaconNodeError};
pub use self::grpc::BeaconBlockGrpcClient; pub use self::grpc::BeaconBlockGrpcClient;
use crate::signer::Signer; use crate::signer::Signer;
use slog::{error, info}; use slog::{error, info};
@ -11,7 +11,7 @@ use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Error { pub enum Error {
BeaconBlockNodeError(BeaconBlockNodeError), BeaconNodeError(BeaconNodeError),
} }
#[derive(Debug, PartialEq)] #[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 /// This struct contains the logic for requesting and signing beacon blocks for a validator. The
/// validator can abstractly sign via the Signer trait object. /// 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. /// The current fork.
pub fork: Fork, pub fork: Fork,
/// The current slot to produce a block for. /// The current slot to produce a block for.
@ -41,7 +41,7 @@ pub struct BlockProducer<'a, B: BeaconBlockNode, S: Signer> {
pub signer: &'a S, 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. /// Handle outputs and results from block production.
pub fn handle_produce_block(&mut self, log: slog::Logger) { pub fn handle_produce_block(&mut self, log: slog::Logger) {
match self.produce_block() { match self.produce_block() {
@ -147,9 +147,9 @@ impl<'a, B: BeaconBlockNode, S: Signer> BlockProducer<'a, B, S> {
} }
} }
impl From<BeaconBlockNodeError> for Error { impl From<BeaconNodeError> for Error {
fn from(e: BeaconBlockNodeError) -> Error { fn from(e: BeaconNodeError) -> Error {
Error::BeaconBlockNodeError(e) Error::BeaconNodeError(e)
} }
} }

View File

@ -8,7 +8,7 @@
/// When a validator needs to either produce a block or sign an attestation, it requests the /// 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 /// data from the beacon node and performs the signing before publishing the block to the beacon
/// node. /// node.
use crate::attester_service::{AttestationGrpcClient, AttesterService}; //use crate::attester_service::{AttestationGrpcClient, AttesterService};
use crate::block_producer::{BeaconBlockGrpcClient, BlockProducer}; use crate::block_producer::{BeaconBlockGrpcClient, BlockProducer};
use crate::config::Config as ValidatorConfig; use crate::config::Config as ValidatorConfig;
use crate::duties::{BeaconNodeDuties, DutiesManager, EpochDutiesMap, UpdateOutcome}; use crate::duties::{BeaconNodeDuties, DutiesManager, EpochDutiesMap, UpdateOutcome};