mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +00:00
Delete SlotClock errs from block_processing, tidy.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use super::{BeaconChain, ClientDB, DBError, SlotClock};
|
||||
use log::debug;
|
||||
use slot_clock::{SystemTimeSlotClockError, TestingSlotClockError};
|
||||
use ssz::{ssz_encode, Encodable};
|
||||
use types::{
|
||||
beacon_state::{BlockProcessingError, SlotProcessingError},
|
||||
@@ -10,32 +9,46 @@ use types::{
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ValidBlock {
|
||||
/// The block was sucessfully processed.
|
||||
Processed,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum InvalidBlock {
|
||||
/// The block slot is greater than the present slot.
|
||||
FutureSlot,
|
||||
/// The block state_root does not match the generated state.
|
||||
StateRootMismatch,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Outcome {
|
||||
/// The block was sucessfully validated.
|
||||
ValidBlock(ValidBlock),
|
||||
/// The block was not sucessfully validated.
|
||||
InvalidBlock(InvalidBlock),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
/// There was in internal database error.
|
||||
DBError(String),
|
||||
/// The block SSZ encoding is unreadable.
|
||||
UnableToDecodeBlock,
|
||||
SlotClockError(SystemTimeSlotClockError),
|
||||
/// The blocks parent state is not in the database. This is an internal error.
|
||||
MissingParentState(Hash256),
|
||||
/// The blocks parent state is in the database, but invalid. This is an internal error.
|
||||
InvalidParentState(Hash256),
|
||||
/// The blocks parent state is in the database, but invalid. This is an internal error.
|
||||
MissingBeaconBlock(Hash256),
|
||||
/// The parent block is not in the database. The block should not be processed.
|
||||
InvalidBeaconBlock(Hash256),
|
||||
/// The parent block is not in the database, but invalid. This is an internal error.
|
||||
MissingParentBlock(Hash256),
|
||||
/// There was an error whilst advancing the parent state to the present slot. This is an
|
||||
/// internal error.
|
||||
SlotProcessingError(SlotProcessingError),
|
||||
/// There was an error whilst processing the block against it's state. The block is invalid.
|
||||
PerBlockProcessingError(BlockProcessingError),
|
||||
}
|
||||
|
||||
@@ -43,8 +56,10 @@ impl<T, U> BeaconChain<T, U>
|
||||
where
|
||||
T: ClientDB,
|
||||
U: SlotClock,
|
||||
Error: From<<U as SlotClock>::Error>,
|
||||
{
|
||||
/// Accept some block and attempt to add it to block DAG.
|
||||
///
|
||||
/// Will accept blocks from prior slots, however it will reject any block from a future slot.
|
||||
pub fn process_block<V>(&self, block: V) -> Result<Outcome, Error>
|
||||
where
|
||||
V: BeaconBlockReader + Encodable + Sized,
|
||||
@@ -94,12 +109,14 @@ where
|
||||
self.block_store.put(&block_root, &ssz_encode(&block)[..])?;
|
||||
self.state_store.put(&state_root, &ssz_encode(&state)[..])?;
|
||||
|
||||
// Update the block DAG.
|
||||
self.block_graph
|
||||
.add_leaf(&parent_block_root, block_root.clone());
|
||||
|
||||
// If the parent block was the parent_block, automatically update the canonical head.
|
||||
//
|
||||
// TODO: this is a first-in-best-dressed scenario that is not ideal -- find a solution.
|
||||
// TODO: this is a first-in-best-dressed scenario that is not ideal; fork_choice should be
|
||||
// run instead.
|
||||
if self.head().beacon_block_root == parent_block_root {
|
||||
self.update_canonical_head(
|
||||
block.clone(),
|
||||
@@ -107,10 +124,10 @@ where
|
||||
state.clone(),
|
||||
state_root.clone(),
|
||||
);
|
||||
// Update the local state variable.
|
||||
*self.state.write() = state.clone();
|
||||
}
|
||||
|
||||
// The block was sucessfully processed.
|
||||
Ok(Outcome::ValidBlock(ValidBlock::Processed))
|
||||
}
|
||||
}
|
||||
@@ -132,15 +149,3 @@ impl From<BlockProcessingError> for Error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user