Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock abstracts important time-related concerns in the beacon chain:
- provides a time.Now() construct that can be overridden in tests
- GenesisTime() to know the genesis time or use genesis time determination as a synchronization point.
- CurrentSlot: convenience conversion for current time -> slot (support backwards compatibility with the TimeFetcher interface)
- GenesisValidatorsRoot: is determined at the same point as genesis time and is needed by some of the same code, so it is also bundled for convenience.
func NewClock ¶
NewClock constructs a Clock value from a genesis timestamp (t) and a Genesis Validator Root (vr). The WithNower ClockOpt can be used in tests to specify an alternate `time.Now` implementation, for instance to return a value for `Now` spanning a certain number of slots from genesis time, to control the current slot.
func (*Clock) CurrentSlot ¶
CurrentSlot returns the current slot relative to the time.Time value that Clock embeds.
func (*Clock) GenesisTime ¶
GenesisTime returns the genesis timestamp.
func (*Clock) GenesisValidatorsRoot ¶
GenesisValidatorsRoot returns the genesis state validator root
type ClockOpt ¶
type ClockOpt func(*Clock)
ClockOpt is a functional option to change the behavior of a clock value made by NewClock. It is primarily intended as a way to inject an alternate time.Now() callback (WithNower) for testing.
type ClockSetter ¶
ClockSetter specifies the SetClock method. ClockSynchronizer works in a 1:N pattern, so in a given graph of services, only one service should be given the ClockSetter, and all others relying on the service's activation should use ClockWaiter.
type ClockSynchronizer ¶
type ClockSynchronizer struct {
// contains filtered or unexported fields
}
ClockSynchronizer provides a synchronization mechanism for services that rely on the genesis time and validator root being known before getting to work.
func NewClockSynchronizer ¶
func NewClockSynchronizer() *ClockSynchronizer
NewClockSynchronizer initializes a single instance of ClockSynchronizer that must be used by all ClockWaiters that need to be synchronized to a ClockSetter (ie blockchain service).
func (*ClockSynchronizer) SetClock ¶
func (w *ClockSynchronizer) SetClock(c *Clock) error
SetClock sets the Clock value `c` and unblocks all threads waiting for `c` via WaitForClock. Calling SetClock more than once will return an error, as calling this function is meant to be a signal that the system is ready to start.
func (*ClockSynchronizer) WaitForClock ¶
func (w *ClockSynchronizer) WaitForClock(ctx context.Context) (*Clock, error)
WaitForClock will block the caller until the *Clock value is available. If the provided context is canceled (eg via a deadline set upstream), the function will return the error given by ctx.Err().
type ClockWaiter ¶
ClockWaiter specifies the WaitForClock method. ClockSynchronizer works in a 1:N pattern, with 1 thread calling SetClock, and the others blocking on a call to WaitForClock until the expected *Clock value is set.