slots

package
v4.0.0-...-ae7b6de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package slots includes ticker and timer-related functions for Ethereum consensus.

Index

Constants

View Source
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(genesisTimeSec uint64) primitives.Slot

CurrentSlot returns the current slot as determined by the local clock and provided genesis time.

func DivideSlotBy

func DivideSlotBy(timesPerSlot int64) time.Duration

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 MultiplySlotBy

func MultiplySlotBy(times int64) time.Duration

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 SecondsSinceSlotStart

func SecondsSinceSlotStart(s primitives.Slot, genesisTime, timeStamp uint64) (uint64, error)

SecondsSinceSlotStart returns the number of seconds transcurred since the given slot start time

func Since

func Since(time time.Time) primitives.Slot

Since computes the number of time slots that have occurred since the given timestamp.

func SinceEpochStarts

func SinceEpochStarts(slot primitives.Slot) primitives.Slot

SinceEpochStarts returns number of slots since the start of the epoch.

func SinceGenesis

func SinceGenesis(genesis time.Time) primitives.Slot

SinceGenesis returns the number of slots since the provided genesis time.

func StartTime

func StartTime(genesis uint64, slot primitives.Slot) time.Time

StartTime returns the start time in terms of its unix epoch value.

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 TimeIntoSlot

func TimeIntoSlot(genesisTime uint64) time.Duration

TimeIntoSlot returns the time duration elapsed between the current time and the start of the current slot

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 ToTime

func ToTime(genesisTimeSec uint64, slot primitives.Slot) (time.Time, error)

ToTime takes the given slot and genesis time to determine the start time of the slot.

func ValidateClock

func ValidateClock(slot primitives.Slot, genesisTimeSec uint64) error

ValidateClock validates a provided slot against the local clock to ensure slots that are unreasonable are returned with an error.

func VerifyTime

func VerifyTime(genesisTime uint64, slot primitives.Slot, timeTolerance time.Duration) error

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.

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

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.

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.

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.

func (*SlotTicker) Done

func (s *SlotTicker) Done()

Done should be called to clean up the ticker.

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.

Directories

Path Synopsis
Package testing includes useful mocks for slot tickers in unit tests.
Package testing includes useful mocks for slot tickers in unit tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL