mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-29 07:17:17 +00:00
Update beacon_state.rs to spec v0.4.0
This commit is contained in:
parent
38a1b94f61
commit
96ec53c6a8
@ -10,6 +10,7 @@ boolean-bitfield = { path = "../utils/boolean-bitfield" }
|
||||
ethereum-types = "0.4.0"
|
||||
hashing = { path = "../utils/hashing" }
|
||||
honey-badger-split = { path = "../utils/honey-badger-split" }
|
||||
int_to_bytes = { path = "../utils/int_to_bytes" }
|
||||
log = "0.4"
|
||||
rayon = "1.0"
|
||||
rand = "0.5.5"
|
||||
|
File diff suppressed because it is too large
Load Diff
0
eth2/types/src/beacon_state/helpers.rs
Normal file
0
eth2/types/src/beacon_state/helpers.rs
Normal file
@ -93,8 +93,20 @@ pub struct ChainSpec {
|
||||
pub domain_randao: u64,
|
||||
pub domain_transfer: u64,
|
||||
}
|
||||
|
||||
impl ChainSpec {
|
||||
/// Return the number of committees in one epoch.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn get_epoch_committee_count(&self, active_validator_count: usize) -> u64 {
|
||||
std::cmp::max(
|
||||
1,
|
||||
std::cmp::min(
|
||||
self.shard_count / self.slots_per_epoch,
|
||||
active_validator_count as u64 / self.slots_per_epoch / self.target_committee_size,
|
||||
),
|
||||
) * self.slots_per_epoch
|
||||
}
|
||||
|
||||
/// Returns a `ChainSpec` compatible with the Ethereum Foundation specification.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
@ -190,9 +202,7 @@ impl ChainSpec {
|
||||
domain_transfer: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainSpec {
|
||||
/// Returns a `ChainSpec` compatible with the specification suitable for 8 validators.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
|
@ -16,6 +16,8 @@ pub struct Fork {
|
||||
|
||||
impl Fork {
|
||||
/// Return the fork version of the given ``epoch``.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn get_fork_version(&self, epoch: Epoch) -> u64 {
|
||||
if epoch < self.epoch {
|
||||
return self.previous_version;
|
||||
@ -24,6 +26,8 @@ impl Fork {
|
||||
}
|
||||
|
||||
/// Get the domain number that represents the fork meta and signature domain.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn get_domain(&self, epoch: Epoch, domain_type: u64) -> u64 {
|
||||
let fork_version = self.get_fork_version(epoch);
|
||||
fork_version * u64::pow(2, 32) + domain_type
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{BeaconState, Hash256, Slot};
|
||||
use crate::{BeaconState, Slot};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// The `BeaconStateReader` provides interfaces for reading a subset of fields of a `BeaconState`.
|
||||
@ -11,7 +11,6 @@ use std::fmt::Debug;
|
||||
/// "future proofing".
|
||||
pub trait BeaconStateReader: Debug + PartialEq {
|
||||
fn slot(&self) -> Slot;
|
||||
fn canonical_root(&self) -> Hash256;
|
||||
fn into_beacon_state(self) -> Option<BeaconState>;
|
||||
}
|
||||
|
||||
@ -20,10 +19,6 @@ impl BeaconStateReader for BeaconState {
|
||||
self.slot
|
||||
}
|
||||
|
||||
fn canonical_root(&self) -> Hash256 {
|
||||
self.canonical_root()
|
||||
}
|
||||
|
||||
fn into_beacon_state(self) -> Option<BeaconState> {
|
||||
Some(self)
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ use super::validator::*;
|
||||
use crate::Epoch;
|
||||
|
||||
/// Given an indexed sequence of `validators`, return the indices corresponding to validators that are active at `epoch`.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn get_active_validator_indices(validators: &[Validator], epoch: Epoch) -> Vec<usize> {
|
||||
validators
|
||||
.iter()
|
||||
|
Loading…
Reference in New Issue
Block a user