slots

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: GPL-3.0 Imports: 10 Imported by: 1

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 types.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) types.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 EpochEnd

func EpochEnd(epoch types.Epoch) (types.Slot, error)

EpochEnd returns the last slot number of the current epoch.

func EpochStart

func EpochStart(epoch types.Epoch) (types.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) types.Epoch

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

func IsEpochEnd

func IsEpochEnd(slot types.Slot) bool

IsEpochEnd returns true if the given slot number is an epoch ending slot number.

func IsEpochStart

func IsEpochStart(slot types.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 types.Slot) types.Slot

PrevSlot returns previous slot, with an exception in slot 0 to prevent underflow.

func RoundUpToNearestEpoch

func RoundUpToNearestEpoch(slot types.Slot) types.Slot

RoundUpToNearestEpoch rounds up the provided slot value to the nearest epoch.

func Since

func Since(time time.Time) types.Slot

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

func SinceEpochStarts

func SinceEpochStarts(slot types.Slot) types.Slot

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

func SinceGenesis

func SinceGenesis(genesis time.Time) types.Slot

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

func StartTime

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

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

func SyncCommitteePeriod

func SyncCommitteePeriod(e types.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 types.Epoch) (types.Epoch, error)

SyncCommitteePeriodStartEpoch returns the start epoch of a sync committee period.

func ToEpoch

func ToEpoch(slot types.Slot) types.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 types.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 types.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 types.Slot, timeTolerance time.Duration) error

VerifyTime validates the input slot is not from the future.

func VotingPeriodStartTime

func VotingPeriodStartTime(genesis uint64, slot types.Slot) uint64

VotingPeriodStartTime returns the current voting period's start time depending on the provided genesis and current slot.

Types

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 types.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 types.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