hydra-node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Chain.Direct.TimeHandle

Description

Module to deal with time in direct cardano chain layer. Defines the type for a PointInTime and a means to acquire one via a TimeHandle and queryTimeHandle.

Synopsis

Documentation

data TimeHandle Source #

Constructors

TimeHandle 

Fields

data TimeHandleParams Source #

Constructors

TimeHandleParams 

Fields

mkTimeHandle :: SlotNo -> SystemStart -> EraHistory -> TimeHandle Source #

Construct a time handle using current slot and given chain parameters. See queryTimeHandle to create one by querying a cardano-node.

slotToUTCTimeWith :: SystemStart -> EraHistory -> SlotNo -> Either Text UTCTime Source #

Convert a slot number to wall-clock time using the given chain parameters. Fails if the slot is outside the era history's horizon.

slotFromUTCTimeWith :: SystemStart -> EraHistory -> UTCTime -> Either Text SlotNo Source #

Look up the slot containing the given wall-clock time. Fails if the time is outside the era history's horizon.

newTimeHandleCache Source #

Arguments

:: MonadLabelledSTM m 
=> m SystemStart

How to query the system start (used once).

-> m EraHistory

How to (re-)query the era history.

-> m (SlotNo -> m TimeHandle) 

Create a cached variant of queryTimeHandle for converting a given slot: system start is queried once, era history is cached and only re-queried when the demanded slot cannot be converted with it any more (its horizon was outrun, e.g. after a hard fork or a long-lived cache). Should a freshly queried era history still not cover the slot, the returned handle reports the conversion failure to its consumer.

newCachedTimeHandle :: ChainBackend backend => (forall a. backend a -> IO a) -> IO (SlotNo -> IO TimeHandle) Source #

Create cached time conversions for the chain-sync path using the given backend runner. That path only converts block slots and never needs the chain tip, so this replaces three chain queries per block with cached values; see newTimeHandleCache for when the era history is re-queried.

queryTimeHandle :: (ChainBackend m, Monad m) => m TimeHandle Source #

Query the chain for system start and era history before constructing a TimeHandle using the slot at the tip of the network.