From db230475d7bd7b7511e28b2221a7054511b81905 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 1 Feb 2019 16:21:18 +1100 Subject: [PATCH] Remove SlotClock error from block production, tidy. --- .../beacon_chain/src/block_production.rs | 25 ++++--------------- .../src/validator/beacon_node/attester.rs | 6 +---- .../src/validator/beacon_node/producer.rs | 6 +---- .../src/validator/direct_duties.rs | 12 +++------ 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/beacon_node/beacon_chain/src/block_production.rs b/beacon_node/beacon_chain/src/block_production.rs index 6c1fa10c4..eecf1af06 100644 --- a/beacon_node/beacon_chain/src/block_production.rs +++ b/beacon_node/beacon_chain/src/block_production.rs @@ -1,20 +1,16 @@ use super::{BeaconChain, ClientDB, DBError, SlotClock}; use bls::Signature; use log::debug; -use slot_clock::{SystemTimeSlotClockError, TestingSlotClockError}; use types::{ beacon_state::{BlockProcessingError, SlotProcessingError}, - readers::{BeaconBlockReader, BeaconStateReader}, BeaconBlock, BeaconBlockBody, BeaconState, Eth1Data, Hash256, }; #[derive(Debug, PartialEq)] pub enum Error { DBError(String), - PresentSlotIsNone, SlotProcessingError(SlotProcessingError), PerBlockProcessingError(BlockProcessingError), - SlotClockError(SystemTimeSlotClockError), } impl BeaconChain @@ -22,13 +18,14 @@ where T: ClientDB, U: SlotClock, { + /// Produce a new block at the present slot. + /// + /// The produced block will not be inheriently valid, it must be signed by a block producer. + /// Block signing is out of the scope of this function and should be done by a separate program. pub fn produce_block( &self, randao_reveal: Signature, - ) -> Result<(BeaconBlock, BeaconState), Error> - where - Error: From<::Error>, - { + ) -> Result<(BeaconBlock, BeaconState), Error> { debug!("Starting block production..."); let mut state = self.state.read().clone(); @@ -103,15 +100,3 @@ impl From for Error { Error::PerBlockProcessingError(e) } } - -impl From for Error { - fn from(_: TestingSlotClockError) -> Error { - unreachable!(); // Testing clock never throws an error. - } -} - -impl From for Error { - fn from(e: SystemTimeSlotClockError) -> Error { - Error::SlotClockError(e) - } -} diff --git a/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/attester.rs b/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/attester.rs index bcfb929ea..19225b671 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/attester.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/attester.rs @@ -1,14 +1,10 @@ use super::BenchingBeaconNode; use attester::{BeaconNode as AttesterBeaconNode, BeaconNodeError as NodeError, PublishOutcome}; -use beacon_chain::block_production::Error as BlockProductionError; use db::ClientDB; use slot_clock::SlotClock; use types::{AttestationData, FreeAttestation}; -impl AttesterBeaconNode for BenchingBeaconNode -where - BlockProductionError: From<::Error>, -{ +impl AttesterBeaconNode for BenchingBeaconNode { fn produce_attestation_data( &self, _slot: u64, diff --git a/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/producer.rs b/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/producer.rs index 9d0b6b91f..861acd25e 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/producer.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator/beacon_node/producer.rs @@ -1,5 +1,4 @@ use super::BenchingBeaconNode; -use beacon_chain::block_production::Error as BlockProductionError; use block_producer::{ BeaconNode as BeaconBlockNode, BeaconNodeError as BeaconBlockNodeError, PublishOutcome, }; @@ -7,10 +6,7 @@ use db::ClientDB; use slot_clock::SlotClock; use types::{BeaconBlock, PublicKey, Signature}; -impl BeaconBlockNode for BenchingBeaconNode -where - BlockProductionError: From<::Error>, -{ +impl BeaconBlockNode for BenchingBeaconNode { /// Requests the `proposer_nonce` from the `BeaconChain`. fn proposer_nonce(&self, pubkey: &PublicKey) -> Result { let validator_index = self diff --git a/beacon_node/beacon_chain/test_harness/src/validator/direct_duties.rs b/beacon_node/beacon_chain/test_harness/src/validator/direct_duties.rs index eddc0d177..943bf6399 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator/direct_duties.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator/direct_duties.rs @@ -1,7 +1,7 @@ use attester::{ DutiesReader as AttesterDutiesReader, DutiesReaderError as AttesterDutiesReaderError, }; -use beacon_chain::{block_production::Error as BlockProductionError, BeaconChain}; +use beacon_chain::BeaconChain; use block_producer::{ DutiesReader as ProducerDutiesReader, DutiesReaderError as ProducerDutiesReaderError, }; @@ -24,10 +24,7 @@ impl DirectDuties { } } -impl ProducerDutiesReader for DirectDuties -where - BlockProductionError: From<::Error>, -{ +impl ProducerDutiesReader for DirectDuties { fn is_block_production_slot(&self, slot: u64) -> Result { let validator_index = self .beacon_chain @@ -42,10 +39,7 @@ where } } -impl AttesterDutiesReader for DirectDuties -where - BlockProductionError: From<::Error>, -{ +impl AttesterDutiesReader for DirectDuties { fn validator_index(&self) -> Option { match self.beacon_chain.validator_index(&self.pubkey) { Some(index) => Some(index as u64),