xrpld
Loading...
Searching...
No Matches
xrpl::TimeKeeper Class Reference

Manages various times used by the server. More...

#include <TimeKeeper.h>

Inheritance diagram for xrpl::TimeKeeper:
Collaboration diagram for xrpl::TimeKeeper:

Public Types

using rep
using period
using duration
using time_point
using clock_type

Public Member Functions

 ~TimeKeeper () override=default
time_point now () const override
 Returns the current time, using the server's clock.
time_point closeTime () const
 Returns the predicted close time, in network time.
std::chrono::seconds closeOffset () const
std::chrono::seconds adjustCloseTime (std::chrono::seconds by)
 Adjust the close time, based on the network's view of time.

Static Public Attributes

static bool const is_steady

Static Private Member Functions

static constexpr time_point adjust (std::chrono::system_clock::time_point when)

Private Attributes

std::atomic< std::chrono::secondscloseOffset_

Detailed Description

Manages various times used by the server.

Definition at line 11 of file TimeKeeper.h.

Member Typedef Documentation

◆ rep

using beast::AbstractClock< NetClock >::rep
inherited

Definition at line 37 of file abstract_clock.h.

◆ period

using beast::AbstractClock< NetClock >::period
inherited

Definition at line 38 of file abstract_clock.h.

◆ duration

using beast::AbstractClock< NetClock >::duration
inherited

Definition at line 39 of file abstract_clock.h.

◆ time_point

using beast::AbstractClock< NetClock >::time_point
inherited

Definition at line 40 of file abstract_clock.h.

◆ clock_type

using beast::AbstractClock< NetClock >::clock_type
inherited

Definition at line 41 of file abstract_clock.h.

Constructor & Destructor Documentation

◆ ~TimeKeeper()

xrpl::TimeKeeper::~TimeKeeper ( )
overridedefault

Member Function Documentation

◆ adjust()

constexpr time_point xrpl::TimeKeeper::adjust ( std::chrono::system_clock::time_point when)
staticconstexprprivate

Definition at line 18 of file TimeKeeper.h.

◆ now()

time_point xrpl::TimeKeeper::now ( ) const
nodiscardoverridevirtual

Returns the current time, using the server's clock.

It's possible for servers to have a different value for network time, especially if they do not use some external mechanism for time synchronization (e.g. NTP or SNTP). This is fine.

This estimate is not directly visible to other servers over the protocol, but it is possible for them to make an educated guess if this server publishes proposals or validations.

Note
The network time is adjusted for the "XRPL epoch" which was arbitrarily defined as 2000-01-01T00:00:00Z by Arthur Britto and David Schwartz during early development of the code. No rationale has been provided for this curious and annoying, but otherwise unimportant, choice.

Implements beast::AbstractClock< NetClock >.

Definition at line 44 of file TimeKeeper.h.

◆ closeTime()

time_point xrpl::TimeKeeper::closeTime ( ) const
nodiscard

Returns the predicted close time, in network time.

The predicted close time represents the notional "center" of the network. Each server assumes that its clock is correct and tries to pull the close time towards its measure of network time.

Definition at line 56 of file TimeKeeper.h.

◆ closeOffset()

std::chrono::seconds xrpl::TimeKeeper::closeOffset ( ) const
nodiscard

Definition at line 63 of file TimeKeeper.h.

◆ adjustCloseTime()

std::chrono::seconds xrpl::TimeKeeper::adjustCloseTime ( std::chrono::seconds by)

Adjust the close time, based on the network's view of time.

Definition at line 70 of file TimeKeeper.h.

Member Data Documentation

◆ closeOffset_

std::atomic<std::chrono::seconds> xrpl::TimeKeeper::closeOffset_
private

Definition at line 14 of file TimeKeeper.h.

◆ is_steady

bool const beast::AbstractClock< NetClock >::is_steady
staticinherited

Definition at line 43 of file abstract_clock.h.