[][src]Struct beacon_chain::BeaconChain

pub struct BeaconChain<T: BeaconChainTypes> {
    pub spec: ChainSpec,
    pub store: Arc<T::Store>,
    pub slot_clock: T::SlotClock,
    pub op_pool: OperationPool<T::EthSpec>,
    pub eth1_chain: Option<Eth1Chain<T::Eth1Chain, T::EthSpec>>,
    pub genesis_block_root: Hash256,
    pub fork_choice: ForkChoice<T>,
    pub event_handler: T::EventHandler,
    // some fields omitted
}

Represents the "Beacon Chain" component of Ethereum 2.0. Allows import of blocks and block operations and chooses a canonical head.

Fields

spec: ChainSpecstore: Arc<T::Store>

Persistent storage for blocks, states, etc. Typically an on-disk store, such as LevelDB.

slot_clock: T::SlotClock

Reports the current slot, typically based upon the system clock.

op_pool: OperationPool<T::EthSpec>

Stores all operations (e.g., Attestation, Deposit, etc) that are candidates for inclusion in a block.

eth1_chain: Option<Eth1Chain<T::Eth1Chain, T::EthSpec>>

Provides information from the Ethereum 1 (PoW) chain.

genesis_block_root: Hash256

The root of the genesis block.

fork_choice: ForkChoice<T>

A state-machine that is updated with information from the network and chooses a canonical head block.

event_handler: T::EventHandler

A handler for events generated by the beacon chain.

Methods

impl<T: BeaconChainTypes> BeaconChain<T>[src]

pub fn persist(&self) -> Result<(), Error>[src]

Attempt to save this instance to self.store.

pub fn slot(&self) -> Result<Slot, Error>[src]

Returns the slot right now according to self.slot_clock. Returns Err 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).

pub fn epoch(&self) -> Result<Epoch, Error>[src]

Returns the epoch right now according to self.slot_clock. Returns Err if the epoch is unavailable.

The epoch might be unavailable due to an error with the system clock, or if the present time is before genesis (i.e., a negative epoch).

pub fn get_block_bodies(
    &self,
    roots: &[Hash256]
) -> Result<Vec<BeaconBlockBody<T::EthSpec>>, Error>
[src]

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_headers(
    &self,
    roots: &[Hash256]
) -> Result<Vec<BeaconBlockHeader>, Error>
[src]

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 rev_iter_block_roots(
    &self
) -> ReverseChainIterator<(Hash256, Slot), BlockRootsIterator<'a, T::EthSpec, T::Store>>
[src]

Iterates across all (block_root, slot) pairs from the head of the chain (inclusive) to the earliest reachable ancestor (may or may not be genesis).

Notes

slot always decreases by 1.

  • Skipped slots contain the root of the closest prior non-skipped slot (identical to the way they are stored in state.block_roots) .
  • Iterator returns (Hash256, Slot).
  • As this iterator starts at the head of the chain (viz., the best block), the first slot returned may be earlier than the wall-clock slot.

pub fn rev_iter_state_roots(
    &self
) -> ReverseChainIterator<(Hash256, Slot), StateRootsIterator<'a, T::EthSpec, T::Store>>
[src]

Iterates across all (state_root, slot) pairs from the head of the chain (inclusive) to the earliest reachable ancestor (may or may not be genesis).

Notes

slot always decreases by 1.

  • Iterator returns (Hash256, Slot).
  • As this iterator starts at the head of the chain (viz., the best block), the first slot returned may be earlier than the wall-clock slot.

pub fn get_block(
    &self,
    block_root: &Hash256
) -> Result<Option<BeaconBlock<T::EthSpec>>, Error>
[src]

Returns the block at the given root, if any.

Errors

May return a database error.

pub fn head(&self) -> CheckPoint<T::EthSpec>[src]

Returns a Checkpoint representing the head block and state. Contains the "best block"; the head of the canonical BeaconChain.

It is important to note that the beacon_state returned may not match the present slot. It is the state as it was when the head block was received, which could be some slots prior to now.

pub fn state_at_slot(
    &self,
    slot: Slot
) -> Result<BeaconState<T::EthSpec>, Error>
[src]

Returns the BeaconState at the given slot.

Returns None when the state is not found in the database or there is an error skipping to a future state.

pub fn wall_clock_state(&self) -> Result<BeaconState<T::EthSpec>, Error>[src]

Returns the BeaconState the current slot (viz., self.slot()).

  • A reference to the head state (note: this keeps a read lock on the head, try to use sparingly).
  • The head state, but with skipped slots (for states later than the head).

Returns None when there is an error skipping to a future state or the slot clock cannot be read.

pub fn best_slot(&self) -> Slot[src]

Returns the slot of the highest block in the canonical chain.

pub fn validator_index(&self, pubkey: &PublicKey) -> Option<usize>[src]

Returns the validator index (if any) for the given public key.

Information is retrieved from the present beacon_state.validators.

pub fn root_at_slot(&self, target_slot: Slot) -> Option<Hash256>[src]

Returns the block canonical root of the current canonical chain at a given slot.

Returns None if a block doesn't exist at the slot.

pub fn slots_since_genesis(&self) -> Option<SlotHeight>[src]

Reads the slot clock (see self.read_slot_clock() and returns the number of slots since genesis.

pub fn block_proposer(&self, slot: Slot) -> Result<usize, Error>[src]

Returns the block proposer for a given slot.

Information is read from the present beacon_state shuffling, only information from the present epoch is available.

pub fn validator_attestation_slot_and_shard(
    &self,
    validator_index: usize,
    epoch: Epoch
) -> Result<Option<(Slot, u64)>, Error>
[src]

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 produce_attestation_data(
    &self,
    shard: u64,
    slot: Slot
) -> Result<AttestationData, Error>
[src]

Produce an AttestationData that is valid for the given slot shard.

Always attests to the canonical chain.

pub fn produce_attestation_data_for_block(
    &self,
    shard: u64,
    head_block_root: Hash256,
    head_block_slot: Slot,
    state: &BeaconState<T::EthSpec>
) -> Result<AttestationData, Error>
[src]

Produce an AttestationData that attests to the chain denoted by block_root and state.

Permits attesting to any arbitrary chain. Generally, the produce_attestation_data function should be used as it attests to the canonical chain.

pub fn process_attestation(
    &self,
    attestation: Attestation<T::EthSpec>
) -> Result<AttestationProcessingOutcome, Error>
[src]

Accept a new, potentially invalid attestation from the network.

If valid, the attestation is added to self.op_pool and self.fork_choice.

Returns an Ok(AttestationProcessingOutcome) if the chain was able to make a determination about the attestation (whether it was invalid or not). Returns an Err if there was an error during this process and no determination was able to be made.

Notes

  • Whilst the attestation is added to fork choice, the head is not updated. That must be done separately.

pub fn process_attestation_internal(
    &self,
    attestation: Attestation<T::EthSpec>
) -> Result<AttestationProcessingOutcome, Error>
[src]

pub fn process_deposit(
    &self,
    index: u64,
    deposit: Deposit
) -> Result<DepositInsertStatus, DepositValidationError>
[src]

Accept some deposit and queue it for inclusion in an appropriate block.

pub fn process_voluntary_exit(
    &self,
    exit: VoluntaryExit
) -> Result<(), ExitValidationError>
[src]

Accept some exit and queue it for inclusion in an appropriate block.

pub fn process_transfer(
    &self,
    transfer: Transfer
) -> Result<(), TransferValidationError>
[src]

Accept some transfer and queue it for inclusion in an appropriate block.

pub fn process_proposer_slashing(
    &self,
    proposer_slashing: ProposerSlashing
) -> Result<(), ProposerSlashingValidationError>
[src]

Accept some proposer slashing and queue it for inclusion in an appropriate block.

pub fn process_attester_slashing(
    &self,
    attester_slashing: AttesterSlashing<T::EthSpec>
) -> Result<(), AttesterSlashingValidationError>
[src]

Accept some attester slashing and queue it for inclusion in an appropriate block.

pub fn process_block(
    &self,
    block: BeaconBlock<T::EthSpec>
) -> Result<BlockProcessingOutcome, Error>
[src]

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 produce_block(
    &self,
    randao_reveal: Signature,
    slot: Slot
) -> Result<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError>
[src]

Produce a new block at the given 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.

pub fn produce_block_on_state(
    &self,
    state: BeaconState<T::EthSpec>,
    produce_at_slot: Slot,
    randao_reveal: Signature
) -> Result<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError>
[src]

Produce a block for some slot upon the given state.

Typically the self.produce_block() function should be used, instead of calling this function directly. This function is useful for purposefully creating forks or blocks at non-current slots.

The given state will be advanced to the given produce_at_slot, then a block will be produced at that slot height.

pub fn fork_choice(&self) -> Result<(), Error>[src]

Execute the fork choice algorithm and enthrone the result as the canonical head.

pub fn is_new_block_root(
    &self,
    beacon_block_root: &Hash256
) -> Result<bool, Error>
[src]

Returns true if the given block root has not been processed.

pub fn chain_dump(&self) -> Result<Vec<CheckPoint<T::EthSpec>>, Error>[src]

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.

Auto Trait Implementations

impl<T> Send for BeaconChain<T> where
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerHistoricalVector: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerSlashingsVector: Send,
    <T as BeaconChainTypes>::Eth1Chain: Send,
    <T as BeaconChainTypes>::EthSpec: EthSpec + Send,
    <T as BeaconChainTypes>::EventHandler: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::HistoricalRootsLimit: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::JustificationBitsLength: Send,
    <T as BeaconChainTypes>::LmdGhost: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttestations: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttesterSlashings: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxDeposits: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxPendingAttestations: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxProposerSlashings: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxTransfers: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxValidatorsPerCommittee: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxVoluntaryExits: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ShardCount: Send,
    <T as BeaconChainTypes>::SlotClock: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerEth1VotingPeriod: Send,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerHistoricalRoot: Send,
    <T as BeaconChainTypes>::Store: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ValidatorRegistryLimit: Send

impl<T> Unpin for BeaconChain<T> where
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerHistoricalVector: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerSlashingsVector: Unpin,
    <T as BeaconChainTypes>::Eth1Chain: Unpin,
    <T as BeaconChainTypes>::EthSpec: EthSpec + Unpin,
    <T as BeaconChainTypes>::EventHandler: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::HistoricalRootsLimit: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::JustificationBitsLength: Unpin,
    <T as BeaconChainTypes>::LmdGhost: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttestations: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttesterSlashings: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxDeposits: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxPendingAttestations: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxProposerSlashings: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxTransfers: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxValidatorsPerCommittee: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxVoluntaryExits: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ShardCount: Unpin,
    <T as BeaconChainTypes>::SlotClock: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerEth1VotingPeriod: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerHistoricalRoot: Unpin,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ValidatorRegistryLimit: Unpin

impl<T> Sync for BeaconChain<T> where
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerHistoricalVector: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerSlashingsVector: Send + Sync,
    <T as BeaconChainTypes>::Eth1Chain: Sync,
    <T as BeaconChainTypes>::EthSpec: EthSpec + Sync,
    <T as BeaconChainTypes>::EventHandler: Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::HistoricalRootsLimit: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::JustificationBitsLength: Send + Sync,
    <T as BeaconChainTypes>::LmdGhost: Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttestations: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttesterSlashings: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxDeposits: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxPendingAttestations: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxProposerSlashings: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxTransfers: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxValidatorsPerCommittee: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxVoluntaryExits: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ShardCount: Send + Sync,
    <T as BeaconChainTypes>::SlotClock: Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerEth1VotingPeriod: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerHistoricalRoot: Send + Sync,
    <T as BeaconChainTypes>::Store: Send + Sync,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ValidatorRegistryLimit: Send + Sync

impl<T> UnwindSafe for BeaconChain<T> where
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerHistoricalVector: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::EpochsPerSlashingsVector: UnwindSafe,
    <T as BeaconChainTypes>::Eth1Chain: UnwindSafe,
    <T as BeaconChainTypes>::EthSpec: EthSpec + UnwindSafe,
    <T as BeaconChainTypes>::EventHandler: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::HistoricalRootsLimit: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::JustificationBitsLength: UnwindSafe,
    <T as BeaconChainTypes>::LmdGhost: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttestations: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxAttesterSlashings: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxDeposits: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxPendingAttestations: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxProposerSlashings: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxTransfers: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxValidatorsPerCommittee: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::MaxVoluntaryExits: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ShardCount: UnwindSafe,
    <T as BeaconChainTypes>::SlotClock: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerEth1VotingPeriod: UnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::SlotsPerHistoricalRoot: UnwindSafe,
    <T as BeaconChainTypes>::Store: RefUnwindSafe,
    <<T as BeaconChainTypes>::EthSpec as EthSpec>::ValidatorRegistryLimit: UnwindSafe

impl<T> !RefUnwindSafe for BeaconChain<T>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

impl<T> Erased for T