Documentation
¶
Overview ¶
Code generated by hack/gen-logs.sh; DO NOT EDIT. This file is created and regenerated automatically. Anything added here might get removed.
Package slots includes ticker and timer-related functions for Ethereum consensus.
Index ¶
- Constants
- func AbsoluteValueSlotDifference(x, y primitives.Slot) uint64
- func At(genesis, tm time.Time) primitives.Slot
- func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValidatorCount uint64, ...)
- func CurrentSlot(genesis time.Time) primitives.Slot
- func DivideSlotBy(timesPerSlot int64) time.Duration
- func Duration(start, end time.Time) primitives.Slot
- func EpochEnd(epoch primitives.Epoch) (primitives.Slot, error)
- func EpochStart(epoch primitives.Epoch) (primitives.Slot, error)
- func EpochsSinceGenesis(genesis time.Time) primitives.Epoch
- func IsEpochEnd(slot primitives.Slot) bool
- func IsEpochStart(slot primitives.Slot) bool
- func MaxSafeEpoch() primitives.Epoch
- func MultiplySlotBy(times int64) time.Duration
- func PrevSlot(slot primitives.Slot) primitives.Slot
- func RoundUpToNearestEpoch(slot primitives.Slot) primitives.Slot
- func SafeEpochStartOrMax(e primitives.Epoch) primitives.Slot
- func SecondsUntilNextEpochStart(genesis time.Time) (uint64, error)
- func SinceEpochStarts(slot primitives.Slot) primitives.Slot
- func SinceSlotStart(s primitives.Slot, genesis time.Time, timestamp time.Time) (time.Duration, error)
- func StartTime(genesis time.Time, slot primitives.Slot) (time.Time, error)
- func SyncCommitteePeriod(e primitives.Epoch) uint64
- func SyncCommitteePeriodStartEpoch(e primitives.Epoch) (primitives.Epoch, error)
- func ToEpoch(slot primitives.Slot) primitives.Epoch
- func ToForkVersion(slot primitives.Slot) int
- func UnsafeEpochStart(epoch primitives.Epoch) primitives.Slot
- func UnsafeStartTime(genesis time.Time, slot primitives.Slot) time.Time
- func ValidateClock(slot primitives.Slot, genesis time.Time) error
- func VerifyTime(genesis time.Time, slot primitives.Slot, timeTolerance time.Duration) error
- func VotingPeriodStartTime(genesis uint64, slot primitives.Slot) uint64
- func WithinVotingWindow(genesis time.Time, slot primitives.Slot) bool
- type IntervalTicker
- type SlotInterval
- type SlotIntervalTicker
- type SlotTicker
- type Ticker
Constants ¶
const MaxSlotBuffer = uint64(1 << 7)
MaxSlotBuffer specifies the max buffer given to slots from incoming objects. (24 mins with mainnet spec)
Variables ¶
This section is empty.
Functions ¶
func AbsoluteValueSlotDifference ¶
func AbsoluteValueSlotDifference(x, y primitives.Slot) uint64
AbsoluteValueSlotDifference between two slots.
func CountdownToGenesis ¶
func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValidatorCount uint64, genesisStateRoot [32]byte)
CountdownToGenesis starts a ticker at the specified duration logging the remaining minutes until the genesis chainstart event along with important genesis state metadata such as number of genesis validators.
func CurrentSlot ¶
func CurrentSlot(genesis time.Time) primitives.Slot
CurrentSlot returns the current slot as determined by the local clock and provided genesis time.
func DivideSlotBy ¶
DivideSlotBy divides the SECONDS_PER_SLOT configuration parameter by a specified number. It returns a value of time.Duration in milliseconds, useful for dividing values such as 1 second into millisecond-based durations.
func Duration ¶
func Duration(start, end time.Time) primitives.Slot
Duration computes the span of time between two instants, represented as Slots.
func EpochEnd ¶
func EpochEnd(epoch primitives.Epoch) (primitives.Slot, error)
EpochEnd returns the last slot number of the current epoch.
func EpochStart ¶
func EpochStart(epoch primitives.Epoch) (primitives.Slot, error)
EpochStart returns the first slot number of the current epoch.
Spec pseudocode definition:
def compute_start_slot_at_epoch(epoch: Epoch) -> Slot: """ Return the start slot of ``epoch``. """ return Slot(epoch * SLOTS_PER_EPOCH)
func EpochsSinceGenesis ¶
func EpochsSinceGenesis(genesis time.Time) primitives.Epoch
EpochsSinceGenesis returns the number of epochs since the provided genesis time.
func IsEpochEnd ¶
func IsEpochEnd(slot primitives.Slot) bool
IsEpochEnd returns true if the given slot number is an epoch ending slot number.
func IsEpochStart ¶
func IsEpochStart(slot primitives.Slot) bool
IsEpochStart returns true if the given slot number is an epoch starting slot number.
func MaxSafeEpoch ¶
func MaxSafeEpoch() primitives.Epoch
MaxSafeEpoch gives the largest epoch value that can be safely converted to a slot. Note that just dividing max uint64 by slots per epoch is not sufficient, because the resulting slot could still be the start of an epoch that would overflow in the end slot computation. So we subtract 1 to ensure that the final epoch can always have 32 slots.
func MultiplySlotBy ¶
MultiplySlotBy multiplies the SECONDS_PER_SLOT configuration parameter by a specified number. It returns a value of time.Duration in millisecond-based durations.
func PrevSlot ¶
func PrevSlot(slot primitives.Slot) primitives.Slot
PrevSlot returns previous slot, with an exception in slot 0 to prevent underflow.
func RoundUpToNearestEpoch ¶
func RoundUpToNearestEpoch(slot primitives.Slot) primitives.Slot
RoundUpToNearestEpoch rounds up the provided slot value to the nearest epoch.
func SafeEpochStartOrMax ¶ added in v7.1.0
func SafeEpochStartOrMax(e primitives.Epoch) primitives.Slot
SafeEpochStartOrMax returns the start slot of the given epoch if it will not overflow, otherwise it takes the highest epoch that won't overflow, and to introduce a little margin for error, returns the slot beginning the prior epoch.
func SecondsUntilNextEpochStart ¶
SecondsUntilNextEpochStart returns how many seconds until the next Epoch start from the current time and slot
func SinceEpochStarts ¶
func SinceEpochStarts(slot primitives.Slot) primitives.Slot
SinceEpochStarts returns number of slots since the start of the epoch.
func SinceSlotStart ¶
func SinceSlotStart(s primitives.Slot, genesis time.Time, timestamp time.Time) (time.Duration, error)
SinceSlotStart returns the amount of time elapsed since the given slot start time. This method returns an error if the timestamp happens before the given slot start time.
func StartTime ¶
StartTime takes the given slot and genesis time to determine the start time of the slot. This method returns an error if the product of the slot duration * slot overflows int64.
func SyncCommitteePeriod ¶
func SyncCommitteePeriod(e primitives.Epoch) uint64
SyncCommitteePeriod returns the sync committee period of input epoch `e`.
Spec code: def compute_sync_committee_period(epoch: Epoch) -> uint64:
return epoch // EPOCHS_PER_SYNC_COMMITTEE_PERIOD
func SyncCommitteePeriodStartEpoch ¶
func SyncCommitteePeriodStartEpoch(e primitives.Epoch) (primitives.Epoch, error)
SyncCommitteePeriodStartEpoch returns the start epoch of a sync committee period.
func ToEpoch ¶
func ToEpoch(slot primitives.Slot) primitives.Epoch
ToEpoch returns the epoch number of the input slot.
Spec pseudocode definition:
def compute_epoch_at_slot(slot: Slot) -> Epoch: """ Return the epoch number at ``slot``. """ return Epoch(slot // SLOTS_PER_EPOCH)
func ToForkVersion ¶
func ToForkVersion(slot primitives.Slot) int
ToForkVersion translates a slot into it's corresponding version.
func UnsafeEpochStart ¶
func UnsafeEpochStart(epoch primitives.Epoch) primitives.Slot
UnsafeEpochStart is a version of EpochStart that panics if there is an overflow. It can be safely used by code that first guarantees epoch <= MaxSafeEpoch.
func UnsafeStartTime ¶
UnsafeStartTime returns the start time in terms of its unix epoch value. This method could panic if the product of slot duration * slot overflows uint64. Deprecated: Use StartTime and handle the error.
func ValidateClock ¶
func ValidateClock(slot primitives.Slot, genesis time.Time) error
ValidateClock validates a provided slot against the local clock to ensure slots that are unreasonable are returned with an error.
func VerifyTime ¶
VerifyTime validates the input slot is not from the future.
func VotingPeriodStartTime ¶
func VotingPeriodStartTime(genesis uint64, slot primitives.Slot) uint64
VotingPeriodStartTime returns the current voting period's start time depending on the provided genesis and current slot.
func WithinVotingWindow ¶
func WithinVotingWindow(genesis time.Time, slot primitives.Slot) bool
WithinVotingWindow returns whether the current time is within the voting window (eg. 4 seconds on mainnet) of the current slot.
Types ¶
type IntervalTicker ¶
type IntervalTicker interface {
C() <-chan SlotInterval
Done()
}
The IntervalTicker is similar to the Ticker interface but exposes also the interval along with the slot number
type SlotInterval ¶
type SlotInterval struct {
Slot primitives.Slot
Interval int
}
SlotInterval is a wrapper that contains a slot and the interval index that triggered the ticker
type SlotIntervalTicker ¶
type SlotIntervalTicker struct {
// contains filtered or unexported fields
}
SlotIntervalTicker is similar to a slot ticker but it returns also the index of the interval that triggered the event
func NewSlotTickerWithIntervals ¶
func NewSlotTickerWithIntervals(genesisTime time.Time, intervals []time.Duration) *SlotIntervalTicker
NewSlotTickerWithIntervals starts and returns a SlotTicker instance that allows several offsets of time from genesis, Caller is responsible to input the intervals in increasing order and none bigger or equal than SecondsPerSlot This method will panic if genesis time is zero, intervals is 0 length, or offsets are invalid. lint:nopanic -- Communicated panic in godoc commentary.
func (*SlotIntervalTicker) C ¶
func (s *SlotIntervalTicker) C() <-chan SlotInterval
C returns the ticker channel. Call Cancel afterwards to ensure that the goroutine exits cleanly.
func (*SlotIntervalTicker) Done ¶
func (s *SlotIntervalTicker) Done()
Done should be called to clean up the ticker.
type SlotTicker ¶
type SlotTicker struct {
// contains filtered or unexported fields
}
SlotTicker is a special ticker for the beacon chain block. The channel emits over the slot interval, and ensures that the ticks are in line with the genesis time. This means that the duration between the ticks and the genesis time are always a multiple of the slot duration. In addition, the channel returns the new slot number.
func NewSlotTicker ¶
func NewSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker
NewSlotTicker starts and returns a new SlotTicker instance. This method panics if genesis time is zero. lint:nopanic -- Communicated panic in godoc commentary.
func NewSlotTickerWithOffset ¶
func NewSlotTickerWithOffset(genesisTime time.Time, offset time.Duration, secondsPerSlot uint64) *SlotTicker
NewSlotTickerWithOffset starts and returns a SlotTicker instance that allows a offset of time from genesis, entering a offset greater than secondsPerSlot is not allowed. This method will panic if genesis time is zero or the offset is less than seconds per slot. lint:nopanic -- Communicated panic in godoc commentary.
func (*SlotTicker) C ¶
func (s *SlotTicker) C() <-chan primitives.Slot
C returns the ticker channel. Call Cancel afterwards to ensure that the goroutine exits cleanly.
type Ticker ¶
type Ticker interface {
C() <-chan primitives.Slot
Done()
}
The Ticker interface defines a type which can expose a receive-only channel firing slot events.