mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
Add incomplete progress on fixing test harness
This commit is contained in:
@@ -253,6 +253,7 @@ where
|
||||
/// Information is read from the present `beacon_state` shuffling, so only information from the
|
||||
/// present and prior epoch is available.
|
||||
pub fn block_proposer(&self, slot: Slot) -> Result<usize, BeaconStateError> {
|
||||
trace!("BeaconChain::block_proposer: slot: {}", slot);
|
||||
let index = self
|
||||
.state
|
||||
.read()
|
||||
@@ -274,6 +275,10 @@ where
|
||||
&self,
|
||||
validator_index: usize,
|
||||
) -> Result<Option<(Slot, u64)>, BeaconStateError> {
|
||||
trace!(
|
||||
"BeaconChain::validator_attestion_slot_and_shard: validator_index: {}",
|
||||
validator_index
|
||||
);
|
||||
if let Some((slot, shard, _committee)) = self
|
||||
.state
|
||||
.read()
|
||||
@@ -287,6 +292,7 @@ where
|
||||
|
||||
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
||||
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
||||
trace!("BeaconChain::produce_attestation_data: shard: {}", shard);
|
||||
let justified_epoch = self.justified_epoch();
|
||||
let justified_block_root = *self
|
||||
.state
|
||||
|
||||
49
beacon_node/beacon_chain/src/cached_beacon_state.rs
Normal file
49
beacon_node/beacon_chain/src/cached_beacon_state.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use types::{beacon_state::BeaconStateError, BeaconState, ChainSpec, Epoch, Slot};
|
||||
|
||||
pub const CACHED_EPOCHS: usize = 3; // previous, current, next.
|
||||
|
||||
pub type CrosslinkCommittees = Vec<(Vec<usize>, u64)>;
|
||||
|
||||
pub struct CachedBeaconState<'a> {
|
||||
state: BeaconState,
|
||||
crosslinks: Vec<Vec<CrosslinkCommittees>>,
|
||||
spec: &'a ChainSpec,
|
||||
}
|
||||
|
||||
impl<'a> CachedBeaconState<'a> {
|
||||
pub fn from_beacon_state(
|
||||
state: BeaconState,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<Self, BeaconStateError> {
|
||||
let current_epoch = state.current_epoch(spec);
|
||||
let previous_epoch = if current_epoch == spec.genesis_epoch {
|
||||
current_epoch
|
||||
} else {
|
||||
current_epoch.saturating_sub(1_u64)
|
||||
};
|
||||
let next_epoch = state.next_epoch(spec);
|
||||
|
||||
let mut crosslinks: Vec<Vec<CrosslinkCommittees>> = Vec::with_capacity(3);
|
||||
crosslinks.push(committees_for_all_slots(&state, previous_epoch, spec)?);
|
||||
crosslinks.push(committees_for_all_slots(&state, current_epoch, spec)?);
|
||||
crosslinks.push(committees_for_all_slots(&state, next_epoch, spec)?);
|
||||
|
||||
Ok(Self {
|
||||
state,
|
||||
crosslinks,
|
||||
spec,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn committees_for_all_slots(
|
||||
state: &BeaconState,
|
||||
epoch: Epoch,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Vec<CrosslinkCommittees>, BeaconStateError> {
|
||||
let mut crosslinks: Vec<CrosslinkCommittees> = Vec::with_capacity(spec.epoch_length as usize);
|
||||
for slot in epoch.slot_iter(spec.epoch_length) {
|
||||
crosslinks.push(state.get_crosslink_committees_at_slot(slot, false, spec)?)
|
||||
}
|
||||
Ok(crosslinks)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
mod attestation_aggregator;
|
||||
mod beacon_chain;
|
||||
mod cached_beacon_state;
|
||||
mod checkpoint;
|
||||
|
||||
pub use self::beacon_chain::{BeaconChain, Error};
|
||||
|
||||
Reference in New Issue
Block a user