2019-02-14 01:09:18 +00:00
|
|
|
use crate::checkpoint::CheckPoint;
|
2019-03-07 01:53:15 +00:00
|
|
|
use crate::errors::{BeaconChainError as Error, BlockProductionError};
|
2019-02-14 01:09:18 +00:00
|
|
|
use db::{
|
|
|
|
stores::{BeaconBlockStore, BeaconStateStore},
|
|
|
|
ClientDB, DBError,
|
|
|
|
};
|
|
|
|
use fork_choice::{ForkChoice, ForkChoiceError};
|
2019-03-29 08:09:01 +00:00
|
|
|
use log::{debug, trace};
|
2019-03-29 07:54:01 +00:00
|
|
|
use operation_pool::DepositInsertStatus;
|
2019-03-29 07:30:03 +00:00
|
|
|
use operation_pool::OperationPool;
|
2019-02-14 01:09:18 +00:00
|
|
|
use parking_lot::{RwLock, RwLockReadGuard};
|
|
|
|
use slot_clock::SlotClock;
|
|
|
|
use ssz::ssz_encode;
|
2019-03-30 08:11:52 +00:00
|
|
|
use state_processing::per_block_processing::errors::{
|
2019-03-29 07:54:01 +00:00
|
|
|
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
|
|
|
|
ExitValidationError, ProposerSlashingValidationError, TransferValidationError,
|
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
use state_processing::{
|
2019-03-07 01:25:29 +00:00
|
|
|
per_block_processing, per_block_processing_without_verifying_block_signature,
|
|
|
|
per_slot_processing, BlockProcessingError, SlotProcessingError,
|
2019-02-14 01:09:18 +00:00
|
|
|
};
|
|
|
|
use std::sync::Arc;
|
2019-03-17 07:10:20 +00:00
|
|
|
use types::*;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum ValidBlock {
|
|
|
|
/// The block was successfully processed.
|
|
|
|
Processed,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum InvalidBlock {
|
|
|
|
/// The block slot is greater than the present slot.
|
2019-03-24 05:35:07 +00:00
|
|
|
FutureSlot {
|
|
|
|
present_slot: Slot,
|
|
|
|
block_slot: Slot,
|
|
|
|
},
|
2019-02-14 01:09:18 +00:00
|
|
|
/// The block state_root does not match the generated state.
|
|
|
|
StateRootMismatch,
|
|
|
|
/// The blocks parent_root is unknown.
|
|
|
|
ParentUnknown,
|
|
|
|
/// There was an error whilst advancing the parent state to the present slot. This condition
|
|
|
|
/// should not occur, it likely represents an internal error.
|
|
|
|
SlotProcessingError(SlotProcessingError),
|
|
|
|
/// The block could not be applied to the state, it is invalid.
|
|
|
|
PerBlockProcessingError(BlockProcessingError),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum BlockProcessingOutcome {
|
|
|
|
/// The block was successfully validated.
|
|
|
|
ValidBlock(ValidBlock),
|
|
|
|
/// The block was not successfully validated.
|
|
|
|
InvalidBlock(InvalidBlock),
|
|
|
|
}
|
|
|
|
|
2019-03-23 07:48:09 +00:00
|
|
|
impl BlockProcessingOutcome {
|
|
|
|
/// Returns `true` if the block was objectively invalid and we should disregard the peer who
|
|
|
|
/// sent it.
|
|
|
|
pub fn is_invalid(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
BlockProcessingOutcome::ValidBlock(_) => false,
|
|
|
|
BlockProcessingOutcome::InvalidBlock(r) => match r {
|
2019-03-24 05:35:07 +00:00
|
|
|
InvalidBlock::FutureSlot { .. } => true,
|
2019-03-23 07:48:09 +00:00
|
|
|
InvalidBlock::StateRootMismatch => true,
|
|
|
|
InvalidBlock::ParentUnknown => false,
|
|
|
|
InvalidBlock::SlotProcessingError(_) => false,
|
|
|
|
InvalidBlock::PerBlockProcessingError(e) => match e {
|
|
|
|
BlockProcessingError::Invalid(_) => true,
|
|
|
|
BlockProcessingError::BeaconStateError(_) => false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 03:22:12 +00:00
|
|
|
|
|
|
|
/// Returns `true` if the block was successfully processed and can be removed from any import
|
|
|
|
/// queues or temporary storage.
|
|
|
|
pub fn sucessfully_processed(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
BlockProcessingOutcome::ValidBlock(_) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 07:48:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice> {
|
|
|
|
pub block_store: Arc<BeaconBlockStore<T>>,
|
|
|
|
pub state_store: Arc<BeaconStateStore<T>>,
|
|
|
|
pub slot_clock: U,
|
2019-03-30 01:26:25 +00:00
|
|
|
pub op_pool: OperationPool,
|
2019-02-14 01:09:18 +00:00
|
|
|
canonical_head: RwLock<CheckPoint>,
|
|
|
|
finalized_head: RwLock<CheckPoint>,
|
|
|
|
pub state: RwLock<BeaconState>,
|
|
|
|
pub spec: ChainSpec,
|
|
|
|
pub fork_choice: RwLock<F>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U, F> BeaconChain<T, U, F>
|
|
|
|
where
|
|
|
|
T: ClientDB,
|
|
|
|
U: SlotClock,
|
|
|
|
F: ForkChoice,
|
|
|
|
{
|
|
|
|
/// Instantiate a new Beacon Chain, from genesis.
|
2019-03-08 04:33:45 +00:00
|
|
|
pub fn from_genesis(
|
2019-02-14 01:09:18 +00:00
|
|
|
state_store: Arc<BeaconStateStore<T>>,
|
|
|
|
block_store: Arc<BeaconBlockStore<T>>,
|
|
|
|
slot_clock: U,
|
2019-03-08 04:33:45 +00:00
|
|
|
mut genesis_state: BeaconState,
|
|
|
|
genesis_block: BeaconBlock,
|
2019-02-14 01:09:18 +00:00
|
|
|
spec: ChainSpec,
|
|
|
|
fork_choice: F,
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
let state_root = genesis_state.canonical_root();
|
|
|
|
state_store.put(&state_root, &ssz_encode(&genesis_state)[..])?;
|
|
|
|
|
2019-03-19 23:51:53 +00:00
|
|
|
let block_root = genesis_block.block_header().canonical_root();
|
2019-02-14 01:09:18 +00:00
|
|
|
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
|
|
|
|
|
|
|
|
let finalized_head = RwLock::new(CheckPoint::new(
|
|
|
|
genesis_block.clone(),
|
|
|
|
block_root,
|
|
|
|
genesis_state.clone(),
|
|
|
|
state_root,
|
|
|
|
));
|
|
|
|
let canonical_head = RwLock::new(CheckPoint::new(
|
|
|
|
genesis_block.clone(),
|
|
|
|
block_root,
|
|
|
|
genesis_state.clone(),
|
|
|
|
state_root,
|
|
|
|
));
|
|
|
|
|
2019-03-31 02:40:12 +00:00
|
|
|
genesis_state.build_all_caches(&spec)?;
|
2019-02-22 05:14:16 +00:00
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
Ok(Self {
|
|
|
|
block_store,
|
|
|
|
state_store,
|
|
|
|
slot_clock,
|
2019-03-30 01:26:25 +00:00
|
|
|
op_pool: OperationPool::new(),
|
2019-02-22 05:14:16 +00:00
|
|
|
state: RwLock::new(genesis_state),
|
2019-02-14 01:09:18 +00:00
|
|
|
finalized_head,
|
|
|
|
canonical_head,
|
|
|
|
spec,
|
|
|
|
fork_choice: RwLock::new(fork_choice),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-24 01:49:59 +00:00
|
|
|
/// Returns the beacon block body for each beacon block root in `roots`.
|
|
|
|
///
|
|
|
|
/// Fails if any root in `roots` does not have a corresponding block.
|
|
|
|
pub fn get_block_bodies(&self, roots: &[Hash256]) -> Result<Vec<BeaconBlockBody>, Error> {
|
|
|
|
let bodies: Result<Vec<BeaconBlockBody>, _> = roots
|
|
|
|
.iter()
|
|
|
|
.map(|root| match self.get_block(root)? {
|
|
|
|
Some(block) => Ok(block.body),
|
|
|
|
None => Err(Error::DBInconsistent("Missing block".into())),
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(bodies?)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the beacon block header for each beacon block root in `roots`.
|
|
|
|
///
|
|
|
|
/// Fails if any root in `roots` does not have a corresponding block.
|
|
|
|
pub fn get_block_headers(&self, roots: &[Hash256]) -> Result<Vec<BeaconBlockHeader>, Error> {
|
|
|
|
let headers: Result<Vec<BeaconBlockHeader>, _> = roots
|
|
|
|
.iter()
|
|
|
|
.map(|root| match self.get_block(root)? {
|
|
|
|
Some(block) => Ok(block.block_header()),
|
|
|
|
None => Err(Error::DBInconsistent("Missing block".into())),
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(headers?)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns `count `beacon block roots, starting from `start_slot` with an
|
|
|
|
/// interval of `skip` slots between each root.
|
2019-03-22 03:20:49 +00:00
|
|
|
///
|
|
|
|
/// ## Errors:
|
|
|
|
///
|
|
|
|
/// - `SlotOutOfBounds`: Unable to return the full specified range.
|
|
|
|
/// - `SlotOutOfBounds`: Unable to load a state from the DB.
|
|
|
|
/// - `SlotOutOfBounds`: Start slot is higher than the first slot.
|
|
|
|
/// - Other: BeaconState` is inconsistent.
|
|
|
|
pub fn get_block_roots(
|
|
|
|
&self,
|
2019-03-24 01:49:59 +00:00
|
|
|
earliest_slot: Slot,
|
|
|
|
count: usize,
|
|
|
|
skip: usize,
|
|
|
|
) -> Result<Vec<Hash256>, Error> {
|
2019-03-22 03:20:49 +00:00
|
|
|
let spec = &self.spec;
|
2019-03-24 01:49:59 +00:00
|
|
|
let step_by = Slot::from(skip + 1);
|
2019-03-22 03:20:49 +00:00
|
|
|
|
|
|
|
let mut roots: Vec<Hash256> = vec![];
|
2019-03-24 01:49:59 +00:00
|
|
|
|
|
|
|
// The state for reading block roots. Will be updated with an older state if slots go too
|
|
|
|
// far back in history.
|
2019-03-22 03:20:49 +00:00
|
|
|
let mut state = self.state.read().clone();
|
|
|
|
|
2019-03-24 01:49:59 +00:00
|
|
|
// The final slot in this series, will be reduced by `skip` each loop iteration.
|
|
|
|
let mut slot = earliest_slot + Slot::from(count * (skip + 1)) - 1;
|
2019-03-23 02:23:44 +00:00
|
|
|
|
2019-03-24 01:49:59 +00:00
|
|
|
// If the highest slot requested is that of the current state insert the root of the
|
|
|
|
// head block, unless the head block's slot is not matching.
|
|
|
|
if slot == state.slot && self.head().beacon_block.slot == slot {
|
|
|
|
roots.push(self.head().beacon_block_root);
|
2019-03-22 03:20:49 +00:00
|
|
|
|
2019-03-24 01:49:59 +00:00
|
|
|
slot -= step_by;
|
|
|
|
} else if slot >= state.slot {
|
|
|
|
return Err(BeaconStateError::SlotOutOfBounds.into());
|
|
|
|
}
|
|
|
|
|
|
|
|
loop {
|
2019-03-22 03:20:49 +00:00
|
|
|
// If the slot is within the range of the current state's block roots, append the root
|
|
|
|
// to the output vec.
|
|
|
|
//
|
2019-03-24 01:49:59 +00:00
|
|
|
// If we get `SlotOutOfBounds` error, load the oldest available historic
|
|
|
|
// state from the DB.
|
2019-03-22 03:20:49 +00:00
|
|
|
match state.get_block_root(slot, spec) {
|
|
|
|
Ok(root) => {
|
2019-03-24 01:49:59 +00:00
|
|
|
if slot < earliest_slot {
|
2019-03-22 03:20:49 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2019-03-24 01:49:59 +00:00
|
|
|
roots.push(*root);
|
|
|
|
slot -= step_by;
|
2019-03-22 03:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(BeaconStateError::SlotOutOfBounds) => {
|
|
|
|
// Read the earliest historic state in the current slot.
|
|
|
|
let earliest_historic_slot =
|
|
|
|
state.slot - Slot::from(spec.slots_per_historical_root);
|
|
|
|
// Load the earlier state from disk.
|
|
|
|
let new_state_root = state.get_state_root(earliest_historic_slot, spec)?;
|
|
|
|
|
|
|
|
// Break if the DB is unable to load the state.
|
|
|
|
state = match self.state_store.get_deserialized(&new_state_root) {
|
|
|
|
Ok(Some(state)) => state,
|
|
|
|
_ => break,
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 01:49:59 +00:00
|
|
|
Err(e) => return Err(e.into()),
|
2019-03-22 03:20:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-24 01:49:59 +00:00
|
|
|
// Return the results if they pass a sanity check.
|
|
|
|
if (slot <= earliest_slot) && (roots.len() == count) {
|
2019-03-23 02:23:44 +00:00
|
|
|
// Reverse the ordering of the roots. We extracted them in reverse order to make it
|
|
|
|
// simpler to lookup historic states.
|
|
|
|
//
|
|
|
|
// This is a potential optimisation target.
|
|
|
|
Ok(roots.iter().rev().cloned().collect())
|
2019-03-22 03:20:49 +00:00
|
|
|
} else {
|
2019-03-24 01:49:59 +00:00
|
|
|
Err(BeaconStateError::SlotOutOfBounds.into())
|
2019-03-22 03:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:23:44 +00:00
|
|
|
/// Returns the block at the given root, if any.
|
|
|
|
///
|
|
|
|
/// ## Errors
|
|
|
|
///
|
|
|
|
/// May return a database error.
|
|
|
|
pub fn get_block(&self, block_root: &Hash256) -> Result<Option<BeaconBlock>, Error> {
|
|
|
|
Ok(self.block_store.get_deserialized(block_root)?)
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Update the canonical head to some new values.
|
|
|
|
pub fn update_canonical_head(
|
|
|
|
&self,
|
|
|
|
new_beacon_block: BeaconBlock,
|
|
|
|
new_beacon_block_root: Hash256,
|
|
|
|
new_beacon_state: BeaconState,
|
|
|
|
new_beacon_state_root: Hash256,
|
|
|
|
) {
|
2019-02-22 05:14:16 +00:00
|
|
|
debug!(
|
|
|
|
"Updating canonical head with block at slot: {}",
|
|
|
|
new_beacon_block.slot
|
|
|
|
);
|
2019-02-14 01:09:18 +00:00
|
|
|
let mut head = self.canonical_head.write();
|
|
|
|
head.update(
|
|
|
|
new_beacon_block,
|
|
|
|
new_beacon_block_root,
|
|
|
|
new_beacon_state,
|
|
|
|
new_beacon_state_root,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a read-lock guarded `CheckPoint` struct for reading the head (as chosen by the
|
|
|
|
/// fork-choice rule).
|
|
|
|
///
|
|
|
|
/// It is important to note that the `beacon_state` returned may not match the present slot. It
|
2019-03-31 04:35:54 +00:00
|
|
|
/// is the state as it was when the head block was received, which could be some slots prior to
|
2019-02-14 01:09:18 +00:00
|
|
|
/// now.
|
|
|
|
pub fn head(&self) -> RwLockReadGuard<CheckPoint> {
|
|
|
|
self.canonical_head.read()
|
|
|
|
}
|
|
|
|
|
2019-03-24 05:35:07 +00:00
|
|
|
/// Updates the canonical `BeaconState` with the supplied state.
|
|
|
|
///
|
|
|
|
/// Advances the chain forward to the present slot. This method is better than just setting
|
|
|
|
/// state and calling `catchup_state` as it will not result in an old state being installed and
|
|
|
|
/// then having it iteratively updated -- in such a case it's possible for another thread to
|
|
|
|
/// find the state at an old slot.
|
|
|
|
pub fn update_state(&self, mut state: BeaconState) -> Result<(), Error> {
|
|
|
|
let latest_block_header = self.head().beacon_block.block_header();
|
|
|
|
|
|
|
|
let present_slot = match self.slot_clock.present_slot() {
|
|
|
|
Ok(Some(slot)) => slot,
|
|
|
|
_ => return Err(Error::UnableToReadSlot),
|
|
|
|
};
|
|
|
|
|
|
|
|
// If required, transition the new state to the present slot.
|
|
|
|
for _ in state.slot.as_u64()..present_slot.as_u64() {
|
|
|
|
per_slot_processing(&mut state, &latest_block_header, &self.spec)?;
|
|
|
|
}
|
|
|
|
|
2019-03-31 02:40:12 +00:00
|
|
|
state.build_all_caches(&self.spec)?;
|
|
|
|
|
2019-03-24 05:35:07 +00:00
|
|
|
*self.state.write() = state;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensures the current canonical `BeaconState` has been transitioned to match the `slot_clock`.
|
|
|
|
pub fn catchup_state(&self) -> Result<(), Error> {
|
|
|
|
let latest_block_header = self.head().beacon_block.block_header();
|
|
|
|
|
|
|
|
let present_slot = match self.slot_clock.present_slot() {
|
|
|
|
Ok(Some(slot)) => slot,
|
|
|
|
_ => return Err(Error::UnableToReadSlot),
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut state = self.state.write();
|
|
|
|
|
|
|
|
// If required, transition the new state to the present slot.
|
|
|
|
for _ in state.slot.as_u64()..present_slot.as_u64() {
|
2019-03-26 23:34:52 +00:00
|
|
|
// Ensure the next epoch state caches are built in case of an epoch transition.
|
|
|
|
state.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, &self.spec)?;
|
|
|
|
state.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, &self.spec)?;
|
|
|
|
|
2019-03-24 05:35:07 +00:00
|
|
|
per_slot_processing(&mut *state, &latest_block_header, &self.spec)?;
|
|
|
|
}
|
2019-03-31 02:40:12 +00:00
|
|
|
|
|
|
|
state.build_all_caches(&self.spec)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Build all of the caches on the current state.
|
|
|
|
///
|
|
|
|
/// Ideally this shouldn't be required, however we leave it here for testing.
|
|
|
|
pub fn ensure_state_caches_are_built(&self) -> Result<(), Error> {
|
|
|
|
self.state.write().build_all_caches(&self.spec)?;
|
2019-03-24 05:35:07 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Update the justified head to some new values.
|
|
|
|
pub fn update_finalized_head(
|
|
|
|
&self,
|
|
|
|
new_beacon_block: BeaconBlock,
|
|
|
|
new_beacon_block_root: Hash256,
|
|
|
|
new_beacon_state: BeaconState,
|
|
|
|
new_beacon_state_root: Hash256,
|
|
|
|
) {
|
|
|
|
let mut finalized_head = self.finalized_head.write();
|
|
|
|
finalized_head.update(
|
|
|
|
new_beacon_block,
|
|
|
|
new_beacon_block_root,
|
|
|
|
new_beacon_state,
|
|
|
|
new_beacon_state_root,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a read-lock guarded `CheckPoint` struct for reading the justified head (as chosen,
|
|
|
|
/// indirectly, by the fork-choice rule).
|
|
|
|
pub fn finalized_head(&self) -> RwLockReadGuard<CheckPoint> {
|
|
|
|
self.finalized_head.read()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the validator index (if any) for the given public key.
|
|
|
|
///
|
|
|
|
/// Information is retrieved from the present `beacon_state.validator_registry`.
|
|
|
|
pub fn validator_index(&self, pubkey: &PublicKey) -> Option<usize> {
|
|
|
|
for (i, validator) in self
|
|
|
|
.head()
|
|
|
|
.beacon_state
|
|
|
|
.validator_registry
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
{
|
|
|
|
if validator.pubkey == *pubkey {
|
|
|
|
return Some(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reads the slot clock, returns `None` if the slot is unavailable.
|
|
|
|
///
|
|
|
|
/// The slot might be unavailable due to an error with the system clock, or if the present time
|
|
|
|
/// is before genesis (i.e., a negative slot).
|
|
|
|
///
|
|
|
|
/// This is distinct to `present_slot`, which simply reads the latest state. If a
|
|
|
|
/// call to `read_slot_clock` results in a higher slot than a call to `present_slot`,
|
|
|
|
/// `self.state` should undergo per slot processing.
|
|
|
|
pub fn read_slot_clock(&self) -> Option<Slot> {
|
|
|
|
match self.slot_clock.present_slot() {
|
|
|
|
Ok(Some(some_slot)) => Some(some_slot),
|
|
|
|
Ok(None) => None,
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-26 23:36:20 +00:00
|
|
|
/// Reads the slot clock (see `self.read_slot_clock()` and returns the number of slots since
|
|
|
|
/// genesis.
|
|
|
|
pub fn slots_since_genesis(&self) -> Option<SlotHeight> {
|
|
|
|
let now = self.read_slot_clock()?;
|
|
|
|
|
|
|
|
if now < self.spec.genesis_slot {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(SlotHeight::from(
|
|
|
|
now.as_u64() - self.spec.genesis_slot.as_u64(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Returns slot of the present state.
|
|
|
|
///
|
|
|
|
/// This is distinct to `read_slot_clock`, which reads from the actual system clock. If
|
|
|
|
/// `self.state` has not been transitioned it is possible for the system clock to be on a
|
|
|
|
/// different slot to what is returned from this call.
|
|
|
|
pub fn present_slot(&self) -> Slot {
|
|
|
|
self.state.read().slot
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the block proposer for a given slot.
|
|
|
|
///
|
|
|
|
/// Information is read from the present `beacon_state` shuffling, so only information from the
|
|
|
|
/// present and prior epoch is available.
|
2019-02-15 05:12:24 +00:00
|
|
|
pub fn block_proposer(&self, slot: Slot) -> Result<usize, BeaconStateError> {
|
2019-03-21 20:11:04 +00:00
|
|
|
self.state
|
|
|
|
.write()
|
|
|
|
.build_epoch_cache(RelativeEpoch::Current, &self.spec)?;
|
|
|
|
|
2019-03-17 07:10:20 +00:00
|
|
|
let index = self.state.read().get_beacon_proposer_index(
|
|
|
|
slot,
|
|
|
|
RelativeEpoch::Current,
|
|
|
|
&self.spec,
|
|
|
|
)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
Ok(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the attestation slot and shard for a given validator index.
|
|
|
|
///
|
|
|
|
/// Information is read from the current state, so only information from the present and prior
|
|
|
|
/// epoch is available.
|
|
|
|
pub fn validator_attestion_slot_and_shard(
|
|
|
|
&self,
|
|
|
|
validator_index: usize,
|
2019-02-15 05:12:24 +00:00
|
|
|
) -> Result<Option<(Slot, u64)>, BeaconStateError> {
|
2019-02-15 08:23:22 +00:00
|
|
|
trace!(
|
|
|
|
"BeaconChain::validator_attestion_slot_and_shard: validator_index: {}",
|
|
|
|
validator_index
|
|
|
|
);
|
2019-03-17 07:10:20 +00:00
|
|
|
if let Some(attestation_duty) = self
|
2019-02-22 05:14:16 +00:00
|
|
|
.state
|
2019-02-14 01:09:18 +00:00
|
|
|
.read()
|
2019-03-17 07:10:20 +00:00
|
|
|
.get_attestation_duties(validator_index, &self.spec)?
|
2019-02-14 01:09:18 +00:00
|
|
|
{
|
2019-03-17 07:10:20 +00:00
|
|
|
Ok(Some((attestation_duty.slot, attestation_duty.shard)))
|
2019-02-14 01:09:18 +00:00
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
2019-03-30 05:02:09 +00:00
|
|
|
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
2019-03-25 07:32:27 +00:00
|
|
|
trace!("BeaconChain::produce_attestation: shard: {}", shard);
|
2019-03-30 06:12:43 +00:00
|
|
|
let state = self.state.read();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-03-31 04:35:27 +00:00
|
|
|
let current_epoch_start_slot = self
|
|
|
|
.state
|
|
|
|
.read()
|
|
|
|
.slot
|
|
|
|
.epoch(self.spec.slots_per_epoch)
|
|
|
|
.start_slot(self.spec.slots_per_epoch);
|
|
|
|
|
|
|
|
let target_root = if state.slot == current_epoch_start_slot {
|
|
|
|
// If we're on the first slot of the state's epoch.
|
|
|
|
if self.head().beacon_block.slot == state.slot {
|
|
|
|
// If the current head block is from the current slot, use its block root.
|
|
|
|
self.head().beacon_block_root
|
|
|
|
} else {
|
|
|
|
// If the current head block is not from this slot, use the slot from the previous
|
|
|
|
// epoch.
|
2019-04-03 05:23:09 +00:00
|
|
|
*self.state.read().get_block_root(
|
2019-03-31 04:35:27 +00:00
|
|
|
current_epoch_start_slot - self.spec.slots_per_epoch,
|
|
|
|
&self.spec,
|
2019-04-03 05:23:09 +00:00
|
|
|
)?
|
2019-03-31 04:35:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If we're not on the first slot of the epoch.
|
2019-04-03 05:23:09 +00:00
|
|
|
*self
|
2019-03-31 04:35:27 +00:00
|
|
|
.state
|
2019-03-17 07:10:20 +00:00
|
|
|
.read()
|
2019-04-03 05:23:09 +00:00
|
|
|
.get_block_root(current_epoch_start_slot, &self.spec)?
|
2019-03-31 04:35:27 +00:00
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
Ok(AttestationData {
|
|
|
|
slot: self.state.read().slot,
|
|
|
|
shard,
|
|
|
|
beacon_block_root: self.head().beacon_block_root,
|
2019-03-17 07:10:20 +00:00
|
|
|
target_root,
|
2019-03-07 01:25:29 +00:00
|
|
|
crosslink_data_root: Hash256::zero(),
|
2019-03-31 01:54:42 +00:00
|
|
|
previous_crosslink: state.latest_crosslinks[shard as usize].clone(),
|
2019-03-30 06:12:43 +00:00
|
|
|
source_epoch: state.current_justified_epoch,
|
|
|
|
source_root: state.current_justified_root,
|
2019-02-14 01:09:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-29 07:40:50 +00:00
|
|
|
/// Accept a new attestation from the network.
|
|
|
|
///
|
|
|
|
/// If valid, the attestation is added to the `op_pool` and aggregated with another attestation
|
|
|
|
/// if possible.
|
2019-03-29 07:54:01 +00:00
|
|
|
pub fn process_attestation(
|
|
|
|
&self,
|
|
|
|
attestation: Attestation,
|
|
|
|
) -> Result<(), AttestationValidationError> {
|
|
|
|
self.op_pool
|
|
|
|
.insert_attestation(attestation, &*self.state.read(), &self.spec)
|
2019-03-29 07:40:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 00:54:51 +00:00
|
|
|
/// Accept some deposit and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_deposit(
|
2019-03-29 07:54:01 +00:00
|
|
|
&self,
|
|
|
|
deposit: Deposit,
|
|
|
|
) -> Result<DepositInsertStatus, DepositValidationError> {
|
|
|
|
self.op_pool
|
|
|
|
.insert_deposit(deposit, &*self.state.read(), &self.spec)
|
2019-03-01 05:54:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:20:59 +00:00
|
|
|
/// Accept some exit and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_voluntary_exit(&self, exit: VoluntaryExit) -> Result<(), ExitValidationError> {
|
2019-03-29 07:54:01 +00:00
|
|
|
self.op_pool
|
|
|
|
.insert_voluntary_exit(exit, &*self.state.read(), &self.spec)
|
2019-03-04 01:20:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 06:23:11 +00:00
|
|
|
/// Accept some transfer and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_transfer(&self, transfer: Transfer) -> Result<(), TransferValidationError> {
|
2019-03-29 07:54:01 +00:00
|
|
|
self.op_pool
|
|
|
|
.insert_transfer(transfer, &*self.state.read(), &self.spec)
|
2019-03-07 06:23:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 00:54:51 +00:00
|
|
|
/// Accept some proposer slashing and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_proposer_slashing(
|
2019-03-29 07:54:01 +00:00
|
|
|
&self,
|
|
|
|
proposer_slashing: ProposerSlashing,
|
|
|
|
) -> Result<(), ProposerSlashingValidationError> {
|
2019-03-30 01:26:25 +00:00
|
|
|
self.op_pool
|
|
|
|
.insert_proposer_slashing(proposer_slashing, &*self.state.read(), &self.spec)
|
2019-03-02 00:23:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 00:54:51 +00:00
|
|
|
/// Accept some attester slashing and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_attester_slashing(
|
2019-03-29 07:54:01 +00:00
|
|
|
&self,
|
|
|
|
attester_slashing: AttesterSlashing,
|
|
|
|
) -> Result<(), AttesterSlashingValidationError> {
|
2019-03-30 01:26:25 +00:00
|
|
|
self.op_pool
|
|
|
|
.insert_attester_slashing(attester_slashing, &*self.state.read(), &self.spec)
|
2019-03-02 00:23:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// 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(&self, block: BeaconBlock) -> Result<BlockProcessingOutcome, Error> {
|
2019-03-17 07:10:20 +00:00
|
|
|
debug!("Processing block with slot {}...", block.slot);
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-03-19 23:51:53 +00:00
|
|
|
let block_root = block.block_header().canonical_root();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
let present_slot = self.present_slot();
|
|
|
|
|
|
|
|
if block.slot > present_slot {
|
|
|
|
return Ok(BlockProcessingOutcome::InvalidBlock(
|
2019-03-24 05:35:07 +00:00
|
|
|
InvalidBlock::FutureSlot {
|
|
|
|
present_slot,
|
|
|
|
block_slot: block.slot,
|
|
|
|
},
|
2019-02-14 01:09:18 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the blocks parent block from the database, returning invalid if that block is not
|
|
|
|
// found.
|
2019-03-17 07:10:20 +00:00
|
|
|
let parent_block_root = block.previous_block_root;
|
|
|
|
let parent_block = match self.block_store.get_deserialized(&parent_block_root)? {
|
|
|
|
Some(previous_block_root) => previous_block_root,
|
2019-02-14 01:09:18 +00:00
|
|
|
None => {
|
|
|
|
return Ok(BlockProcessingOutcome::InvalidBlock(
|
|
|
|
InvalidBlock::ParentUnknown,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load the parent blocks state from the database, returning an error if it is not found.
|
|
|
|
// It is an error because if know the parent block we should also know the parent state.
|
2019-03-17 07:10:20 +00:00
|
|
|
let parent_state_root = parent_block.state_root;
|
2019-02-14 01:09:18 +00:00
|
|
|
let parent_state = self
|
|
|
|
.state_store
|
2019-03-17 07:10:20 +00:00
|
|
|
.get_deserialized(&parent_state_root)?
|
|
|
|
.ok_or_else(|| Error::DBInconsistent(format!("Missing state {}", parent_state_root)))?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
// TODO: check the block proposer signature BEFORE doing a state transition. This will
|
|
|
|
// significantly lower exposure surface to DoS attacks.
|
|
|
|
|
2019-03-23 07:48:09 +00:00
|
|
|
// Transition the parent state to the block slot.
|
2019-02-14 01:09:18 +00:00
|
|
|
let mut state = parent_state;
|
2019-03-19 23:51:53 +00:00
|
|
|
let previous_block_header = parent_block.block_header();
|
2019-03-23 07:48:09 +00:00
|
|
|
for _ in state.slot.as_u64()..block.slot.as_u64() {
|
2019-03-18 05:53:59 +00:00
|
|
|
if let Err(e) = per_slot_processing(&mut state, &previous_block_header, &self.spec) {
|
2019-02-14 01:09:18 +00:00
|
|
|
return Ok(BlockProcessingOutcome::InvalidBlock(
|
|
|
|
InvalidBlock::SlotProcessingError(e),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the received block to its parent state (which has been transitioned into this
|
|
|
|
// slot).
|
2019-03-07 01:25:29 +00:00
|
|
|
if let Err(e) = per_block_processing(&mut state, &block, &self.spec) {
|
2019-02-14 01:09:18 +00:00
|
|
|
return Ok(BlockProcessingOutcome::InvalidBlock(
|
|
|
|
InvalidBlock::PerBlockProcessingError(e),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
let state_root = state.canonical_root();
|
|
|
|
|
|
|
|
if block.state_root != state_root {
|
|
|
|
return Ok(BlockProcessingOutcome::InvalidBlock(
|
|
|
|
InvalidBlock::StateRootMismatch,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the block and state.
|
|
|
|
self.block_store.put(&block_root, &ssz_encode(&block)[..])?;
|
|
|
|
self.state_store.put(&state_root, &ssz_encode(&state)[..])?;
|
|
|
|
|
|
|
|
// run the fork_choice add_block logic
|
2019-02-18 06:49:05 +00:00
|
|
|
self.fork_choice
|
|
|
|
.write()
|
|
|
|
.add_block(&block, &block_root, &self.spec)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
// 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; fork_choice should be
|
|
|
|
// run instead.
|
|
|
|
if self.head().beacon_block_root == parent_block_root {
|
2019-02-24 05:52:12 +00:00
|
|
|
self.update_canonical_head(block.clone(), block_root, state.clone(), state_root);
|
2019-03-24 05:35:07 +00:00
|
|
|
|
|
|
|
// Update the canonical `BeaconState`.
|
|
|
|
self.update_state(state)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(BlockProcessingOutcome::ValidBlock(ValidBlock::Processed))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Produce a new block at the present slot.
|
|
|
|
///
|
|
|
|
/// The produced block will not be inherently 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.
|
2019-03-07 01:53:15 +00:00
|
|
|
pub fn produce_block(
|
|
|
|
&self,
|
|
|
|
randao_reveal: Signature,
|
|
|
|
) -> Result<(BeaconBlock, BeaconState), BlockProductionError> {
|
2019-02-14 01:09:18 +00:00
|
|
|
debug!("Producing block at slot {}...", self.state.read().slot);
|
|
|
|
|
|
|
|
let mut state = self.state.read().clone();
|
|
|
|
|
2019-03-21 20:11:04 +00:00
|
|
|
state.build_epoch_cache(RelativeEpoch::Current, &self.spec)?;
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
trace!("Finding attestations for new block...");
|
|
|
|
|
2019-03-17 07:10:20 +00:00
|
|
|
let previous_block_root = *state
|
2019-03-18 05:53:59 +00:00
|
|
|
.get_block_root(state.slot - 1, &self.spec)
|
2019-03-17 07:10:20 +00:00
|
|
|
.map_err(|_| BlockProductionError::UnableToGetBlockRootFromState)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-03-30 01:26:25 +00:00
|
|
|
let (proposer_slashings, attester_slashings) =
|
|
|
|
self.op_pool.get_slashings(&*self.state.read(), &self.spec);
|
2019-03-29 07:30:03 +00:00
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
let mut block = BeaconBlock {
|
|
|
|
slot: state.slot,
|
2019-03-17 07:10:20 +00:00
|
|
|
previous_block_root,
|
2019-02-14 01:09:18 +00:00
|
|
|
state_root: Hash256::zero(), // Updated after the state is calculated.
|
|
|
|
signature: self.spec.empty_signature.clone(), // To be completed by a validator.
|
|
|
|
body: BeaconBlockBody {
|
2019-03-17 07:10:20 +00:00
|
|
|
randao_reveal,
|
|
|
|
eth1_data: Eth1Data {
|
|
|
|
// TODO: replace with real data
|
|
|
|
deposit_root: Hash256::zero(),
|
|
|
|
block_hash: Hash256::zero(),
|
|
|
|
},
|
2019-03-29 07:30:03 +00:00
|
|
|
proposer_slashings,
|
|
|
|
attester_slashings,
|
2019-03-30 01:26:25 +00:00
|
|
|
attestations: self
|
2019-03-29 07:30:03 +00:00
|
|
|
.op_pool
|
2019-03-30 01:26:25 +00:00
|
|
|
.get_attestations(&*self.state.read(), &self.spec),
|
|
|
|
deposits: self.op_pool.get_deposits(&*self.state.read(), &self.spec),
|
2019-03-29 07:30:03 +00:00
|
|
|
voluntary_exits: self
|
|
|
|
.op_pool
|
|
|
|
.get_voluntary_exits(&*self.state.read(), &self.spec),
|
2019-03-30 01:26:25 +00:00
|
|
|
transfers: self.op_pool.get_transfers(&*self.state.read(), &self.spec),
|
2019-02-14 01:09:18 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-03-30 06:13:23 +00:00
|
|
|
debug!(
|
|
|
|
"Produced block with {} attestations, updating state.",
|
|
|
|
block.body.attestations.len()
|
|
|
|
);
|
2019-02-16 00:04:12 +00:00
|
|
|
|
2019-03-07 01:53:15 +00:00
|
|
|
per_block_processing_without_verifying_block_signature(&mut state, &block, &self.spec)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
let state_root = state.canonical_root();
|
|
|
|
|
|
|
|
block.state_root = state_root;
|
|
|
|
|
2019-03-07 01:53:15 +00:00
|
|
|
Ok((block, state))
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Left this as is, modify later
|
|
|
|
pub fn fork_choice(&self) -> Result<(), Error> {
|
|
|
|
let present_head = self.finalized_head().beacon_block_root;
|
|
|
|
|
2019-02-18 06:49:05 +00:00
|
|
|
let new_head = self
|
|
|
|
.fork_choice
|
|
|
|
.write()
|
|
|
|
.find_head(&present_head, &self.spec)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
if new_head != present_head {
|
|
|
|
let block = self
|
|
|
|
.block_store
|
|
|
|
.get_deserialized(&new_head)?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconBlock(new_head))?;
|
|
|
|
let block_root = block.canonical_root();
|
|
|
|
|
|
|
|
let state = self
|
|
|
|
.state_store
|
|
|
|
.get_deserialized(&block.state_root)?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconState(block.state_root))?;
|
|
|
|
let state_root = state.canonical_root();
|
|
|
|
|
2019-03-24 05:35:07 +00:00
|
|
|
self.update_canonical_head(block, block_root, state.clone(), state_root);
|
|
|
|
|
|
|
|
// Update the canonical `BeaconState`.
|
|
|
|
self.update_state(state)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-03-18 05:53:59 +00:00
|
|
|
|
2019-03-29 08:09:01 +00:00
|
|
|
/// Returns `true` if the given block root has not been processed.
|
|
|
|
pub fn is_new_block_root(&self, beacon_block_root: &Hash256) -> Result<bool, Error> {
|
|
|
|
Ok(!self.block_store.exists(beacon_block_root)?)
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:53:59 +00:00
|
|
|
/// Dumps the entire canonical chain, from the head to genesis to a vector for analysis.
|
|
|
|
///
|
|
|
|
/// This could be a very expensive operation and should only be done in testing/analysis
|
|
|
|
/// activities.
|
|
|
|
pub fn chain_dump(&self) -> Result<Vec<CheckPoint>, Error> {
|
|
|
|
let mut dump = vec![];
|
|
|
|
|
|
|
|
let mut last_slot = CheckPoint {
|
|
|
|
beacon_block: self.head().beacon_block.clone(),
|
|
|
|
beacon_block_root: self.head().beacon_block_root,
|
|
|
|
beacon_state: self.head().beacon_state.clone(),
|
|
|
|
beacon_state_root: self.head().beacon_state_root,
|
|
|
|
};
|
|
|
|
|
|
|
|
dump.push(last_slot.clone());
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let beacon_block_root = last_slot.beacon_block.previous_block_root;
|
|
|
|
|
|
|
|
if beacon_block_root == self.spec.zero_hash {
|
|
|
|
break; // Genesis has been reached.
|
|
|
|
}
|
|
|
|
|
|
|
|
let beacon_block = self
|
|
|
|
.block_store
|
|
|
|
.get_deserialized(&beacon_block_root)?
|
|
|
|
.ok_or_else(|| {
|
|
|
|
Error::DBInconsistent(format!("Missing block {}", beacon_block_root))
|
|
|
|
})?;
|
|
|
|
let beacon_state_root = beacon_block.state_root;
|
|
|
|
let beacon_state = self
|
|
|
|
.state_store
|
|
|
|
.get_deserialized(&beacon_state_root)?
|
|
|
|
.ok_or_else(|| {
|
|
|
|
Error::DBInconsistent(format!("Missing state {}", beacon_state_root))
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let slot = CheckPoint {
|
|
|
|
beacon_block,
|
|
|
|
beacon_block_root,
|
|
|
|
beacon_state,
|
|
|
|
beacon_state_root,
|
|
|
|
};
|
|
|
|
|
|
|
|
dump.push(slot.clone());
|
|
|
|
last_slot = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump.reverse();
|
|
|
|
|
|
|
|
Ok(dump)
|
|
|
|
}
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<DBError> for Error {
|
|
|
|
fn from(e: DBError) -> Error {
|
|
|
|
Error::DBError(e.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ForkChoiceError> for Error {
|
|
|
|
fn from(e: ForkChoiceError) -> Error {
|
|
|
|
Error::ForkChoiceError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 05:12:24 +00:00
|
|
|
impl From<BeaconStateError> for Error {
|
|
|
|
fn from(e: BeaconStateError) -> Error {
|
|
|
|
Error::BeaconStateError(e)
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
}
|