Documentation ¶
Overview ¶
Package slots includes ticker and timer-related functions for Ethereum consensus.
Index ¶
- Constants
- func AbsoluteValueSlotDifference(x, y primitives.Slot) uint64
- func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValidatorCount uint64, ...)
- func CurrentSlot(genesisTimeSec uint64) 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 MultiplySlotBy(times int64) time.Duration
- func PrevSlot(slot primitives.Slot) primitives.Slot
- func RoundUpToNearestEpoch(slot primitives.Slot) primitives.Slot
- func SecondsSinceSlotStart(s primitives.Slot, genesisTime, timeStamp uint64) (uint64, error)
- func Since(time time.Time) primitives.Slot
- func SinceEpochStarts(slot primitives.Slot) primitives.Slot
- func SinceGenesis(genesis time.Time) primitives.Slot
- func StartTime(genesis uint64, slot primitives.Slot) time.Time
- func SyncCommitteePeriod(e primitives.Epoch) uint64
- func SyncCommitteePeriodStartEpoch(e primitives.Epoch) (primitives.Epoch, error)
- func ToEpoch(slot primitives.Slot) primitives.Epoch
- func ToTime(genesisTimeSec uint64, slot primitives.Slot) (time.Time, error)
- func ValidateClock(slot primitives.Slot, genesisTimeSec uint64) error
- func VerifyTime(genesisTime uint64, slot primitives.Slot, timeTolerance time.Duration) error
- func VotingPeriodStartTime(genesis uint64, slot primitives.Slot) uint64
- 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(genesisTimeSec uint64) 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 ¶ added in v4.0.4
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 ¶
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 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 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 ¶
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 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.
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.