vegatime

package
v0.77.0-preview.5 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

README

Time

This simple package handles a complex issue - how do we represent time in a network with geographically distributed nodes? The answer within the core is to rely on the block time that Tendermint provides.

The general rule of thumb for Vega developers is:

  • Use Vega time for everything in Core
  • Unless you are logging metrics, in which case use the system time

Vega time

Vega time is set whenever the Tendermint calls Vega's BeginBlock function. As per Tendermint's BeginBlock documentation, this includes the header field Time:

Time (google.protobuf.Timestamp): Time of the previous block. For heights > 1, it's the weighted median of the timestamps of the valid votes in the block.LastCommit. For height == 1, it's genesis time.

System time

System time in this case means the current OS time on the computer. As noted above, the block time is set based on a median of the validators - meaning that your system time is likely to be somewhat different to the block time. This isn't a problem, as long API outputs and timestamps that go on chain use a consistent source of time.

For logs that are more like system logs, or metrics that you may view as the operator of a node, it makes more sense for these to be in your timezone, to avoid having to work out what the block time was in your local time.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(t time.Time) string

Format format the time using the time.RFC3339Nano formatting.

func Parse

func Parse(t string) (time.Time, error)

Parse parse a string expected to be a time in the time.RFC3339Nano format.

func RoundToNearest

func RoundToNearest(t time.Time, interval types.Interval) time.Time

RoundToNearest round an actual time to the nearest interval.

func Unix

func Unix(sec int64, nsec int64) time.Time

Unix create a new time from sec and nsec in UTC timezone.

func UnixNano

func UnixNano(nsec int64) time.Time

UnixNano equivalent to time.Unix(sec, nsec) but to be used with the result of time.Time{}.UnixNano() in UTC timezone.

Types

type Broker

type Broker interface {
	Send(event events.Event)
	SendBatch(events []events.Event)
}

type Config

type Config struct {
	Level encoding.LogLevel `long:"log-level"`
}

Config represent the configuration of vegatime service.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.

type Svc

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

Svc represents the Service managing time inside Vega. this is basically based on the time of the chain in use.

func New

func New(conf Config, broker Broker) *Svc

New instantiates a new vegatime service.

func (*Svc) GetTimeLastBatch

func (s *Svc) GetTimeLastBatch() time.Time

GetTimeLastBatch returns the previous vega time.

func (*Svc) GetTimeNow

func (s *Svc) GetTimeNow() time.Time

GetTimeNow returns the current time in vega.

func (*Svc) NotifyOnTick

func (s *Svc) NotifyOnTick(callbacks ...func(context.Context, time.Time))

NotifyOnTick allows other services to register a callback function which will be called once the vega time is updated (SetTimeNow is called).

func (*Svc) ReloadConf

func (s *Svc) ReloadConf(conf Config)

ReloadConf reload the configuration for the vegatime service.

func (*Svc) SetTimeNow

func (s *Svc) SetTimeNow(ctx context.Context, t time.Time)

SetTimeNow update the current time.

type TimeService

type TimeService interface {
	GetTimeNow() time.Time
	NotifyOnTick(...func(context.Context, time.Time))
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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