ethwallclock

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: GPL-3.0 Imports: 3 Imported by: 22

README

EthWallclock

Go Report Card Release

An Ethereum Wallclock Go package

Installation

go get github.com/ethpandaops/ethwallclock

Usage

package main

import (
  "fmt"
  "time"

  "github.com/ethpandaops/ethwallclock"
)
 
func main() {
  genesisTime, _ := time.Parse(time.RFC3339, "2020-01-01T12:00:23Z")

  wallclock := ethwallclock.NewEthereumBeaconChain(genesisTime, 12*time.Second, 32)

  slot, epoch, err := wallclock.Now()
  if err != nil {
    panic(err)
  }

  fmt.Println("Slot: ", slot)
  fmt.Println("Epoch: ", epoch)
}
Slot duration change at Heze

Heze changes the slot duration from SLOT_DURATION_MS to SLOT_DURATION_MS_HEZE at HEZE_FORK_EPOCH. Pass both from the beacon spec; slot/epoch numbers, time windows and the OnSlotChanged/OnEpochChanged callbacks follow the change.

wallclock := ethwallclock.NewEthereumBeaconChain(genesisTime, 12*time.Second, 32,
  ethwallclock.WithHezeSlotDuration(hezeForkEpoch, 9*time.Second),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultEpochCreator

type DefaultEpochCreator struct {
	// contains filtered or unexported fields
}

func NewDefaultEpochCreator

func NewDefaultEpochCreator(genesis time.Time, durationPerSlot time.Duration, slotsPerEpoch uint64, opts ...Option) *DefaultEpochCreator

func (*DefaultEpochCreator) Current

func (e *DefaultEpochCreator) Current() Epoch

func (*DefaultEpochCreator) FromNumber

func (e *DefaultEpochCreator) FromNumber(number uint64) Epoch

func (*DefaultEpochCreator) FromSlot

func (e *DefaultEpochCreator) FromSlot(slot uint64) Epoch

func (*DefaultEpochCreator) FromTime

func (e *DefaultEpochCreator) FromTime(t time.Time) Epoch

type DefaultSlotCreator

type DefaultSlotCreator struct {
	// contains filtered or unexported fields
}

func NewDefaultSlotCreator

func NewDefaultSlotCreator(genesis time.Time, durationPerSlot time.Duration) *DefaultSlotCreator

func (*DefaultSlotCreator) Current

func (s *DefaultSlotCreator) Current() Slot

func (*DefaultSlotCreator) DurationAt

func (s *DefaultSlotCreator) DurationAt(number uint64) time.Duration

DurationAt returns the duration of the given slot.

func (*DefaultSlotCreator) FromNumber

func (s *DefaultSlotCreator) FromNumber(number uint64) Slot

func (*DefaultSlotCreator) FromTime

func (s *DefaultSlotCreator) FromTime(t time.Time) Slot

type Epoch

type Epoch struct {
	// contains filtered or unexported fields
}

func NewEpoch

func NewEpoch(number uint64, start, end time.Time) Epoch

func (*Epoch) Number

func (e *Epoch) Number() uint64

func (*Epoch) TimeWindow

func (e *Epoch) TimeWindow() *TimeWindow

type EthereumBeaconChain

type EthereumBeaconChain struct {
	// contains filtered or unexported fields
}

func NewEthereumBeaconChain

func NewEthereumBeaconChain(genesis time.Time, durationPerSlot time.Duration, slotsPerEpoch uint64, opts ...Option) *EthereumBeaconChain

func (*EthereumBeaconChain) Epochs

func (*EthereumBeaconChain) FromTime

func (e *EthereumBeaconChain) FromTime(t time.Time) (Slot, Epoch, error)

func (*EthereumBeaconChain) Now

func (e *EthereumBeaconChain) Now() (Slot, Epoch, error)

func (*EthereumBeaconChain) OnEpochChanged

func (e *EthereumBeaconChain) OnEpochChanged(callback func(current Epoch))

func (*EthereumBeaconChain) OnSlotChanged

func (e *EthereumBeaconChain) OnSlotChanged(callback func(current Slot))

func (*EthereumBeaconChain) Slots

func (*EthereumBeaconChain) Stop

func (e *EthereumBeaconChain) Stop()

type Option

type Option func(*config)

Option configures a wall clock.

func WithHezeSlotDuration

func WithHezeSlotDuration(hezeForkEpoch uint64, slotDuration time.Duration) Option

WithHezeSlotDuration switches the slot duration to SLOT_DURATION_MS_HEZE from HEZE_FORK_EPOCH onwards. A zero duration or an unreachable epoch (FAR_FUTURE_EPOCH) leaves the slot duration unchanged.

type Slot

type Slot struct {
	// contains filtered or unexported fields
}

func NewSlot

func NewSlot(number uint64, start, end time.Time) Slot

func (*Slot) Number

func (s *Slot) Number() uint64

func (*Slot) TimeWindow

func (s *Slot) TimeWindow() *TimeWindow

type TimeWindow

type TimeWindow struct {
	// contains filtered or unexported fields
}

func NewTimeWindow

func NewTimeWindow(start, end time.Time) *TimeWindow

func (*TimeWindow) Active

func (t *TimeWindow) Active() bool

func (*TimeWindow) End

func (t *TimeWindow) End() time.Time

func (*TimeWindow) EndsIn

func (t *TimeWindow) EndsIn() time.Duration

func (*TimeWindow) Start

func (t *TimeWindow) Start() time.Time

func (*TimeWindow) StartsIn

func (t *TimeWindow) StartsIn() time.Duration

Jump to

Keyboard shortcuts

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