mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Finished Gossip Block Validation Conditions (#2640)
* Gossip Block Validation is Much More Efficient Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -65,6 +65,9 @@ pub trait SlotClock: Send + Sync + Sized + Clone {
|
||||
/// Returns the first slot to be returned at the genesis time.
|
||||
fn genesis_slot(&self) -> Slot;
|
||||
|
||||
/// Returns the `Duration` from `UNIX_EPOCH` to the genesis time.
|
||||
fn genesis_duration(&self) -> Duration;
|
||||
|
||||
/// Returns the slot if the internal clock were advanced by `duration`.
|
||||
fn now_with_future_tolerance(&self, tolerance: Duration) -> Option<Slot> {
|
||||
self.slot_of(self.now_duration()?.checked_add(tolerance)?)
|
||||
@@ -99,4 +102,14 @@ pub trait SlotClock: Send + Sync + Sized + Clone {
|
||||
fn sync_committee_contribution_production_delay(&self) -> Duration {
|
||||
self.slot_duration() * 2 / 3
|
||||
}
|
||||
|
||||
/// An implementation of the method described in the consensus spec here:
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#compute_timestamp_at_slot
|
||||
fn compute_timestamp_at_slot(&self, slot: Slot) -> Option<u64> {
|
||||
let slots_since_genesis = slot.as_u64().checked_sub(self.genesis_slot().as_u64())?;
|
||||
slots_since_genesis
|
||||
.checked_mul(self.slot_duration().as_secs())
|
||||
.and_then(|since_genesis| self.genesis_duration().as_secs().checked_add(since_genesis))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,10 @@ impl SlotClock for ManualSlotClock {
|
||||
fn genesis_slot(&self) -> Slot {
|
||||
self.genesis_slot
|
||||
}
|
||||
|
||||
fn genesis_duration(&self) -> Duration {
|
||||
self.genesis_duration
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -61,6 +61,10 @@ impl SlotClock for SystemTimeSlotClock {
|
||||
fn genesis_slot(&self) -> Slot {
|
||||
self.clock.genesis_slot()
|
||||
}
|
||||
|
||||
fn genesis_duration(&self) -> Duration {
|
||||
*self.clock.genesis_duration()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user