Renames BeaconBlockNode to BeaconNodeBlock for future consistency
This commit is contained in:
parent
bc305cacc2
commit
25d1ddfbb0
@ -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)
|
||||
}
|
||||
}
|
||||
*/
|
@ -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<U: BeaconNode, W: Signer> {
|
||||
// pub attester: Attester<U, W>,
|
||||
pub attester: Attester<U, W>,
|
||||
pub poll_interval_millis: u64,
|
||||
pub log: Logger,
|
||||
}
|
||||
|
@ -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>;
|
||||
}
|
@ -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<Option<BeaconBlock>, BeaconBlockNodeError> {
|
||||
) -> Result<Option<BeaconBlock>, 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<PublishOutcome, BeaconBlockNodeError> {
|
||||
fn publish_beacon_block(&self, block: BeaconBlock) -> Result<PublishOutcome, BeaconNodeError> {
|
||||
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()))
|
||||
|
@ -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<BeaconBlockNodeError> for Error {
|
||||
fn from(e: BeaconBlockNodeError) -> Error {
|
||||
Error::BeaconBlockNodeError(e)
|
||||
impl From<BeaconNodeError> for Error {
|
||||
fn from(e: BeaconNodeError) -> Error {
|
||||
Error::BeaconNodeError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user