mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Merge branch 'validator-enhancements' into testnet-client
This commit is contained in:
@@ -661,6 +661,17 @@ impl BeaconState {
|
||||
})
|
||||
}
|
||||
|
||||
/// Build all the caches, if they need to be built.
|
||||
pub fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), Error> {
|
||||
self.build_epoch_cache(RelativeEpoch::Previous, spec)?;
|
||||
self.build_epoch_cache(RelativeEpoch::Current, spec)?;
|
||||
self.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, spec)?;
|
||||
self.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, spec)?;
|
||||
self.update_pubkey_cache()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Build an epoch cache, unless it is has already been built.
|
||||
pub fn build_epoch_cache(
|
||||
&mut self,
|
||||
|
||||
@@ -113,6 +113,16 @@ mod epoch_tests {
|
||||
|
||||
all_tests!(Epoch);
|
||||
|
||||
#[test]
|
||||
fn epoch_start_end() {
|
||||
let slots_per_epoch = 8;
|
||||
|
||||
let epoch = Epoch::new(0);
|
||||
|
||||
assert_eq!(epoch.start_slot(slots_per_epoch), Slot::new(0));
|
||||
assert_eq!(epoch.end_slot(slots_per_epoch), Slot::new(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slot_iter() {
|
||||
let slots_per_epoch = 8;
|
||||
|
||||
@@ -6,6 +6,8 @@ use dirs;
|
||||
use log::debug;
|
||||
use rayon::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
//TODO: testing only
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
pub const KEYPAIRS_FILE: &str = "keypairs.raw_keypairs";
|
||||
|
||||
@@ -120,7 +122,17 @@ impl TestingBeaconStateBuilder {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let genesis_time = 1553753928; // arbitrary
|
||||
// TODO: Testing only. Burn with fire later.
|
||||
// set genesis to the last 30 minute block.
|
||||
// this is used for testing only. Allows multiple nodes to connect within a 30min window
|
||||
// and agree on a genesis
|
||||
let now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
let secs_after_last_period = now.checked_rem(30 * 60).unwrap_or(0);
|
||||
// genesis is now the last 30 minute block.
|
||||
let genesis_time = now - secs_after_last_period;
|
||||
|
||||
let mut state = BeaconState::genesis(
|
||||
genesis_time,
|
||||
|
||||
Reference in New Issue
Block a user