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 RoundToNearest ¶
RoundToNearest round an actual time to the nearest interval.
Types ¶
type Config ¶
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 (*Svc) GetTimeLastBatch ¶
GetTimeLastBatch returns the previous vega time.
func (*Svc) GetTimeNow ¶
GetTimeNow returns the current time in vega.
func (*Svc) NotifyOnTick ¶
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 ¶
ReloadConf reload the configuration for the vegatime service.