mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-29 07:17:17 +00:00
Remove SlotClock error from block production, tidy.
This commit is contained in:
parent
9d1f98ba8f
commit
db230475d7
@ -1,20 +1,16 @@
|
|||||||
use super::{BeaconChain, ClientDB, DBError, SlotClock};
|
use super::{BeaconChain, ClientDB, DBError, SlotClock};
|
||||||
use bls::Signature;
|
use bls::Signature;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use slot_clock::{SystemTimeSlotClockError, TestingSlotClockError};
|
|
||||||
use types::{
|
use types::{
|
||||||
beacon_state::{BlockProcessingError, SlotProcessingError},
|
beacon_state::{BlockProcessingError, SlotProcessingError},
|
||||||
readers::{BeaconBlockReader, BeaconStateReader},
|
|
||||||
BeaconBlock, BeaconBlockBody, BeaconState, Eth1Data, Hash256,
|
BeaconBlock, BeaconBlockBody, BeaconState, Eth1Data, Hash256,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
DBError(String),
|
DBError(String),
|
||||||
PresentSlotIsNone,
|
|
||||||
SlotProcessingError(SlotProcessingError),
|
SlotProcessingError(SlotProcessingError),
|
||||||
PerBlockProcessingError(BlockProcessingError),
|
PerBlockProcessingError(BlockProcessingError),
|
||||||
SlotClockError(SystemTimeSlotClockError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, U> BeaconChain<T, U>
|
impl<T, U> BeaconChain<T, U>
|
||||||
@ -22,13 +18,14 @@ where
|
|||||||
T: ClientDB,
|
T: ClientDB,
|
||||||
U: SlotClock,
|
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(
|
pub fn produce_block(
|
||||||
&self,
|
&self,
|
||||||
randao_reveal: Signature,
|
randao_reveal: Signature,
|
||||||
) -> Result<(BeaconBlock, BeaconState), Error>
|
) -> Result<(BeaconBlock, BeaconState), Error> {
|
||||||
where
|
|
||||||
Error: From<<U>::Error>,
|
|
||||||
{
|
|
||||||
debug!("Starting block production...");
|
debug!("Starting block production...");
|
||||||
|
|
||||||
let mut state = self.state.read().clone();
|
let mut state = self.state.read().clone();
|
||||||
@ -103,15 +100,3 @@ impl From<BlockProcessingError> for Error {
|
|||||||
Error::PerBlockProcessingError(e)
|
Error::PerBlockProcessingError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TestingSlotClockError> for Error {
|
|
||||||
fn from(_: TestingSlotClockError) -> Error {
|
|
||||||
unreachable!(); // Testing clock never throws an error.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<SystemTimeSlotClockError> for Error {
|
|
||||||
fn from(e: SystemTimeSlotClockError) -> Error {
|
|
||||||
Error::SlotClockError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
use super::BenchingBeaconNode;
|
use super::BenchingBeaconNode;
|
||||||
use attester::{BeaconNode as AttesterBeaconNode, BeaconNodeError as NodeError, PublishOutcome};
|
use attester::{BeaconNode as AttesterBeaconNode, BeaconNodeError as NodeError, PublishOutcome};
|
||||||
use beacon_chain::block_production::Error as BlockProductionError;
|
|
||||||
use db::ClientDB;
|
use db::ClientDB;
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use types::{AttestationData, FreeAttestation};
|
use types::{AttestationData, FreeAttestation};
|
||||||
|
|
||||||
impl<T: ClientDB, U: SlotClock> AttesterBeaconNode for BenchingBeaconNode<T, U>
|
impl<T: ClientDB, U: SlotClock> AttesterBeaconNode for BenchingBeaconNode<T, U> {
|
||||||
where
|
|
||||||
BlockProductionError: From<<U>::Error>,
|
|
||||||
{
|
|
||||||
fn produce_attestation_data(
|
fn produce_attestation_data(
|
||||||
&self,
|
&self,
|
||||||
_slot: u64,
|
_slot: u64,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use super::BenchingBeaconNode;
|
use super::BenchingBeaconNode;
|
||||||
use beacon_chain::block_production::Error as BlockProductionError;
|
|
||||||
use block_producer::{
|
use block_producer::{
|
||||||
BeaconNode as BeaconBlockNode, BeaconNodeError as BeaconBlockNodeError, PublishOutcome,
|
BeaconNode as BeaconBlockNode, BeaconNodeError as BeaconBlockNodeError, PublishOutcome,
|
||||||
};
|
};
|
||||||
@ -7,10 +6,7 @@ use db::ClientDB;
|
|||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use types::{BeaconBlock, PublicKey, Signature};
|
use types::{BeaconBlock, PublicKey, Signature};
|
||||||
|
|
||||||
impl<T: ClientDB, U: SlotClock> BeaconBlockNode for BenchingBeaconNode<T, U>
|
impl<T: ClientDB, U: SlotClock> BeaconBlockNode for BenchingBeaconNode<T, U> {
|
||||||
where
|
|
||||||
BlockProductionError: From<<U>::Error>,
|
|
||||||
{
|
|
||||||
/// Requests the `proposer_nonce` from the `BeaconChain`.
|
/// Requests the `proposer_nonce` from the `BeaconChain`.
|
||||||
fn proposer_nonce(&self, pubkey: &PublicKey) -> Result<u64, BeaconBlockNodeError> {
|
fn proposer_nonce(&self, pubkey: &PublicKey) -> Result<u64, BeaconBlockNodeError> {
|
||||||
let validator_index = self
|
let validator_index = self
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use attester::{
|
use attester::{
|
||||||
DutiesReader as AttesterDutiesReader, DutiesReaderError as AttesterDutiesReaderError,
|
DutiesReader as AttesterDutiesReader, DutiesReaderError as AttesterDutiesReaderError,
|
||||||
};
|
};
|
||||||
use beacon_chain::{block_production::Error as BlockProductionError, BeaconChain};
|
use beacon_chain::BeaconChain;
|
||||||
use block_producer::{
|
use block_producer::{
|
||||||
DutiesReader as ProducerDutiesReader, DutiesReaderError as ProducerDutiesReaderError,
|
DutiesReader as ProducerDutiesReader, DutiesReaderError as ProducerDutiesReaderError,
|
||||||
};
|
};
|
||||||
@ -24,10 +24,7 @@ impl<T: ClientDB, U: SlotClock> DirectDuties<T, U> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ClientDB, U: SlotClock> ProducerDutiesReader for DirectDuties<T, U>
|
impl<T: ClientDB, U: SlotClock> ProducerDutiesReader for DirectDuties<T, U> {
|
||||||
where
|
|
||||||
BlockProductionError: From<<U>::Error>,
|
|
||||||
{
|
|
||||||
fn is_block_production_slot(&self, slot: u64) -> Result<bool, ProducerDutiesReaderError> {
|
fn is_block_production_slot(&self, slot: u64) -> Result<bool, ProducerDutiesReaderError> {
|
||||||
let validator_index = self
|
let validator_index = self
|
||||||
.beacon_chain
|
.beacon_chain
|
||||||
@ -42,10 +39,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ClientDB, U: SlotClock> AttesterDutiesReader for DirectDuties<T, U>
|
impl<T: ClientDB, U: SlotClock> AttesterDutiesReader for DirectDuties<T, U> {
|
||||||
where
|
|
||||||
BlockProductionError: From<<U>::Error>,
|
|
||||||
{
|
|
||||||
fn validator_index(&self) -> Option<u64> {
|
fn validator_index(&self) -> Option<u64> {
|
||||||
match self.beacon_chain.validator_index(&self.pubkey) {
|
match self.beacon_chain.validator_index(&self.pubkey) {
|
||||||
Some(index) => Some(index as u64),
|
Some(index) => Some(index as u64),
|
||||||
|
Loading…
Reference in New Issue
Block a user