| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.HardFork.History.Qry
Synopsis
- data Expr (f ∷ Type → Type) a where
- EVar ∷ ∀ (f ∷ Type → Type) a. f a → Expr f a
- ELit ∷ ∀ a (f ∷ Type → Type). Show a ⇒ a → Expr f a
- ELet ∷ ∀ (f ∷ Type → Type) a1 a. Expr f a1 → (f a1 → Expr f a) → Expr f a
- EPair ∷ ∀ (f ∷ Type → Type) a1 b. Expr f a1 → Expr f b → Expr f (a1, b)
- EFst ∷ ∀ (f ∷ Type → Type) a b. Expr f (a, b) → Expr f a
- ESnd ∷ ∀ (f ∷ Type → Type) a1 a. Expr f (a1, a) → Expr f a
- EAbsToRelTime ∷ ∀ (f ∷ Type → Type). Expr f RelativeTime → Expr f TimeInEra
- EAbsToRelSlot ∷ ∀ (f ∷ Type → Type). Expr f SlotNo → Expr f SlotInEra
- EAbsToRelEpoch ∷ ∀ (f ∷ Type → Type). Expr f EpochNo → Expr f EpochInEra
- EAbsToRelPerasRoundNo ∷ ∀ (f ∷ Type → Type). Expr f PerasRoundNo → Expr f (PerasEnabled PerasRoundNoInEra)
- ERelToAbsTime ∷ ∀ (f ∷ Type → Type). Expr f TimeInEra → Expr f RelativeTime
- ERelToAbsSlot ∷ ∀ (f ∷ Type → Type). Expr f (SlotInEra, TimeInSlot) → Expr f SlotNo
- ERelToAbsEpoch ∷ ∀ (f ∷ Type → Type). Expr f (EpochInEra, SlotInEpoch) → Expr f EpochNo
- ERelToAbsPerasRoundNo ∷ ∀ (f ∷ Type → Type). Expr f (PerasEnabled (PerasRoundNoInEra, SlotInPerasRound)) → Expr f (PerasEnabled PerasRoundNo)
- ERelTimeToSlot ∷ ∀ (f ∷ Type → Type). Expr f TimeInEra → Expr f (SlotInEra, TimeInSlot)
- ERelSlotToTime ∷ ∀ (f ∷ Type → Type). Expr f SlotInEra → Expr f TimeInEra
- ERelSlotToEpoch ∷ ∀ (f ∷ Type → Type). Expr f SlotInEra → Expr f (EpochInEra, SlotInEpoch)
- ERelEpochToSlot ∷ ∀ (f ∷ Type → Type). Expr f EpochInEra → Expr f SlotInEra
- ERelPerasRoundNoToSlot ∷ ∀ (f ∷ Type → Type). Expr f (PerasEnabled PerasRoundNoInEra) → Expr f (PerasEnabled SlotInEra)
- ERelSlotToPerasRoundNo ∷ ∀ (f ∷ Type → Type). Expr f SlotInEra → Expr f (PerasEnabled (PerasRoundNoInEra, SlotInPerasRound))
- ESlotLength ∷ ∀ (f ∷ Type → Type). Expr f SlotNo → Expr f SlotLength
- EEpochSize ∷ ∀ (f ∷ Type → Type). Expr f EpochNo → Expr f EpochSize
- EGenesisWindow ∷ ∀ (f ∷ Type → Type). Expr f SlotNo → Expr f GenesisWindow
- EPerasRoundLength ∷ ∀ (f ∷ Type → Type). Expr f PerasRoundNo → Expr f (PerasEnabled PerasRoundLength)
- data PastHorizonException = PastHorizon {
- pastHorizonCallStack ∷ CallStack
- pastHorizonExpression ∷ Some ClosedExpr
- pastHorizonSummary ∷ [EraSummary]
- qryFromExpr ∷ (∀ (f ∷ Type → Type). Expr f a) → Qry a
- newtype EraIndexed (xs ∷ [Type]) a = EraIndexed {
- eraIndexedToNS ∷ NS (K a ∷ Type → Type) xs
- forgetEraIndex ∷ ∀ (xs ∷ [Type]) a. EraIndexed xs a → a
- runQuery ∷ ∀ a (xs ∷ [Type]). HasCallStack ⇒ Qry a → Summary xs → Either PastHorizonException a
- runQueryEraIndexed ∷ ∀ a (xs ∷ [Type]). HasCallStack ⇒ Qry a → Summary xs → Either PastHorizonException (EraIndexed xs a)
- runQueryPure ∷ ∀ a (xs ∷ [Type]). HasCallStack ⇒ Qry a → Summary xs → a
- runQueryThrow ∷ ∀ m a (xs ∷ [Type]). (HasCallStack, MonadThrow m) ⇒ Qry a → Summary xs → m a
- data Qry a
- interpretQuery ∷ ∀ (xs ∷ [Type]) a. HasCallStack ⇒ Interpreter xs → Qry a → Either PastHorizonException a
- mkInterpreter ∷ ∀ (xs ∷ [Type]). Summary xs → Interpreter xs
- unsafeExtendSafeZone ∷ ∀ (xs ∷ [Type]). Interpreter xs → Interpreter xs
- data Interpreter (xs ∷ [Type])
- epochToSize ∷ EpochNo → Qry EpochSize
- epochToSlot ∷ EpochNo → Qry (SlotNo, EpochSize)
- epochToSlot' ∷ EpochNo → Qry SlotNo
- slotToEpoch ∷ SlotNo → Qry (EpochNo, Word64, Word64)
- slotToEpoch' ∷ SlotNo → Qry (EpochNo, Word64)
- slotToGenesisWindow ∷ ∀ (f ∷ Type → Type). SlotNo → Expr f GenesisWindow
- slotToSlotLength ∷ SlotNo → Qry SlotLength
- slotToWallclock ∷ SlotNo → Qry (RelativeTime, SlotLength)
- wallclockToSlot ∷ RelativeTime → Qry (SlotNo, NominalDiffTime, NominalDiffTime)
- perasRoundNoToSlot ∷ PerasRoundNo → Qry (PerasEnabled (SlotNo, PerasRoundLength))
- perasRoundNoToPerasRoundLength ∷ PerasRoundNo → Qry (PerasEnabled PerasRoundLength)
- slotToPerasRoundNo ∷ SlotNo → Qry (PerasEnabled (PerasRoundNo, Word64, Word64))
- slotToPerasRoundNo' ∷ SlotNo → Qry (PerasEnabled (PerasRoundNo, Word64))
- epochToPerasRoundInfo ∷ EpochNo → Qry (PerasEnabled EpochToPerasRoundInfo)
- data EpochToPerasRoundInfo = EpochToPerasRoundInfo {}
Qry
data Expr (f ∷ Type → Type) a where Source #
Query expressions in PHOAS
Constructors
| EVar ∷ ∀ (f ∷ Type → Type) a. f a → Expr f a | |
| ELit ∷ ∀ a (f ∷ Type → Type). Show a ⇒ a → Expr f a | |
| ELet ∷ ∀ (f ∷ Type → Type) a1 a. Expr f a1 → (f a1 → Expr f a) → Expr f a | |
| EPair ∷ ∀ (f ∷ Type → Type) a1 b. Expr f a1 → Expr f b → Expr f (a1, b) | |
| EFst ∷ ∀ (f ∷ Type → Type) a b. Expr f (a, b) → Expr f a | |
| ESnd ∷ ∀ (f ∷ Type → Type) a1 a. Expr f (a1, a) → Expr f a | |
| EAbsToRelTime ∷ ∀ (f ∷ Type → Type). Expr f RelativeTime → Expr f TimeInEra | |
| EAbsToRelSlot ∷ ∀ (f ∷ Type → Type). Expr f SlotNo → Expr f SlotInEra | |
| EAbsToRelEpoch ∷ ∀ (f ∷ Type → Type). Expr f EpochNo → Expr f EpochInEra | |
| EAbsToRelPerasRoundNo ∷ ∀ (f ∷ Type → Type). Expr f PerasRoundNo → Expr f (PerasEnabled PerasRoundNoInEra) | |
| ERelToAbsTime ∷ ∀ (f ∷ Type → Type). Expr f TimeInEra → Expr f RelativeTime | |
| ERelToAbsSlot ∷ ∀ (f ∷ Type → Type). Expr f (SlotInEra, TimeInSlot) → Expr f SlotNo | |
| ERelToAbsEpoch ∷ ∀ (f ∷ Type → Type). Expr f (EpochInEra, SlotInEpoch) → Expr f EpochNo | |
| ERelToAbsPerasRoundNo ∷ ∀ (f ∷ Type → Type). Expr f (PerasEnabled (PerasRoundNoInEra, SlotInPerasRound)) → Expr f (PerasEnabled PerasRoundNo) | |
| ERelTimeToSlot ∷ ∀ (f ∷ Type → Type). Expr f TimeInEra → Expr f (SlotInEra, TimeInSlot) | |
| ERelSlotToTime ∷ ∀ (f ∷ Type → Type). Expr f SlotInEra → Expr f TimeInEra | |
| ERelSlotToEpoch ∷ ∀ (f ∷ Type → Type). Expr f SlotInEra → Expr f (EpochInEra, SlotInEpoch) | |
| ERelEpochToSlot ∷ ∀ (f ∷ Type → Type). Expr f EpochInEra → Expr f SlotInEra | |
| ERelPerasRoundNoToSlot ∷ ∀ (f ∷ Type → Type). Expr f (PerasEnabled PerasRoundNoInEra) → Expr f (PerasEnabled SlotInEra) | |
| ERelSlotToPerasRoundNo ∷ ∀ (f ∷ Type → Type). Expr f SlotInEra → Expr f (PerasEnabled (PerasRoundNoInEra, SlotInPerasRound)) | |
| ESlotLength ∷ ∀ (f ∷ Type → Type). Expr f SlotNo → Expr f SlotLength | |
| EEpochSize ∷ ∀ (f ∷ Type → Type). Expr f EpochNo → Expr f EpochSize | |
| EGenesisWindow ∷ ∀ (f ∷ Type → Type). Expr f SlotNo → Expr f GenesisWindow | |
| EPerasRoundLength ∷ ∀ (f ∷ Type → Type). Expr f PerasRoundNo → Expr f (PerasEnabled PerasRoundLength) |
data PastHorizonException Source #
We tried to convert something that is past the horizon
That is, we tried to convert something that is past the point in time beyond which we lack information due to uncertainty about the next hard fork.
Constructors
| PastHorizon | |
Fields
| |
Instances
| Exception PastHorizonException Source # | |
| Show PastHorizonException Source # | |
Defined in Ouroboros.Consensus.HardFork.History.Qry Methods showsPrec ∷ Int → PastHorizonException → ShowS # show ∷ PastHorizonException → String # showList ∷ [PastHorizonException] → ShowS # | |
newtype EraIndexed (xs ∷ [Type]) a Source #
Result of a query, indexed by the era in which it was evaluated.
Constructors
| EraIndexed | |
Fields
| |
forgetEraIndex ∷ ∀ (xs ∷ [Type]) a. EraIndexed xs a → a Source #
Collapse the result of an era-indexed query
runQuery ∷ ∀ a (xs ∷ [Type]). HasCallStack ⇒ Qry a → Summary xs → Either PastHorizonException a Source #
Run a query
Unlike an Expr, which is evaluated in a single era, a Qry is evaluated
against all eras. Only if all Exprs embedded in the Qry can be
evaluated in the same era (we don't want to mix properties of different
eras in one query) do we return the result. If there is no era in which we
can evaluate all Exprs in the Qry, we report a PastHorizonException.
NOTE: this means that queries about separate eras have to be run separately, they should not be composed into a single query. How could we know to which era which relative slot/time refers?
NOTE: runQuery is implemented in terms of runQueryEraIndexed, collapsing
the resulting NS wrapper.
runQueryEraIndexed ∷ ∀ a (xs ∷ [Type]). HasCallStack ⇒ Qry a → Summary xs → Either PastHorizonException (EraIndexed xs a) Source #
Like runQuery, but returns the result tagged with the era index in
which the query was successfully evaluated.
While runQuery collapses the era information and returns a plain value,
runQueryEraIndexed preserves it by wrapping the result in an
NS (K a) xs, where the position in the sum indicates the era. This is
useful when the caller needs to know which era the query resolved in.
NOTE: Be careful, several queries have lax bound checks for era, so they may succeed in an era that is not the one you expect.
runQueryPure ∷ ∀ a (xs ∷ [Type]). HasCallStack ⇒ Qry a → Summary xs → a Source #
runQueryThrow ∷ ∀ m a (xs ∷ [Type]). (HasCallStack, MonadThrow m) ⇒ Qry a → Summary xs → m a Source #
opaque
Query
Qry adds a monadic interface on top of Expr. Although means that Qry
itself is not showable, the PastHorizonException can nonetheless show the
offending expression alongside the Summary against which it was evaluated.
Interpreter
interpretQuery ∷ ∀ (xs ∷ [Type]) a. HasCallStack ⇒ Interpreter xs → Qry a → Either PastHorizonException a Source #
mkInterpreter ∷ ∀ (xs ∷ [Type]). Summary xs → Interpreter xs Source #
unsafeExtendSafeZone ∷ ∀ (xs ∷ [Type]). Interpreter xs → Interpreter xs Source #
UNSAFE: extend the safe zone of the current era of the given Interpreter
to be unbounded, ignoring any future hard forks.
This only has effect when the Interpreter was obtained in an era that was
not the final one (in the final era, this is a no-op). The Interpreter
will be made to believe that the current era is the final era, making its
horizon unbounded, and thus never returning a PastHorizonException.
Use of this function is strongly discouraged, as it will ignore any future
hard forks, and the results produced by the Interpreter can thus be
incorrect.
opaque
data Interpreter (xs ∷ [Type]) Source #
Can be sent across the LocalStateQuery protocol to interpret queries in the wallet.
The Summary should be considered internal.
Instances
| Eq (Interpreter xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.History.Qry Methods (==) ∷ Interpreter xs → Interpreter xs → Bool # (/=) ∷ Interpreter xs → Interpreter xs → Bool # | |
| Show (Interpreter xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.History.Qry Methods showsPrec ∷ Int → Interpreter xs → ShowS # show ∷ Interpreter xs → String # showList ∷ [Interpreter xs] → ShowS # | |
| SListI xs ⇒ Serialise (Interpreter xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.History.Qry Methods encode ∷ Interpreter xs → Encoding Source # decode ∷ Decoder s (Interpreter xs) Source # encodeList ∷ [Interpreter xs] → Encoding Source # decodeList ∷ Decoder s [Interpreter xs] Source # | |
Specific queries
slotToGenesisWindow ∷ ∀ (f ∷ Type → Type). SlotNo → Expr f GenesisWindow Source #
slotToSlotLength ∷ SlotNo → Qry SlotLength Source #
Acquire a slot's length
slotToWallclock ∷ SlotNo → Qry (RelativeTime, SlotLength) Source #
Translate SlotNo to the UTCTime at the start of that slot
Additionally returns the length of the slot.
wallclockToSlot ∷ RelativeTime → Qry (SlotNo, NominalDiffTime, NominalDiffTime) Source #
Translate UTCTime to SlotNo
Additionally returns the time spent and time left in this slot.
perasRoundNoToSlot ∷ PerasRoundNo → Qry (PerasEnabled (SlotNo, PerasRoundLength)) Source #
Translate PerasRoundNo to the SlotNo of the first slot in that Peras round
Additionally returns the length of the round.
perasRoundNoToPerasRoundLength ∷ PerasRoundNo → Qry (PerasEnabled PerasRoundLength) Source #
It is safe to rely on the era index in which this query resolves, because
EPerasRoundLength inside perasRoundNoPerasRoundLengthExpr has strict
era boundary guards.
slotToPerasRoundNo ∷ SlotNo → Qry (PerasEnabled (PerasRoundNo, Word64, Word64)) Source #
Translate SlotNo to its corresponding PerasRoundNo
Additionally returns the relative slot within this round and how many slots are left in this round.
epochToPerasRoundInfo ∷ EpochNo → Qry (PerasEnabled EpochToPerasRoundInfo) Source #
It is safe to rely on the era index in which this query resolves, because
EPerasRoundLength inside perasRoundNoPerasRoundLengthExpr has strict
era boundary guards.
data EpochToPerasRoundInfo Source #
Information about the Peras rounds that correspond to a given epoch.
Constructors
| EpochToPerasRoundInfo | |