Documentation ¶
Overview ¶
Package slots includes ticker and timer-related functions for Ethereum consensus.
Index ¶
- Constants
- func AbsoluteValueSlotDifference(x, y types.Slot) uint64
- func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValidatorCount uint64, ...)
- func CurrentSlot(genesisTimeSec uint64) types.Slot
- func DivideSlotBy(timesPerSlot int64) time.Duration
- func EpochEnd(epoch types.Epoch) (types.Slot, error)
- func EpochStart(epoch types.Epoch) (types.Slot, error)
- func EpochsSinceGenesis(genesis time.Time) types.Epoch
- func IsEpochEnd(slot types.Slot) bool
- func IsEpochStart(slot types.Slot) bool
- func MultiplySlotBy(times int64) time.Duration
- func PrevSlot(slot types.Slot) types.Slot
- func RoundUpToNearestEpoch(slot types.Slot) types.Slot
- func Since(time time.Time) types.Slot
- func SinceEpochStarts(slot types.Slot) types.Slot
- func SinceGenesis(genesis time.Time) types.Slot
- func StartTime(genesis uint64, slot types.Slot) time.Time
- func SyncCommitteePeriod(e types.Epoch) uint64
- func SyncCommitteePeriodStartEpoch(e types.Epoch) (types.Epoch, error)
- func ToEpoch(slot types.Slot) types.Epoch
- func ToTime(genesisTimeSec uint64, slot types.Slot) (time.Time, error)
- func ValidateClock(slot types.Slot, genesisTimeSec uint64) error
- func VerifyTime(genesisTime uint64, slot types.Slot, timeTolerance time.Duration) error
- func VotingPeriodStartTime(genesis uint64, slot types.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 ¶
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 ¶
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 EpochStart ¶
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 ¶
EpochsSinceGenesis returns the number of slots since the provided genesis time.
func IsEpochEnd ¶
IsEpochEnd returns true if the given slot number is an epoch ending slot number.
func IsEpochStart ¶
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 RoundUpToNearestEpoch ¶
RoundUpToNearestEpoch rounds up the provided slot value to the nearest epoch.
func SinceEpochStarts ¶
SinceEpochStarts returns number of slots since the start of the epoch.
func SinceGenesis ¶
SinceGenesis returns the number of slots since the provided genesis time.
func SyncCommitteePeriod ¶
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 ¶
SyncCommitteePeriodStartEpoch returns the start epoch of a sync committee period.
func ToEpoch ¶
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 ¶
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.
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.