[][src]Struct types::beacon_state::BeaconState

pub struct BeaconState<T> where
    T: EthSpec
{ pub genesis_time: u64, pub slot: Slot, pub fork: Fork, pub latest_block_header: BeaconBlockHeader, pub block_roots: FixedVector<Hash256, T::SlotsPerHistoricalRoot>, pub state_roots: FixedVector<Hash256, T::SlotsPerHistoricalRoot>, pub historical_roots: VariableList<Hash256, T::HistoricalRootsLimit>, pub eth1_data: Eth1Data, pub eth1_data_votes: VariableList<Eth1Data, T::SlotsPerEth1VotingPeriod>, pub eth1_deposit_index: u64, pub validators: VariableList<Validator, T::ValidatorRegistryLimit>, pub balances: VariableList<u64, T::ValidatorRegistryLimit>, pub start_shard: u64, pub randao_mixes: FixedVector<Hash256, T::EpochsPerHistoricalVector>, pub active_index_roots: FixedVector<Hash256, T::EpochsPerHistoricalVector>, pub compact_committees_roots: FixedVector<Hash256, T::EpochsPerHistoricalVector>, pub slashings: FixedVector<u64, T::EpochsPerSlashingsVector>, pub previous_epoch_attestations: VariableList<PendingAttestation<T>, T::MaxPendingAttestations>, pub current_epoch_attestations: VariableList<PendingAttestation<T>, T::MaxPendingAttestations>, pub previous_crosslinks: FixedVector<Crosslink, T::ShardCount>, pub current_crosslinks: FixedVector<Crosslink, T::ShardCount>, pub justification_bits: BitVector<T::JustificationBitsLength>, pub previous_justified_checkpoint: Checkpoint, pub current_justified_checkpoint: Checkpoint, pub finalized_checkpoint: Checkpoint, pub committee_caches: [CommitteeCache; 3], pub pubkey_cache: PubkeyCache, pub exit_cache: ExitCache, pub tree_hash_cache: BeaconTreeHashCache, }

The state of the BeaconChain at some slot.

Spec v0.8.0

Fields

genesis_time: u64slot: Slotfork: Forklatest_block_header: BeaconBlockHeaderblock_roots: FixedVector<Hash256, T::SlotsPerHistoricalRoot>state_roots: FixedVector<Hash256, T::SlotsPerHistoricalRoot>historical_roots: VariableList<Hash256, T::HistoricalRootsLimit>eth1_data: Eth1Dataeth1_data_votes: VariableList<Eth1Data, T::SlotsPerEth1VotingPeriod>eth1_deposit_index: u64validators: VariableList<Validator, T::ValidatorRegistryLimit>balances: VariableList<u64, T::ValidatorRegistryLimit>start_shard: u64randao_mixes: FixedVector<Hash256, T::EpochsPerHistoricalVector>active_index_roots: FixedVector<Hash256, T::EpochsPerHistoricalVector>compact_committees_roots: FixedVector<Hash256, T::EpochsPerHistoricalVector>slashings: FixedVector<u64, T::EpochsPerSlashingsVector>previous_epoch_attestations: VariableList<PendingAttestation<T>, T::MaxPendingAttestations>current_epoch_attestations: VariableList<PendingAttestation<T>, T::MaxPendingAttestations>previous_crosslinks: FixedVector<Crosslink, T::ShardCount>current_crosslinks: FixedVector<Crosslink, T::ShardCount>justification_bits: BitVector<T::JustificationBitsLength>previous_justified_checkpoint: Checkpointcurrent_justified_checkpoint: Checkpointfinalized_checkpoint: Checkpointcommittee_caches: [CommitteeCache; 3]pubkey_cache: PubkeyCacheexit_cache: ExitCachetree_hash_cache: BeaconTreeHashCache

Methods

impl<T: EthSpec> BeaconState<T>[src]

pub fn new(genesis_time: u64, eth1_data: Eth1Data, spec: &ChainSpec) -> Self[src]

Create a new BeaconState suitable for genesis.

Not a complete genesis state, see initialize_beacon_state_from_eth1.

Spec v0.8.0

pub fn canonical_root(&self) -> Hash256[src]

Returns the tree_hash_root of the state.

Spec v0.8.1

pub fn historical_batch(&self) -> HistoricalBatch<T>[src]

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

If a validator pubkey exists in the validator registry, returns Some(i), otherwise returns None.

Requires a fully up-to-date pubkey_cache, returns an error if this is not the case.

pub fn current_epoch(&self) -> Epoch[src]

The epoch corresponding to self.slot.

Spec v0.8.1

pub fn previous_epoch(&self) -> Epoch[src]

The epoch prior to self.current_epoch().

If the current epoch is the genesis epoch, the genesis_epoch is returned.

Spec v0.8.1

pub fn next_epoch(&self) -> Epoch[src]

The epoch following self.current_epoch().

Spec v0.8.1

pub fn get_committee_count(
    &self,
    relative_epoch: RelativeEpoch
) -> Result<u64, Error>
[src]

pub fn get_epoch_start_shard(
    &self,
    relative_epoch: RelativeEpoch
) -> Result<u64, Error>
[src]

pub fn get_attestation_data_slot(
    &self,
    attestation_data: &AttestationData
) -> Result<Slot, Error>
[src]

Get the slot of an attestation.

Note: Utilizes the cache and will fail if the appropriate cache is not initialized.

Spec v0.8.0

pub fn get_cached_active_validator_indices(
    &self,
    relative_epoch: RelativeEpoch
) -> Result<&[usize], Error>
[src]

Return the cached active validator indices at some epoch.

Note: the indices are shuffled (i.e., not in ascending order).

Returns an error if that epoch is not cached, or the cache is not initialized.

pub fn get_active_validator_indices(&self, epoch: Epoch) -> Vec<usize>[src]

Returns the active validator indices for the given epoch.

Does not utilize the cache, performs a full iteration over the validator registry.

Spec v0.8.1

pub fn get_shuffling(
    &self,
    relative_epoch: RelativeEpoch
) -> Result<&[usize], Error>
[src]

Return the cached active validator indices at some epoch.

Note: the indices are shuffled (i.e., not in ascending order).

Returns an error if that epoch is not cached, or the cache is not initialized.

Returns the crosslink committees for some slot.

Note: Utilizes the cache and will fail if the appropriate cache is not initialized.

Spec v0.8.1

Returns the crosslink committees for some shard in some cached epoch.

Note: Utilizes the cache and will fail if the appropriate cache is not initialized.

Spec v0.8.1

pub fn get_beacon_proposer_index(
    &self,
    slot: Slot,
    relative_epoch: RelativeEpoch,
    spec: &ChainSpec
) -> Result<usize, Error>
[src]

Returns the beacon proposer index for the slot in the given relative_epoch.

Spec v0.8.1

pub fn get_block_root(&self, slot: Slot) -> Result<&Hash256, BeaconStateError>[src]

Return the block root at a recent slot.

Spec v0.8.1

pub fn get_block_root_at_epoch(
    &self,
    epoch: Epoch
) -> Result<&Hash256, BeaconStateError>
[src]

Return the block root at a recent epoch.

Spec v0.8.1

pub fn set_block_root(
    &mut self,
    slot: Slot,
    block_root: Hash256
) -> Result<(), BeaconStateError>
[src]

Sets the block root for some given slot.

Spec v0.8.1

pub fn update_randao_mix(
    &mut self,
    epoch: Epoch,
    signature: &Signature
) -> Result<(), Error>
[src]

XOR-assigns the existing epoch randao mix with the hash of the signature.

Errors:

See Self::get_randao_mix.

Spec v0.8.0

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

Return the randao mix at a recent epoch.

Spec v0.8.1

pub fn set_randao_mix(
    &mut self,
    epoch: Epoch,
    mix: Hash256
) -> Result<(), Error>
[src]

Set the randao mix at a recent epoch.

Spec v0.8.1

pub fn get_active_index_root(
    &self,
    epoch: Epoch,
    spec: &ChainSpec
) -> Result<Hash256, Error>
[src]

Return the active_index_root at a recent epoch.

Spec v0.8.1

pub fn set_active_index_root(
    &mut self,
    epoch: Epoch,
    index_root: Hash256,
    spec: &ChainSpec
) -> Result<(), Error>
[src]

Set the active_index_root at a recent epoch.

Spec v0.8.1

pub fn fill_active_index_roots_with(&mut self, index_root: Hash256)[src]

Replace active_index_roots with clones of index_root.

Spec v0.8.0

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

Return the compact_committee_root at a recent epoch.

Spec v0.8.1

pub fn set_compact_committee_root(
    &mut self,
    epoch: Epoch,
    index_root: Hash256
) -> Result<(), Error>
[src]

Set the compact_committee_root at a recent epoch.

Spec v0.8.1

pub fn fill_compact_committees_roots_with(&mut self, committee_root: Hash256)[src]

Replace compact_committees_roots with clones of committee_root.

Spec v0.8.0

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

Gets the state root for some slot.

Spec v0.8.1

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

Gets the oldest (earliest slot) state root.

Spec v0.8.1

pub fn set_state_root(
    &mut self,
    slot: Slot,
    state_root: Hash256
) -> Result<(), Error>
[src]

Sets the latest state root for slot.

Spec v0.8.1

Important traits for &'_ mut [u8]
pub fn get_all_slashings(&self) -> &[u64][src]

Get a reference to the entire slashings vector.

Spec v0.8.0

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

Get the total slashed balances for some epoch.

Spec v0.8.1

pub fn set_slashings(&mut self, epoch: Epoch, value: u64) -> Result<(), Error>[src]

Set the total slashed balances for some epoch.

Spec v0.8.1

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

Get the attestations from the current or previous epoch.

Spec v0.8.1

Get the current crosslink for a shard.

Spec v0.8.1

Get the previous crosslink for a shard.

Spec v0.8.1

pub fn get_seed(&self, epoch: Epoch, spec: &ChainSpec) -> Result<Hash256, Error>[src]

Generate a seed for the given epoch.

Spec v0.8.0

pub fn get_effective_balance(
    &self,
    validator_index: usize,
    _spec: &ChainSpec
) -> Result<u64, Error>
[src]

Return the effective balance (also known as "balance at stake") for a validator with the given index.

Spec v0.8.1

pub fn compute_activation_exit_epoch(
    &self,
    epoch: Epoch,
    spec: &ChainSpec
) -> Epoch
[src]

Return the epoch at which an activation or exit triggered in epoch takes effect.

Spec v0.8.1

pub fn get_churn_limit(&self, spec: &ChainSpec) -> Result<u64, Error>[src]

Return the churn limit for the current epoch (number of validators who can leave per epoch).

Uses the epoch cache, and will error if it isn't initialized.

Spec v0.8.1

pub fn get_attestation_duties(
    &self,
    validator_index: usize,
    relative_epoch: RelativeEpoch
) -> Result<Option<AttestationDuty>, Error>
[src]

Returns the slot, shard and committee_index for which a validator must produce an attestation.

Note: Utilizes the cache and will fail if the appropriate cache is not initialized.

Spec v0.8.1

pub fn get_total_balance(
    &self,
    validator_indices: &[usize],
    spec: &ChainSpec
) -> Result<u64, Error>
[src]

Return the combined effective balance of an array of validators.

Spec v0.8.1

pub fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), Error>[src]

Build all the caches, if they need to be built.

pub fn drop_all_caches(&mut self)[src]

Drop all caches on the state.

pub fn build_committee_cache(
    &mut self,
    relative_epoch: RelativeEpoch,
    spec: &ChainSpec
) -> Result<(), Error>
[src]

Build an epoch cache, unless it is has already been built.

pub fn force_build_committee_cache(
    &mut self,
    relative_epoch: RelativeEpoch,
    spec: &ChainSpec
) -> Result<(), Error>
[src]

Always builds the previous epoch cache, even if it is already initialized.

pub fn advance_caches(&mut self)[src]

Advances the cache for this state into the next epoch.

This should be used if the slot of this state is advanced beyond an epoch boundary.

Note: whilst this function will preserve already-built caches, it will not build any.

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

Updates the pubkey cache, if required.

Adds all pubkeys from the validators which are not already in the cache. Will never re-add a pubkey.

pub fn drop_pubkey_cache(&mut self)[src]

Completely drops the pubkey_cache, replacing it with a new, empty cache.

pub fn initialize_tree_hash_cache(&mut self)[src]

Initialize but don't fill the tree hash cache, if it isn't already initialized.

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

Build and update the tree hash cache if it isn't already initialized.

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

Build the tree hash cache, with blatant disregard for any existing cache.

pub fn update_tree_hash_cache(&mut self) -> Result<Hash256, Error>[src]

Compute the tree hash root of the state using the tree hash cache.

Initialize the tree hash cache if it isn't already initialized.

pub fn drop_tree_hash_cache(&mut self)[src]

Completely drops the tree hash cache, replacing it with a new, empty cache.

Trait Implementations

impl<T> TestRandom for BeaconState<T> where
    T: EthSpec
[src]

impl<T: Clone> Clone for BeaconState<T> where
    T: EthSpec,
    T::SlotsPerHistoricalRoot: Clone,
    T::SlotsPerHistoricalRoot: Clone,
    T::HistoricalRootsLimit: Clone,
    T::SlotsPerEth1VotingPeriod: Clone,
    T::ValidatorRegistryLimit: Clone,
    T::ValidatorRegistryLimit: Clone,
    T::EpochsPerHistoricalVector: Clone,
    T::EpochsPerHistoricalVector: Clone,
    T::EpochsPerHistoricalVector: Clone,
    T::EpochsPerSlashingsVector: Clone,
    T::MaxPendingAttestations: Clone,
    T::MaxPendingAttestations: Clone,
    T::ShardCount: Clone,
    T::ShardCount: Clone,
    T::JustificationBitsLength: Clone
[src]

impl<T: PartialEq> PartialEq<BeaconState<T>> for BeaconState<T> where
    T: EthSpec,
    T::SlotsPerHistoricalRoot: PartialEq,
    T::SlotsPerHistoricalRoot: PartialEq,
    T::HistoricalRootsLimit: PartialEq,
    T::SlotsPerEth1VotingPeriod: PartialEq,
    T::ValidatorRegistryLimit: PartialEq,
    T::ValidatorRegistryLimit: PartialEq,
    T::EpochsPerHistoricalVector: PartialEq,
    T::EpochsPerHistoricalVector: PartialEq,
    T::EpochsPerHistoricalVector: PartialEq,
    T::EpochsPerSlashingsVector: PartialEq,
    T::MaxPendingAttestations: PartialEq,
    T::MaxPendingAttestations: PartialEq,
    T::ShardCount: PartialEq,
    T::ShardCount: PartialEq,
    T::JustificationBitsLength: PartialEq
[src]

impl<T: Debug> Debug for BeaconState<T> where
    T: EthSpec,
    T::SlotsPerHistoricalRoot: Debug,
    T::SlotsPerHistoricalRoot: Debug,
    T::HistoricalRootsLimit: Debug,
    T::SlotsPerEth1VotingPeriod: Debug,
    T::ValidatorRegistryLimit: Debug,
    T::ValidatorRegistryLimit: Debug,
    T::EpochsPerHistoricalVector: Debug,
    T::EpochsPerHistoricalVector: Debug,
    T::EpochsPerHistoricalVector: Debug,
    T::EpochsPerSlashingsVector: Debug,
    T::MaxPendingAttestations: Debug,
    T::MaxPendingAttestations: Debug,
    T::ShardCount: Debug,
    T::ShardCount: Debug,
    T::JustificationBitsLength: Debug
[src]

impl<T> TreeHash for BeaconState<T> where
    T: EthSpec
[src]

impl<T> Serialize for BeaconState<T> where
    T: EthSpec,
    T: EthSpec
[src]

impl<'de, T> Deserialize<'de> for BeaconState<T> where
    T: EthSpec,
    T: EthSpec
[src]

impl<T> Decode for BeaconState<T> where
    T: EthSpec
[src]

impl<T> Encode for BeaconState<T> where
    T: EthSpec
[src]

impl<T> CachedTreeHash<BeaconTreeHashCache> for BeaconState<T> where
    T: EthSpec
[src]

impl<T> CompareFields for BeaconState<T> where
    T: EthSpec
[src]

Auto Trait Implementations

impl<T> Send for BeaconState<T> where
    <T as EthSpec>::EpochsPerHistoricalVector: Send,
    <T as EthSpec>::EpochsPerSlashingsVector: Send,
    <T as EthSpec>::HistoricalRootsLimit: Send,
    <T as EthSpec>::JustificationBitsLength: Send,
    <T as EthSpec>::MaxPendingAttestations: Send,
    <T as EthSpec>::MaxValidatorsPerCommittee: Send,
    <T as EthSpec>::ShardCount: Send,
    <T as EthSpec>::SlotsPerEth1VotingPeriod: Send,
    <T as EthSpec>::SlotsPerHistoricalRoot: Send,
    <T as EthSpec>::ValidatorRegistryLimit: Send

impl<T> Unpin for BeaconState<T> where
    <T as EthSpec>::EpochsPerHistoricalVector: Unpin,
    <T as EthSpec>::EpochsPerSlashingsVector: Unpin,
    <T as EthSpec>::HistoricalRootsLimit: Unpin,
    <T as EthSpec>::JustificationBitsLength: Unpin,
    <T as EthSpec>::MaxPendingAttestations: Unpin,
    <T as EthSpec>::MaxValidatorsPerCommittee: Unpin,
    <T as EthSpec>::ShardCount: Unpin,
    <T as EthSpec>::SlotsPerEth1VotingPeriod: Unpin,
    <T as EthSpec>::SlotsPerHistoricalRoot: Unpin,
    <T as EthSpec>::ValidatorRegistryLimit: Unpin

impl<T> Sync for BeaconState<T> where
    <T as EthSpec>::EpochsPerHistoricalVector: Sync,
    <T as EthSpec>::EpochsPerSlashingsVector: Sync,
    <T as EthSpec>::HistoricalRootsLimit: Sync,
    <T as EthSpec>::JustificationBitsLength: Sync,
    <T as EthSpec>::MaxPendingAttestations: Sync,
    <T as EthSpec>::MaxValidatorsPerCommittee: Sync,
    <T as EthSpec>::ShardCount: Sync,
    <T as EthSpec>::SlotsPerEth1VotingPeriod: Sync,
    <T as EthSpec>::SlotsPerHistoricalRoot: Sync,
    <T as EthSpec>::ValidatorRegistryLimit: Sync

impl<T> UnwindSafe for BeaconState<T> where
    <T as EthSpec>::EpochsPerHistoricalVector: UnwindSafe,
    <T as EthSpec>::EpochsPerSlashingsVector: UnwindSafe,
    <T as EthSpec>::HistoricalRootsLimit: UnwindSafe,
    <T as EthSpec>::JustificationBitsLength: UnwindSafe,
    <T as EthSpec>::MaxPendingAttestations: UnwindSafe,
    <T as EthSpec>::MaxValidatorsPerCommittee: UnwindSafe,
    <T as EthSpec>::ShardCount: UnwindSafe,
    <T as EthSpec>::SlotsPerEth1VotingPeriod: UnwindSafe,
    <T as EthSpec>::SlotsPerHistoricalRoot: UnwindSafe,
    <T as EthSpec>::ValidatorRegistryLimit: UnwindSafe

impl<T> RefUnwindSafe for BeaconState<T> where
    <T as EthSpec>::EpochsPerHistoricalVector: RefUnwindSafe,
    <T as EthSpec>::EpochsPerSlashingsVector: RefUnwindSafe,
    <T as EthSpec>::HistoricalRootsLimit: RefUnwindSafe,
    <T as EthSpec>::JustificationBitsLength: RefUnwindSafe,
    <T as EthSpec>::MaxPendingAttestations: RefUnwindSafe,
    <T as EthSpec>::MaxValidatorsPerCommittee: RefUnwindSafe,
    <T as EthSpec>::ShardCount: RefUnwindSafe,
    <T as EthSpec>::SlotsPerEth1VotingPeriod: RefUnwindSafe,
    <T as EthSpec>::SlotsPerHistoricalRoot: RefUnwindSafe,
    <T as EthSpec>::ValidatorRegistryLimit: RefUnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[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