slotutil

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: GPL-3.0 Imports: 7 Imported by: 35

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsoluteValueSlotDifference added in v1.3.11

func AbsoluteValueSlotDifference(x, y types.Slot) uint64

AbsoluteValueSlotDifference between two slots.

func CountdownToGenesis added in v1.0.0

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 DivideSlotBy added in v1.0.0

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 EpochsSinceGenesis added in v0.3.0

func EpochsSinceGenesis(genesis time.Time) types.Epoch

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

func MultiplySlotBy added in v1.4.1

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 SlotStartTime

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

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

func SlotsSinceGenesis added in v0.3.0

func SlotsSinceGenesis(genesis time.Time) types.Slot

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

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 added in v1.2.0

func NewSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker

NewSlotTicker starts and returns a new SlotTicker instance.

func NewSlotTickerWithOffset added in v1.2.0

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 added in v0.3.0

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