mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 13:58:28 +00:00
v0.6: update all spec version comments
This commit is contained in:
@@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// Details an attestation that can be slashable.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// The data upon which an attestation is based.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Used for pairing an attestation with a proof-of-custody.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Two conflicting attestations.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
|
||||
@@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// A block of the `BeaconChain`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
@@ -36,7 +36,7 @@ pub struct BeaconBlock {
|
||||
impl BeaconBlock {
|
||||
/// Returns an empty block to be used during genesis.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn empty(spec: &ChainSpec) -> BeaconBlock {
|
||||
BeaconBlock {
|
||||
slot: spec.genesis_slot,
|
||||
@@ -63,7 +63,7 @@ impl BeaconBlock {
|
||||
|
||||
/// Returns the `tree_hash_root | update` of the block.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from_slice(&self.tree_hash_root()[..])
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl BeaconBlock {
|
||||
///
|
||||
/// Note: performs a full tree-hash of `self.body`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn block_header(&self) -> BeaconBlockHeader {
|
||||
BeaconBlockHeader {
|
||||
slot: self.slot,
|
||||
@@ -88,7 +88,7 @@ impl BeaconBlock {
|
||||
|
||||
/// Returns a "temporary" header, where the `state_root` is `spec.zero_hash`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader {
|
||||
BeaconBlockHeader {
|
||||
state_root: spec.zero_hash,
|
||||
|
||||
@@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// The body of a `BeaconChain` block, containing operations.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
|
||||
@@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// A header of a `BeaconBlock`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
@@ -36,14 +36,14 @@ pub struct BeaconBlockHeader {
|
||||
impl BeaconBlockHeader {
|
||||
/// Returns the `tree_hash_root` of the header.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from_slice(&self.signed_root()[..])
|
||||
}
|
||||
|
||||
/// Given a `body`, consumes `self` and returns a complete `BeaconBlock`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn into_block(self, body: BeaconBlockBody) -> BeaconBlock {
|
||||
BeaconBlock {
|
||||
slot: self.slot,
|
||||
|
||||
@@ -63,7 +63,7 @@ pub enum Error {
|
||||
|
||||
/// The state of the `BeaconChain` at some slot.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
@@ -157,7 +157,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
/// This does not fully build a genesis beacon state, it omits processing of initial validator
|
||||
/// deposits. To obtain a full genesis beacon state, use the `BeaconStateBuilder`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn genesis(
|
||||
genesis_time: u64,
|
||||
latest_eth1_data: Eth1Data,
|
||||
@@ -234,7 +234,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Returns the `tree_hash_root` of the state.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from_slice(&self.tree_hash_root()[..])
|
||||
}
|
||||
@@ -263,7 +263,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// The epoch corresponding to `self.slot`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn current_epoch(&self) -> Epoch {
|
||||
self.slot.epoch(T::slots_per_epoch())
|
||||
}
|
||||
@@ -272,7 +272,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// If the current epoch is the genesis epoch, the genesis_epoch is returned.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn previous_epoch(&self) -> Epoch {
|
||||
let current_epoch = self.current_epoch();
|
||||
if current_epoch > T::genesis_epoch() {
|
||||
@@ -284,7 +284,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// The epoch following `self.current_epoch()`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn next_epoch(&self) -> Epoch {
|
||||
self.current_epoch() + 1
|
||||
}
|
||||
@@ -313,7 +313,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_attestation_slot(&self, attestation_data: &AttestationData) -> Result<Slot, Error> {
|
||||
let target_relative_epoch =
|
||||
RelativeEpoch::from_epoch(self.current_epoch(), attestation_data.target_epoch)?;
|
||||
@@ -342,7 +342,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// Does not utilize the cache, performs a full iteration over the validator registry.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_active_validator_indices(&self, epoch: Epoch) -> Vec<usize> {
|
||||
get_active_validator_indices(&self.validator_registry, epoch)
|
||||
}
|
||||
@@ -362,7 +362,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_crosslink_committees_at_slot(
|
||||
&self,
|
||||
slot: Slot,
|
||||
@@ -379,7 +379,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_crosslink_committee_for_shard(
|
||||
&self,
|
||||
shard: u64,
|
||||
@@ -396,7 +396,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Returns the beacon proposer index for the `slot` in the given `relative_epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
// NOTE: be sure to test this bad boy.
|
||||
pub fn get_beacon_proposer_index(
|
||||
&self,
|
||||
@@ -433,7 +433,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Safely obtains the index for latest block roots, given some `slot`.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
fn get_latest_block_roots_index(&self, slot: Slot) -> Result<usize, Error> {
|
||||
if (slot < self.slot) && (self.slot <= slot + self.latest_block_roots.len() as u64) {
|
||||
Ok(slot.as_usize() % self.latest_block_roots.len())
|
||||
@@ -444,7 +444,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the block root at a recent `slot`.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_block_root(&self, slot: Slot) -> Result<&Hash256, BeaconStateError> {
|
||||
let i = self.get_latest_block_roots_index(slot)?;
|
||||
Ok(&self.latest_block_roots[i])
|
||||
@@ -452,7 +452,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the block root at a recent `epoch`.
|
||||
///
|
||||
/// Spec v0.6.0
|
||||
/// Spec v0.6.3
|
||||
// NOTE: the spec calls this get_block_root
|
||||
pub fn get_block_root_at_epoch(&self, epoch: Epoch) -> Result<&Hash256, BeaconStateError> {
|
||||
self.get_block_root(epoch.start_slot(T::slots_per_epoch()))
|
||||
@@ -460,7 +460,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Sets the block root for some given slot.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn set_block_root(
|
||||
&mut self,
|
||||
slot: Slot,
|
||||
@@ -473,7 +473,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Safely obtains the index for `latest_randao_mixes`
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
fn get_randao_mix_index(&self, epoch: Epoch) -> Result<usize, Error> {
|
||||
let current_epoch = self.current_epoch();
|
||||
let len = T::LatestRandaoMixesLength::to_u64();
|
||||
@@ -491,7 +491,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// See `Self::get_randao_mix`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn update_randao_mix(&mut self, epoch: Epoch, signature: &Signature) -> Result<(), Error> {
|
||||
let i = epoch.as_usize() % T::LatestRandaoMixesLength::to_usize();
|
||||
|
||||
@@ -504,7 +504,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the randao mix at a recent ``epoch``.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_randao_mix(&self, epoch: Epoch) -> Result<&Hash256, Error> {
|
||||
let i = self.get_randao_mix_index(epoch)?;
|
||||
Ok(&self.latest_randao_mixes[i])
|
||||
@@ -512,7 +512,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Set the randao mix at a recent ``epoch``.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn set_randao_mix(&mut self, epoch: Epoch, mix: Hash256) -> Result<(), Error> {
|
||||
let i = self.get_randao_mix_index(epoch)?;
|
||||
self.latest_randao_mixes[i] = mix;
|
||||
@@ -521,7 +521,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Safely obtains the index for `latest_active_index_roots`, given some `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn get_active_index_root_index(&self, epoch: Epoch, spec: &ChainSpec) -> Result<usize, Error> {
|
||||
let current_epoch = self.current_epoch();
|
||||
|
||||
@@ -537,7 +537,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the `active_index_root` at a recent `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_active_index_root(&self, epoch: Epoch, spec: &ChainSpec) -> Result<Hash256, Error> {
|
||||
let i = self.get_active_index_root_index(epoch, spec)?;
|
||||
Ok(self.latest_active_index_roots[i])
|
||||
@@ -545,7 +545,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Set the `active_index_root` at a recent `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn set_active_index_root(
|
||||
&mut self,
|
||||
epoch: Epoch,
|
||||
@@ -559,7 +559,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Replace `active_index_roots` with clones of `index_root`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn fill_active_index_roots_with(&mut self, index_root: Hash256) {
|
||||
self.latest_active_index_roots =
|
||||
vec![index_root; self.latest_active_index_roots.len()].into()
|
||||
@@ -567,7 +567,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Safely obtains the index for latest state roots, given some `slot`.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
fn get_latest_state_roots_index(&self, slot: Slot) -> Result<usize, Error> {
|
||||
if (slot < self.slot) && (self.slot <= slot + self.latest_state_roots.len() as u64) {
|
||||
Ok(slot.as_usize() % self.latest_state_roots.len())
|
||||
@@ -578,7 +578,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Gets the state root for some slot.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_state_root(&mut self, slot: Slot) -> Result<&Hash256, Error> {
|
||||
let i = self.get_latest_state_roots_index(slot)?;
|
||||
Ok(&self.latest_state_roots[i])
|
||||
@@ -586,7 +586,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Sets the latest state root for slot.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn set_state_root(&mut self, slot: Slot, state_root: Hash256) -> Result<(), Error> {
|
||||
let i = self.get_latest_state_roots_index(slot)?;
|
||||
self.latest_state_roots[i] = state_root;
|
||||
@@ -595,7 +595,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Safely obtains the index for `latest_slashed_balances`, given some `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn get_slashed_balance_index(&self, epoch: Epoch) -> Result<usize, Error> {
|
||||
let i = epoch.as_usize() % self.latest_slashed_balances.len();
|
||||
|
||||
@@ -610,7 +610,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Gets the total slashed balances for some epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_slashed_balance(&self, epoch: Epoch) -> Result<u64, Error> {
|
||||
let i = self.get_slashed_balance_index(epoch)?;
|
||||
Ok(self.latest_slashed_balances[i])
|
||||
@@ -618,7 +618,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Sets the total slashed balances for some epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn set_slashed_balance(&mut self, epoch: Epoch, balance: u64) -> Result<(), Error> {
|
||||
let i = self.get_slashed_balance_index(epoch)?;
|
||||
self.latest_slashed_balances[i] = balance;
|
||||
@@ -627,7 +627,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Get the attestations from the current or previous epoch.
|
||||
///
|
||||
/// Spec v0.6.0
|
||||
/// Spec v0.6.3
|
||||
pub fn get_matching_source_attestations(
|
||||
&self,
|
||||
epoch: Epoch,
|
||||
@@ -643,7 +643,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Get the current crosslink for a shard.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_current_crosslink(&self, shard: u64) -> Result<&Crosslink, Error> {
|
||||
self.current_crosslinks
|
||||
.get(shard as usize)
|
||||
@@ -652,7 +652,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Get the previous crosslink for a shard.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_previous_crosslink(&self, shard: u64) -> Result<&Crosslink, Error> {
|
||||
self.previous_crosslinks
|
||||
.get(shard as usize)
|
||||
@@ -661,7 +661,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Transform an attestation into the crosslink that it reinforces.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_crosslink_from_attestation_data(
|
||||
&self,
|
||||
data: &AttestationData,
|
||||
@@ -680,7 +680,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Generate a seed for the given `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn generate_seed(&self, epoch: Epoch, spec: &ChainSpec) -> Result<Hash256, Error> {
|
||||
// Bypass the safe getter for RANDAO so we can gracefully handle the scenario where `epoch
|
||||
// == 0`.
|
||||
@@ -701,7 +701,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the effective balance (also known as "balance at stake") for a validator with the given ``index``.
|
||||
///
|
||||
/// Spec v0.6.0
|
||||
/// Spec v0.6.3
|
||||
pub fn get_effective_balance(
|
||||
&self,
|
||||
validator_index: usize,
|
||||
@@ -715,7 +715,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the epoch at which an activation or exit triggered in ``epoch`` takes effect.
|
||||
///
|
||||
/// Spec v0.5.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_delayed_activation_exit_epoch(&self, epoch: Epoch, spec: &ChainSpec) -> Epoch {
|
||||
epoch + 1 + spec.activation_exit_delay
|
||||
}
|
||||
@@ -724,7 +724,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// Uses the epoch cache, and will error if it isn't initialized.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_churn_limit(&self, spec: &ChainSpec) -> Result<u64, Error> {
|
||||
Ok(std::cmp::max(
|
||||
spec.min_per_epoch_churn_limit,
|
||||
@@ -738,7 +738,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
///
|
||||
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
|
||||
///
|
||||
/// Spec v0.6.2
|
||||
/// Spec v0.6.3
|
||||
pub fn get_attestation_duties(
|
||||
&self,
|
||||
validator_index: usize,
|
||||
@@ -751,7 +751,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
|
||||
/// Return the combined effective balance of an array of validators.
|
||||
///
|
||||
/// Spec v0.6.0
|
||||
/// Spec v0.6.3
|
||||
pub fn get_total_balance(
|
||||
&self,
|
||||
validator_indices: &[usize],
|
||||
|
||||
@@ -22,7 +22,7 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq {
|
||||
|
||||
/// Return the number of committees in one epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn get_epoch_committee_count(
|
||||
active_validator_count: usize,
|
||||
target_committee_size: usize,
|
||||
@@ -60,42 +60,42 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq {
|
||||
|
||||
/// Returns the `SLOTS_PER_EPOCH` constant for this specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn slots_per_epoch() -> u64 {
|
||||
Self::SlotsPerEpoch::to_u64()
|
||||
}
|
||||
|
||||
/// Returns the `SHARD_COUNT` constant for this specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn shard_count() -> usize {
|
||||
Self::ShardCount::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `SLOTS_PER_HISTORICAL_ROOT` constant for this specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn slots_per_historical_root() -> usize {
|
||||
Self::SlotsPerHistoricalRoot::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `LATEST_RANDAO_MIXES_LENGTH` constant for this specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn latest_randao_mixes_length() -> usize {
|
||||
Self::LatestRandaoMixesLength::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `LATEST_ACTIVE_INDEX_ROOTS` constant for this specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn latest_active_index_roots() -> usize {
|
||||
Self::LatestActiveIndexRootsLength::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `LATEST_SLASHED_EXIT_LENGTH` constant for this specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn latest_slashed_exit_length() -> usize {
|
||||
Self::LatestSlashedExitLength::to_usize()
|
||||
}
|
||||
@@ -103,7 +103,7 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq {
|
||||
|
||||
/// Ethereum Foundation specifications.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct MainnetEthSpec;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pub struct CommitteeCache {
|
||||
impl CommitteeCache {
|
||||
/// Return a new, fully initialized cache.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn initialized<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
epoch: Epoch,
|
||||
@@ -128,7 +128,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `&[]` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn active_validator_indices(&self) -> &[usize] {
|
||||
&self.shuffling
|
||||
}
|
||||
@@ -137,7 +137,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `&[]` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn shuffling(&self) -> &[usize] {
|
||||
&self.shuffling
|
||||
}
|
||||
@@ -147,7 +147,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `None` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_crosslink_committee_for_shard(&self, shard: Shard) -> Option<CrosslinkCommittee> {
|
||||
if shard >= self.shard_count || self.initialized_epoch.is_none() {
|
||||
return None;
|
||||
@@ -201,7 +201,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `usize::default()` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn active_validator_count(&self) -> usize {
|
||||
self.shuffling.len()
|
||||
}
|
||||
@@ -210,7 +210,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `usize::default()` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn epoch_committee_count(&self) -> usize {
|
||||
self.committee_count
|
||||
}
|
||||
@@ -226,7 +226,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Returns `None` if `slot` is not in the initialized epoch, or if `Self` is not initialized.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_crosslink_committees_for_slot(&self, slot: Slot) -> Option<Vec<CrosslinkCommittee>> {
|
||||
let position = self
|
||||
.initialized_epoch?
|
||||
@@ -258,7 +258,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `None` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn first_committee_at_slot(&self, slot: Slot) -> Option<&[usize]> {
|
||||
self.get_crosslink_committees_for_slot(slot)?
|
||||
.first()
|
||||
@@ -267,7 +267,7 @@ impl CommitteeCache {
|
||||
|
||||
/// Returns a slice of `self.shuffling` that represents the `index`'th committee in the epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn compute_committee(&self, index: usize) -> Option<&[usize]> {
|
||||
Some(&self.shuffling[self.compute_committee_range(index)?])
|
||||
}
|
||||
@@ -276,7 +276,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// To avoid a divide-by-zero, returns `None` if `self.committee_count` is zero.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn compute_committee_range(&self, index: usize) -> Option<Range<usize>> {
|
||||
if self.committee_count == 0 {
|
||||
return None;
|
||||
@@ -295,7 +295,7 @@ impl CommitteeCache {
|
||||
///
|
||||
/// Always returns `None` for a non-initialized epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn crosslink_slot_for_shard(&self, shard: u64) -> Option<Slot> {
|
||||
let offset = (shard + self.shard_count - self.shuffling_start_shard) % self.shard_count;
|
||||
Some(
|
||||
@@ -317,7 +317,7 @@ impl CommitteeCache {
|
||||
/// Returns a list of all `validator_registry` indices where the validator is active at the given
|
||||
/// `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_active_validator_indices(validators: &[Validator], epoch: Epoch) -> Vec<usize> {
|
||||
let mut active = Vec::with_capacity(validators.len());
|
||||
|
||||
@@ -335,7 +335,7 @@ pub fn get_active_validator_indices(validators: &[Validator], epoch: Epoch) -> V
|
||||
/// Returns the count of all `validator_registry` indices where the validator is active at the given
|
||||
/// `epoch`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
fn get_active_validator_count(validators: &[Validator], epoch: Epoch) -> usize {
|
||||
validators.iter().filter(|v| v.is_active_at(epoch)).count()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use test_utils::{u8_from_hex_str, u8_to_hex_str};
|
||||
|
||||
/// Each of the BLS signature domains.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub enum Domain {
|
||||
BeaconProposer,
|
||||
Randao,
|
||||
@@ -17,7 +17,7 @@ pub enum Domain {
|
||||
|
||||
/// Holds all the "constants" for a BeaconChain.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct ChainSpec {
|
||||
@@ -115,7 +115,7 @@ pub struct ChainSpec {
|
||||
impl ChainSpec {
|
||||
/// Get the domain number that represents the fork meta and signature domain.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_domain(&self, epoch: Epoch, domain: Domain, fork: &Fork) -> u64 {
|
||||
let domain_constant = match domain {
|
||||
Domain::BeaconProposer => self.domain_beacon_proposer,
|
||||
@@ -137,7 +137,7 @@ impl ChainSpec {
|
||||
|
||||
/// Returns a `ChainSpec` compatible with the Ethereum Foundation specification.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn mainnet() -> Self {
|
||||
Self {
|
||||
/*
|
||||
|
||||
@@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Specifies the block hash for a shard at an epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// A deposit to potentially become a beacon chain validator.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
|
||||
@@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// The data supplied by the user to the deposit contract.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
@@ -35,7 +35,7 @@ pub struct DepositData {
|
||||
impl DepositData {
|
||||
/// Generate the signature for a given DepositData details.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn create_signature(
|
||||
&self,
|
||||
secret_key: &SecretKey,
|
||||
|
||||
@@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Contains data obtained from the Eth1 chain.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
|
||||
@@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Specifies a fork of the `BeaconChain`, to prevent replay attacks.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
@@ -35,7 +35,7 @@ pub struct Fork {
|
||||
impl Fork {
|
||||
/// Initialize the `Fork` from the genesis parameters in the `spec`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn genesis(genesis_epoch: Epoch) -> Self {
|
||||
Self {
|
||||
previous_version: [0; 4],
|
||||
@@ -46,7 +46,7 @@ impl Fork {
|
||||
|
||||
/// Return the fork version of the given ``epoch``.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn get_fork_version(&self, epoch: Epoch) -> [u8; 4] {
|
||||
if epoch < self.epoch {
|
||||
return self.previous_version;
|
||||
|
||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Historical block and state roots.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
///
|
||||
/// To be included in an `AttesterSlashing`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
@@ -35,14 +35,14 @@ pub struct IndexedAttestation {
|
||||
impl IndexedAttestation {
|
||||
/// Check if ``attestation_data_1`` and ``attestation_data_2`` have the same target.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn is_double_vote(&self, other: &IndexedAttestation) -> bool {
|
||||
self.data.target_epoch == other.data.target_epoch && self.data != other.data
|
||||
}
|
||||
|
||||
/// Check if ``attestation_data_1`` surrounds ``attestation_data_2``.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn is_surround_vote(&self, other: &IndexedAttestation) -> bool {
|
||||
self.data.source_epoch < other.data.source_epoch
|
||||
&& other.data.target_epoch < self.data.target_epoch
|
||||
|
||||
@@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// An attestation that has been included in the state but not yet fully processed.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Two conflicting proposals from the same proposer (validator).
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
|
||||
@@ -9,7 +9,7 @@ pub enum Error {
|
||||
/// Defines the epochs relative to some epoch. Most useful when referring to the committees prior
|
||||
/// to and following some epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum RelativeEpoch {
|
||||
/// The prior epoch.
|
||||
@@ -23,7 +23,7 @@ pub enum RelativeEpoch {
|
||||
impl RelativeEpoch {
|
||||
/// Returns the `epoch` that `self` refers to, with respect to the `base` epoch.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn into_epoch(self, base: Epoch) -> Epoch {
|
||||
match self {
|
||||
// Due to saturating nature of epoch, check for current first.
|
||||
@@ -40,7 +40,7 @@ impl RelativeEpoch {
|
||||
/// - `EpochTooLow` when `other` is more than 1 prior to `base`.
|
||||
/// - `EpochTooHigh` when `other` is more than 1 after `base`.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
pub fn from_epoch(base: Epoch, other: Epoch) -> Result<Self, Error> {
|
||||
// Due to saturating nature of epoch, check for current first.
|
||||
if other == base {
|
||||
|
||||
@@ -11,7 +11,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// The data submitted to the deposit contract.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||
|
||||
/// Information about a `BeaconChain` validator.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
||||
|
||||
/// An exit voluntarily submitted a validator who wishes to withdraw.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
/// Spec v0.6.3
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
|
||||
Reference in New Issue
Block a user