clock

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0, MIT Imports: 5 Imported by: 6

Documentation

Index

Constants

View Source
const DefaultEpochDuration = builtin.EpochDurationSeconds * time.Second

DefaultEpochDuration is the default duration of epochs

View Source
const DefaultPropagationDelay = 6 * time.Second

DefaultPropagationDelay is the default time to await for blocks to arrive before mining

Variables

This section is empty.

Functions

func NewFakeChain

func NewFakeChain(genesis uint64, epochDuration time.Duration, now int64) (Fake, ChainEpochClock)

Creates a new fake clock and chain clock wrapping it.

Types

type ChainEpochClock

type ChainEpochClock interface {
	EpochDuration() time.Duration
	EpochAtTime(t time.Time) abi.ChainEpoch
	EpochRangeAtTimestamp(t uint64) (abi.ChainEpoch, abi.ChainEpoch)
	StartTimeOfEpoch(e abi.ChainEpoch) time.Time
	WaitForEpoch(ctx context.Context, e abi.ChainEpoch)
	WaitNextEpoch(ctx context.Context) abi.ChainEpoch
	Clock
}

ChainEpochClock is an interface for a clock that represents epochs of the protocol.

func NewChainClock

func NewChainClock(genesisTime uint64, blockTime time.Duration) ChainEpochClock

NewChainClock returns a ChainEpochClock wrapping a default clock.Clock

func NewChainClockFromClock

func NewChainClockFromClock(genesisSeconds uint64, blockTime time.Duration, c Clock) ChainEpochClock

NewChainClockFromClock returns a ChainEpochClock wrapping the provided clock.Clock

type Clock

type Clock interface {
	After(d time.Duration) <-chan time.Time
	Sleep(d time.Duration)
	Now() time.Time
	Since(t time.Time) time.Duration

	NewTicker(d time.Duration) Ticker

	NewTimer(d time.Duration) Timer
	AfterFunc(d time.Duration, f func()) Timer
}

Clock provides an interface that packages can use instead of directly using the time module, so that chronology-related behavior can be tested Adapted from: https://github.com/jonboulle/clockwork

func NewSystemClock

func NewSystemClock() Clock

NewSystemClock returns a Clock that delegates calls to the actual time package; it should be used by packages in production.

type Fake

type Fake interface {
	Clock
	// Advance advances the Fake to a new point in time, ensuring any existing
	// sleepers are notified appropriately before returning
	Advance(d time.Duration)
	// BlockUntil will block until the Fake has the given number of
	// sleepers (callers of Sleep or After)
	BlockUntil(n int)
}

Fake provides an interface for a clock which can be manually advanced. Adapted from: https://github.com/jonboulle/clockwork

func NewFake

func NewFake(n time.Time) Fake

Returns a Fake initialised at the given time.Time.

type Ticker

type Ticker interface {
	Chan() <-chan time.Time
	Stop()
}

Ticker provides an interface which can be used instead of directly using the ticker within the time module. The real-time ticker t provides ticks through t.C which becomes now t.Chan() to make this channel requirement definable in this interface. Adapted from: https://github.com/jonboulle/clockwork

type Timer

type Timer interface {
	Chan() <-chan time.Time
	Reset(d time.Duration) bool
	Stop() bool
}

Timer provides an interface to a time.Timer which is testable. See https://golang.org/pkg/time/#Timer for more details on how timers work.

Jump to

Keyboard shortcuts

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