mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Upgrade codebase to new SlotClock API
This commit is contained in:
@@ -123,8 +123,10 @@ impl<T: EthSpec> TestingBeaconStateBuilder<T> {
|
||||
.collect::<Vec<_>>()
|
||||
.into();
|
||||
|
||||
let genesis_time = 1567052589; // 29 August, 2019;
|
||||
|
||||
let mut state = BeaconState::new(
|
||||
spec.min_genesis_time,
|
||||
genesis_time,
|
||||
Eth1Data {
|
||||
deposit_root: Hash256::zero(),
|
||||
deposit_count: 0,
|
||||
|
||||
@@ -33,7 +33,7 @@ pub trait SlotClock: Send + Sync + Sized {
|
||||
|
||||
fn new(genesis_slot: Slot, genesis: Instant, slot_duration: Duration) -> Self;
|
||||
|
||||
fn present_slot(&self) -> Option<Slot>;
|
||||
fn now(&self) -> Option<Slot>;
|
||||
|
||||
fn duration_to_next_slot(&self) -> Option<Duration>;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ lazy_static! {
|
||||
|
||||
/// Update the global metrics `DEFAULT_REGISTRY` with info from the slot clock.
|
||||
pub fn scrape_for_metrics<T: EthSpec, U: SlotClock>(clock: &U) {
|
||||
let present_slot = match clock.present_slot() {
|
||||
let present_slot = match clock.now() {
|
||||
Some(slot) => slot,
|
||||
_ => Slot::new(0),
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ impl SlotClock for SystemTimeSlotClock {
|
||||
}
|
||||
}
|
||||
|
||||
fn present_slot(&self) -> Option<Slot> {
|
||||
fn now(&self) -> Option<Slot> {
|
||||
let now = Instant::now();
|
||||
|
||||
if now < self.genesis {
|
||||
@@ -80,18 +80,18 @@ mod tests {
|
||||
|
||||
let clock =
|
||||
SystemTimeSlotClock::new(genesis_slot, prior_genesis(0), Duration::from_secs(1));
|
||||
assert_eq!(clock.present_slot(), Some(Slot::new(0)));
|
||||
assert_eq!(clock.now(), Some(Slot::new(0)));
|
||||
|
||||
let clock =
|
||||
SystemTimeSlotClock::new(genesis_slot, prior_genesis(5), Duration::from_secs(1));
|
||||
assert_eq!(clock.present_slot(), Some(Slot::new(5)));
|
||||
assert_eq!(clock.now(), Some(Slot::new(5)));
|
||||
|
||||
let clock = SystemTimeSlotClock::new(
|
||||
genesis_slot,
|
||||
Instant::now() - Duration::from_millis(500),
|
||||
Duration::from_secs(1),
|
||||
);
|
||||
assert_eq!(clock.present_slot(), Some(Slot::new(0)));
|
||||
assert_eq!(clock.now(), Some(Slot::new(0)));
|
||||
assert!(clock.duration_to_next_slot().unwrap() < Duration::from_millis(500));
|
||||
|
||||
let clock = SystemTimeSlotClock::new(
|
||||
@@ -99,7 +99,7 @@ mod tests {
|
||||
Instant::now() - Duration::from_millis(1_500),
|
||||
Duration::from_secs(1),
|
||||
);
|
||||
assert_eq!(clock.present_slot(), Some(Slot::new(1)));
|
||||
assert_eq!(clock.now(), Some(Slot::new(1)));
|
||||
assert!(clock.duration_to_next_slot().unwrap() < Duration::from_millis(500));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ impl TestingSlotClock {
|
||||
}
|
||||
|
||||
pub fn advance_slot(&self) {
|
||||
self.set_slot(self.present_slot().unwrap().as_u64() + 1)
|
||||
self.set_slot(self.now().unwrap().as_u64() + 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ impl SlotClock for TestingSlotClock {
|
||||
}
|
||||
}
|
||||
|
||||
fn present_slot(&self) -> Option<Slot> {
|
||||
fn now(&self) -> Option<Slot> {
|
||||
let slot = *self.slot.read().expect("TestingSlotClock poisoned.");
|
||||
Some(slot)
|
||||
}
|
||||
@@ -50,8 +50,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_slot_now() {
|
||||
let clock = TestingSlotClock::new(Slot::new(10), Instant::now(), Duration::from_secs(0));
|
||||
assert_eq!(clock.present_slot(), Some(Slot::new(10)));
|
||||
assert_eq!(clock.now(), Some(Slot::new(10)));
|
||||
clock.set_slot(123);
|
||||
assert_eq!(clock.present_slot(), Some(Slot::new(123)));
|
||||
assert_eq!(clock.now(), Some(Slot::new(123)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user