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
6 changed files with 21 additions and 103 deletions

View File

@@ -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()))