{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Ouroboros.Consensus.Peras.Context
(
BoundedPerasEpochContext (..)
, withinEpochContext
, PerasEpochContextResolver (..)
, PerasEpochContextNotFoundForRound (..)
, resolveRoundNo
, perasEpochContextResolverBounds
, PerasEpochContextResolverHandle (..)
, mockPerasEpochContextResolverHandle
, withResolvedRoundNo
, StateSupportsPerasEpochContext (..)
, mkBoundedPerasEpochContextWith
, initPerasEpochContextResolver
, tickPerasEpochContextResolver
, TimeResolutionContext (..)
, runQueryWithContext
, runQueryEraIndexedWithContext
, TimeResolutionContextHandle (..)
, runQueryWithContextHandle
, EpochCrossing (..)
, DetectNextEpochError
, isNextEpoch
)
where
import Cardano.Binary
( FromCBOR (..)
, ToCBOR (..)
, decodeListLen
, decodeListLenOf
, encodeListLen
)
import Cardano.Prelude (maybeToEither)
import Control.Exception (Exception)
import Control.Monad.Class.MonadSTM (STM)
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString.Char8 as ByteString
import Data.Data (Proxy (..))
import Data.Kind (Type)
import Data.SOP (HCollapse (..), K (..))
import Data.SOP.Constraint (All, Top)
import Data.SOP.Index (himap, injectNS)
import Data.Typeable (Typeable)
import Data.Word (Word8)
import GHC.Generics (Generic)
import Ouroboros.Consensus.Block.Abstract
( BlockProtocol
, EpochNo (..)
, SlotNo
, WithOrigin (..)
)
import Ouroboros.Consensus.Block.SupportsPeras
( BlockSupportsPeras (..)
, IsPerasError (..)
, PerasEpochContext (..)
, PerasRoundNo
, PerasVotingCommittee
, PerasVotingCommitteeInput
)
import Ouroboros.Consensus.Committee.Class (CryptoSupportsVotingCommittee)
import qualified Ouroboros.Consensus.Committee.Class as Committee
import Ouroboros.Consensus.HardFork.Abstract (HasHardForkHistory (..))
import Ouroboros.Consensus.HardFork.History.Qry
( EpochToPerasRoundInfo (..)
, EraIndexed (..)
, PastHorizonException
, Qry
, epochToPerasRoundInfo
, runQuery
, runQueryEraIndexed
, slotToEpoch'
)
import Ouroboros.Consensus.HeaderValidation
( HeaderState
, Ticked
, annTipSlotNo
, headerStateTip
)
import Ouroboros.Consensus.Ledger.Abstract (EmptyMK, LedgerConfig, LedgerState)
import Ouroboros.Consensus.Ledger.SupportsPeras (LedgerStateSupportsPeras (..))
import Ouroboros.Consensus.Peras.Params
( PerasEnabled
, perasEnabledToMaybe
, pattern NoPerasEnabled
, pattern PerasEnabled
)
import Ouroboros.Consensus.Protocol.Abstract
( ChainDepStateSupportsPeras
, ConsensusProtocol (..)
)
import Ouroboros.Consensus.Storage.Serialisation
( DecodeDisk (..)
, EncodeDisk (..)
)
import Ouroboros.Consensus.Util.IOLike
( IOLike
, MonadSTM
, MonadThrow
, NoThunks (..)
, newTVarIO
, readTVar
, throwSTM
)
data BoundedPerasEpochContext blk
= BoundedPerasEpochContext
{ forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo :: PerasRoundNo
, forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo :: PerasRoundNo
, forall blk. BoundedPerasEpochContext blk -> PerasEpochContext blk
epochContext :: PerasEpochContext blk
}
deriving instance
Show (PerasEpochContext blk) =>
Show (BoundedPerasEpochContext blk)
deriving instance
Eq (PerasEpochContext blk) =>
Eq (BoundedPerasEpochContext blk)
deriving instance
NoThunks (PerasEpochContext blk) =>
NoThunks (BoundedPerasEpochContext blk)
deriving instance
Generic (BoundedPerasEpochContext blk)
instance
( Typeable blk
, FromCBOR (PerasVotingCommittee blk)
) =>
FromCBOR (BoundedPerasEpochContext blk)
where
fromCBOR :: forall s. Decoder s (BoundedPerasEpochContext blk)
fromCBOR = do
Int -> Decoder s ()
forall s. Int -> Decoder s ()
decodeListLenOf Int
3
startPerasRoundNo <- Decoder s PerasRoundNo
forall s. Decoder s PerasRoundNo
forall a s. FromCBOR a => Decoder s a
fromCBOR
endPerasRoundNo <- fromCBOR
epochContext <- fromCBOR
pure
BoundedPerasEpochContext
{ startPerasRoundNo
, endPerasRoundNo
, epochContext
}
instance
( Typeable blk
, ToCBOR (PerasVotingCommittee blk)
) =>
ToCBOR (BoundedPerasEpochContext blk)
where
toCBOR :: BoundedPerasEpochContext blk -> Encoding
toCBOR
BoundedPerasEpochContext
{ PerasRoundNo
startPerasRoundNo :: forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo :: PerasRoundNo
startPerasRoundNo
, PerasRoundNo
endPerasRoundNo :: forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo :: PerasRoundNo
endPerasRoundNo
, PerasEpochContext blk
epochContext :: forall blk. BoundedPerasEpochContext blk -> PerasEpochContext blk
epochContext :: PerasEpochContext blk
epochContext
} =
Word -> Encoding
encodeListLen Word
3
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PerasRoundNo -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR PerasRoundNo
startPerasRoundNo
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PerasRoundNo -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR PerasRoundNo
endPerasRoundNo
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PerasEpochContext blk -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR PerasEpochContext blk
epochContext
instance
FromCBOR (BoundedPerasEpochContext blk) =>
DecodeDisk blk (BoundedPerasEpochContext blk)
where
decodeDisk :: CodecConfig blk
-> forall s. Decoder s (BoundedPerasEpochContext blk)
decodeDisk CodecConfig blk
_ccfg = Decoder s (BoundedPerasEpochContext blk)
forall s. Decoder s (BoundedPerasEpochContext blk)
forall a s. FromCBOR a => Decoder s a
fromCBOR
instance
ToCBOR (BoundedPerasEpochContext blk) =>
EncodeDisk blk (BoundedPerasEpochContext blk)
where
encodeDisk :: CodecConfig blk -> BoundedPerasEpochContext blk -> Encoding
encodeDisk CodecConfig blk
_ccfg = BoundedPerasEpochContext blk -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
withinEpochContext ::
PerasRoundNo ->
BoundedPerasEpochContext blk ->
Maybe (PerasEpochContext blk)
withinEpochContext :: forall blk.
PerasRoundNo
-> BoundedPerasEpochContext blk -> Maybe (PerasEpochContext blk)
withinEpochContext PerasRoundNo
roundNo BoundedPerasEpochContext blk
boundedContext
| PerasRoundNo
roundNo PerasRoundNo -> PerasRoundNo -> Bool
forall a. Ord a => a -> a -> Bool
>= BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo BoundedPerasEpochContext blk
boundedContext
Bool -> Bool -> Bool
&& PerasRoundNo
roundNo PerasRoundNo -> PerasRoundNo -> Bool
forall a. Ord a => a -> a -> Bool
< BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo BoundedPerasEpochContext blk
boundedContext =
PerasEpochContext blk -> Maybe (PerasEpochContext blk)
forall a. a -> Maybe a
Just (BoundedPerasEpochContext blk -> PerasEpochContext blk
forall blk. BoundedPerasEpochContext blk -> PerasEpochContext blk
epochContext BoundedPerasEpochContext blk
boundedContext)
| Bool
otherwise =
Maybe (PerasEpochContext blk)
forall a. Maybe a
Nothing
data PerasEpochContextResolver blk
=
PerasEpochContextResolverError
!String
|
PerasEpochContextResolver
!(PerasEnabled (BoundedPerasEpochContext blk))
!(PerasEnabled (BoundedPerasEpochContext blk))
deriving instance
Show (PerasEpochContext blk) =>
Show (PerasEpochContextResolver blk)
deriving instance
Eq (PerasEpochContext blk) =>
Eq (PerasEpochContextResolver blk)
deriving instance
NoThunks (PerasEpochContext blk) =>
NoThunks (PerasEpochContextResolver blk)
deriving instance
Generic (PerasEpochContextResolver blk)
instance
( Typeable blk
, FromCBOR (PerasVotingCommittee blk)
) =>
FromCBOR (PerasEpochContextResolver blk)
where
fromCBOR :: forall s. Decoder s (PerasEpochContextResolver blk)
fromCBOR = do
len <- Decoder s Int
forall s. Decoder s Int
decodeListLen
tag <- fromCBOR @Word8
case (len, tag) of
(Int
2, Word8
0) -> do
reason <- ByteString -> String
ByteString.unpack (ByteString -> String) -> Decoder s ByteString -> Decoder s String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s ByteString
forall s. Decoder s ByteString
forall a s. FromCBOR a => Decoder s a
fromCBOR
pure $ PerasEpochContextResolverError reason
(Int
3, Word8
1) -> do
curr <- Decoder s (PerasEnabled (BoundedPerasEpochContext blk))
forall s. Decoder s (PerasEnabled (BoundedPerasEpochContext blk))
forall a s. FromCBOR a => Decoder s a
fromCBOR
prev <- fromCBOR
pure $ PerasEpochContextResolver curr prev
(Int, Word8)
_ ->
String -> Decoder s (PerasEpochContextResolver blk)
forall a. HasCallStack => String -> Decoder s a
forall (m :: * -> *) a.
(MonadFail m, HasCallStack) =>
String -> m a
fail (String -> Decoder s (PerasEpochContextResolver blk))
-> String -> Decoder s (PerasEpochContextResolver blk)
forall a b. (a -> b) -> a -> b
$
String
"PerasEpochContextResolver: unexpected list length and tag: "
String -> ShowS
forall a. Semigroup a => a -> a -> a
<> (Int, Word8) -> String
forall a. Show a => a -> String
show (Int
len, Word8
tag)
instance
( Typeable blk
, ToCBOR (PerasVotingCommittee blk)
) =>
ToCBOR (PerasEpochContextResolver blk)
where
toCBOR :: PerasEpochContextResolver blk -> Encoding
toCBOR = \case
PerasEpochContextResolverError String
reason ->
Word -> Encoding
encodeListLen Word
2
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Word8
0 :: Word8)
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ByteString -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (String -> ByteString
ByteString.pack String
reason)
PerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
curr PerasEnabled (BoundedPerasEpochContext blk)
prev ->
Word -> Encoding
encodeListLen Word
3
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Word8
1 :: Word8)
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PerasEnabled (BoundedPerasEpochContext blk) -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR PerasEnabled (BoundedPerasEpochContext blk)
curr
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PerasEnabled (BoundedPerasEpochContext blk) -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR PerasEnabled (BoundedPerasEpochContext blk)
prev
instance
FromCBOR (PerasEpochContextResolver blk) =>
DecodeDisk blk (PerasEpochContextResolver blk)
where
decodeDisk :: CodecConfig blk
-> forall s. Decoder s (PerasEpochContextResolver blk)
decodeDisk CodecConfig blk
_ccfg = Decoder s (PerasEpochContextResolver blk)
forall s. Decoder s (PerasEpochContextResolver blk)
forall a s. FromCBOR a => Decoder s a
fromCBOR
instance
ToCBOR (PerasEpochContextResolver blk) =>
EncodeDisk blk (PerasEpochContextResolver blk)
where
encodeDisk :: CodecConfig blk -> PerasEpochContextResolver blk -> Encoding
encodeDisk CodecConfig blk
_ccfg = PerasEpochContextResolver blk -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
data PerasEpochContextNotFoundForRound
= PerasEpochContextNotFoundForRound
!PerasRoundNo
!String
deriving (PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool
(PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool)
-> (PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool)
-> Eq PerasEpochContextNotFoundForRound
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool
== :: PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool
$c/= :: PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool
/= :: PerasEpochContextNotFoundForRound
-> PerasEpochContextNotFoundForRound -> Bool
Eq, Int -> PerasEpochContextNotFoundForRound -> ShowS
[PerasEpochContextNotFoundForRound] -> ShowS
PerasEpochContextNotFoundForRound -> String
(Int -> PerasEpochContextNotFoundForRound -> ShowS)
-> (PerasEpochContextNotFoundForRound -> String)
-> ([PerasEpochContextNotFoundForRound] -> ShowS)
-> Show PerasEpochContextNotFoundForRound
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PerasEpochContextNotFoundForRound -> ShowS
showsPrec :: Int -> PerasEpochContextNotFoundForRound -> ShowS
$cshow :: PerasEpochContextNotFoundForRound -> String
show :: PerasEpochContextNotFoundForRound -> String
$cshowList :: [PerasEpochContextNotFoundForRound] -> ShowS
showList :: [PerasEpochContextNotFoundForRound] -> ShowS
Show, (forall x.
PerasEpochContextNotFoundForRound
-> Rep PerasEpochContextNotFoundForRound x)
-> (forall x.
Rep PerasEpochContextNotFoundForRound x
-> PerasEpochContextNotFoundForRound)
-> Generic PerasEpochContextNotFoundForRound
forall x.
Rep PerasEpochContextNotFoundForRound x
-> PerasEpochContextNotFoundForRound
forall x.
PerasEpochContextNotFoundForRound
-> Rep PerasEpochContextNotFoundForRound x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
PerasEpochContextNotFoundForRound
-> Rep PerasEpochContextNotFoundForRound x
from :: forall x.
PerasEpochContextNotFoundForRound
-> Rep PerasEpochContextNotFoundForRound x
$cto :: forall x.
Rep PerasEpochContextNotFoundForRound x
-> PerasEpochContextNotFoundForRound
to :: forall x.
Rep PerasEpochContextNotFoundForRound x
-> PerasEpochContextNotFoundForRound
Generic, Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo)
Proxy PerasEpochContextNotFoundForRound -> String
(Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo))
-> (Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo))
-> (Proxy PerasEpochContextNotFoundForRound -> String)
-> NoThunks PerasEpochContextNotFoundForRound
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo)
noThunks :: Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo)
wNoThunks :: Context
-> PerasEpochContextNotFoundForRound -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy PerasEpochContextNotFoundForRound -> String
showTypeOf :: Proxy PerasEpochContextNotFoundForRound -> String
NoThunks, Show PerasEpochContextNotFoundForRound
Typeable PerasEpochContextNotFoundForRound
(Typeable PerasEpochContextNotFoundForRound,
Show PerasEpochContextNotFoundForRound) =>
(PerasEpochContextNotFoundForRound -> SomeException)
-> (SomeException -> Maybe PerasEpochContextNotFoundForRound)
-> (PerasEpochContextNotFoundForRound -> String)
-> (PerasEpochContextNotFoundForRound -> Bool)
-> Exception PerasEpochContextNotFoundForRound
SomeException -> Maybe PerasEpochContextNotFoundForRound
PerasEpochContextNotFoundForRound -> Bool
PerasEpochContextNotFoundForRound -> String
PerasEpochContextNotFoundForRound -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> (e -> Bool)
-> Exception e
$ctoException :: PerasEpochContextNotFoundForRound -> SomeException
toException :: PerasEpochContextNotFoundForRound -> SomeException
$cfromException :: SomeException -> Maybe PerasEpochContextNotFoundForRound
fromException :: SomeException -> Maybe PerasEpochContextNotFoundForRound
$cdisplayException :: PerasEpochContextNotFoundForRound -> String
displayException :: PerasEpochContextNotFoundForRound -> String
$cbacktraceDesired :: PerasEpochContextNotFoundForRound -> Bool
backtraceDesired :: PerasEpochContextNotFoundForRound -> Bool
Exception)
newPerasEpochContextResolver ::
PerasEnabled (BoundedPerasEpochContext blk) ->
PerasEpochContextResolver blk
newPerasEpochContextResolver :: forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
newPerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
currEpochContext =
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
PerasEpochContextResolver
PerasEnabled (BoundedPerasEpochContext blk)
currEpochContext
PerasEnabled (BoundedPerasEpochContext blk)
forall a. PerasEnabled a
NoPerasEnabled
advancePerasEpochContextResolver ::
PerasEpochContextResolver blk ->
PerasEnabled (BoundedPerasEpochContext blk) ->
PerasEpochContextResolver blk
advancePerasEpochContextResolver :: forall blk.
PerasEpochContextResolver blk
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
advancePerasEpochContextResolver PerasEpochContextResolver blk
resolver PerasEnabled (BoundedPerasEpochContext blk)
newEpochContext =
case PerasEpochContextResolver blk
resolver of
PerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
currEpochContext PerasEnabled (BoundedPerasEpochContext blk)
_prevEpochContext ->
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
PerasEpochContextResolver
PerasEnabled (BoundedPerasEpochContext blk)
newEpochContext
PerasEnabled (BoundedPerasEpochContext blk)
currEpochContext
PerasEpochContextResolverError{} ->
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
newPerasEpochContextResolver
PerasEnabled (BoundedPerasEpochContext blk)
newEpochContext
resolveRoundNo ::
PerasEpochContextResolver blk ->
PerasRoundNo ->
Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
resolveRoundNo :: forall blk.
PerasEpochContextResolver blk
-> PerasRoundNo
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
resolveRoundNo PerasEpochContextResolver blk
resolver PerasRoundNo
roundNo = case PerasEpochContextResolver blk
resolver of
PerasEpochContextResolverError String
reason ->
PerasEpochContextNotFoundForRound
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
forall a b. a -> Either a b
Left (PerasEpochContextNotFoundForRound
-> Either
PerasEpochContextNotFoundForRound (PerasEpochContext blk))
-> PerasEpochContextNotFoundForRound
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
forall a b. (a -> b) -> a -> b
$
PerasRoundNo -> String -> PerasEpochContextNotFoundForRound
PerasEpochContextNotFoundForRound PerasRoundNo
roundNo String
reason
PerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
curr PerasEnabled (BoundedPerasEpochContext blk)
prev ->
case (String
-> PerasEnabled (BoundedPerasEpochContext blk)
-> Either String (PerasEpochContext blk)
lookupBounded String
"current" PerasEnabled (BoundedPerasEpochContext blk)
curr, String
-> PerasEnabled (BoundedPerasEpochContext blk)
-> Either String (PerasEpochContext blk)
lookupBounded String
"previous" PerasEnabled (BoundedPerasEpochContext blk)
prev) of
(Right PerasEpochContext blk
context, Either String (PerasEpochContext blk)
_) ->
PerasEpochContext blk
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
forall a b. b -> Either a b
Right PerasEpochContext blk
context
(Either String (PerasEpochContext blk)
_, Right PerasEpochContext blk
context) ->
PerasEpochContext blk
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
forall a b. b -> Either a b
Right PerasEpochContext blk
context
(Left String
reason1, Left String
reason2) ->
PerasEpochContextNotFoundForRound
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
forall a b. a -> Either a b
Left (PerasEpochContextNotFoundForRound
-> Either
PerasEpochContextNotFoundForRound (PerasEpochContext blk))
-> PerasEpochContextNotFoundForRound
-> Either PerasEpochContextNotFoundForRound (PerasEpochContext blk)
forall a b. (a -> b) -> a -> b
$
PerasRoundNo -> String -> PerasEpochContextNotFoundForRound
PerasEpochContextNotFoundForRound PerasRoundNo
roundNo (String
reason1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"; " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
reason2)
where
lookupBounded :: String
-> PerasEnabled (BoundedPerasEpochContext blk)
-> Either String (PerasEpochContext blk)
lookupBounded String
name PerasEnabled (BoundedPerasEpochContext blk)
mbContext = do
boundedContext <-
String
-> Maybe (BoundedPerasEpochContext blk)
-> Either String (BoundedPerasEpochContext blk)
forall e a. e -> Maybe a -> Either e a
maybeToEither
(String
"no " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
name String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" epoch context available because Peras isn't enabled")
(PerasEnabled (BoundedPerasEpochContext blk)
-> Maybe (BoundedPerasEpochContext blk)
forall a. PerasEnabled a -> Maybe a
perasEnabledToMaybe PerasEnabled (BoundedPerasEpochContext blk)
mbContext)
maybeToEither
( name
<> " epoch context available, but roundNo "
<> show roundNo
<> " not within "
<> name
<> " epoch context bounds ["
<> show (startPerasRoundNo boundedContext)
<> ", "
<> show (endPerasRoundNo boundedContext)
<> ")"
)
(withinEpochContext roundNo boundedContext)
perasEpochContextResolverBounds ::
PerasEpochContextResolver blk ->
(PerasRoundNo, PerasRoundNo)
perasEpochContextResolverBounds :: forall blk.
PerasEpochContextResolver blk -> (PerasRoundNo, PerasRoundNo)
perasEpochContextResolverBounds = \case
PerasEpochContextResolverError String
_ ->
( PerasRoundNo
0
, PerasRoundNo
0
)
PerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
NoPerasEnabled PerasEnabled (BoundedPerasEpochContext blk)
NoPerasEnabled ->
( PerasRoundNo
0
, PerasRoundNo
0
)
PerasEpochContextResolver (PerasEnabled BoundedPerasEpochContext blk
curr) PerasEnabled (BoundedPerasEpochContext blk)
NoPerasEnabled ->
( BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo BoundedPerasEpochContext blk
curr
, BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo BoundedPerasEpochContext blk
curr
)
PerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
NoPerasEnabled (PerasEnabled BoundedPerasEpochContext blk
prev) ->
( BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo BoundedPerasEpochContext blk
prev
, BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo BoundedPerasEpochContext blk
prev
)
PerasEpochContextResolver (PerasEnabled BoundedPerasEpochContext blk
curr) (PerasEnabled BoundedPerasEpochContext blk
prev) ->
( PerasRoundNo -> PerasRoundNo -> PerasRoundNo
forall a. Ord a => a -> a -> a
min (BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo BoundedPerasEpochContext blk
curr) (BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
startPerasRoundNo BoundedPerasEpochContext blk
prev)
, PerasRoundNo -> PerasRoundNo -> PerasRoundNo
forall a. Ord a => a -> a -> a
max (BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo BoundedPerasEpochContext blk
curr) (BoundedPerasEpochContext blk -> PerasRoundNo
forall blk. BoundedPerasEpochContext blk -> PerasRoundNo
endPerasRoundNo BoundedPerasEpochContext blk
prev)
)
newtype PerasEpochContextResolverHandle m blk
= PerasEpochContextResolverHandle
{ forall (m :: * -> *) blk.
PerasEpochContextResolverHandle m blk
-> STM m (PerasEpochContextResolver blk)
getPerasEpochContextResolver :: STM m (PerasEpochContextResolver blk)
}
mockPerasEpochContextResolverHandle ::
( IOLike m
, NoThunks (PerasEpochContext blk)
) =>
PerasEpochContext blk ->
m (PerasEpochContextResolverHandle m blk)
mockPerasEpochContextResolverHandle :: forall (m :: * -> *) blk.
(IOLike m, NoThunks (PerasEpochContext blk)) =>
PerasEpochContext blk -> m (PerasEpochContextResolverHandle m blk)
mockPerasEpochContextResolverHandle PerasEpochContext blk
context = do
resolverVar <-
PerasEpochContextResolver blk
-> m (StrictTVar m (PerasEpochContextResolver blk))
forall (m :: * -> *) a.
(HasCallStack, MonadSTM m, NoThunks a) =>
a -> m (StrictTVar m a)
newTVarIO
( PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
PerasEpochContextResolver
(BoundedPerasEpochContext blk
-> PerasEnabled (BoundedPerasEpochContext blk)
forall a. a -> PerasEnabled a
PerasEnabled (PerasRoundNo
-> PerasRoundNo
-> PerasEpochContext blk
-> BoundedPerasEpochContext blk
forall blk.
PerasRoundNo
-> PerasRoundNo
-> PerasEpochContext blk
-> BoundedPerasEpochContext blk
BoundedPerasEpochContext PerasRoundNo
forall a. Bounded a => a
minBound PerasRoundNo
forall a. Bounded a => a
maxBound PerasEpochContext blk
context))
PerasEnabled (BoundedPerasEpochContext blk)
forall a. PerasEnabled a
NoPerasEnabled
)
pure $ PerasEpochContextResolverHandle (readTVar resolverVar)
withResolvedRoundNo ::
( MonadSTM m
, MonadThrow (STM m)
, Exception err
) =>
PerasEpochContextResolverHandle m blk ->
PerasRoundNo ->
(PerasEpochContext blk -> Either err a) ->
STM m a
withResolvedRoundNo :: forall (m :: * -> *) err blk a.
(MonadSTM m, MonadThrow (STM m), Exception err) =>
PerasEpochContextResolverHandle m blk
-> PerasRoundNo
-> (PerasEpochContext blk -> Either err a)
-> STM m a
withResolvedRoundNo PerasEpochContextResolverHandle m blk
handle PerasRoundNo
roundNo PerasEpochContext blk -> Either err a
k = do
resolver <- PerasEpochContextResolverHandle m blk
-> STM m (PerasEpochContextResolver blk)
forall (m :: * -> *) blk.
PerasEpochContextResolverHandle m blk
-> STM m (PerasEpochContextResolver blk)
getPerasEpochContextResolver PerasEpochContextResolverHandle m blk
handle
case resolveRoundNo resolver roundNo of
Left PerasEpochContextNotFoundForRound
err -> PerasEpochContextNotFoundForRound -> STM m a
forall (m :: * -> *) e a.
(MonadSTM m, MonadThrow (STM m), Exception e) =>
e -> STM m a
throwSTM PerasEpochContextNotFoundForRound
err
Right PerasEpochContext blk
context ->
case PerasEpochContext blk -> Either err a
k PerasEpochContext blk
context of
Left err
err -> err -> STM m a
forall (m :: * -> *) e a.
(MonadSTM m, MonadThrow (STM m), Exception e) =>
e -> STM m a
throwSTM err
err
Right a
a -> a -> STM m a
forall a. a -> STM m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
class
( HasHardForkHistory blk
, LedgerStateSupportsPeras (LedgerState blk)
, LedgerStateSupportsPeras (Ticked LedgerState blk)
, ChainDepStateSupportsPeras (ChainDepState (BlockProtocol blk))
, ChainDepStateSupportsPeras (Ticked (ChainDepState (BlockProtocol blk)))
, IsPerasError (PerasError blk) blk
, Show (PerasError blk)
, Show (PerasVotingCommittee blk)
, Eq (PerasVotingCommittee blk)
, NoThunks (PerasVotingCommittee blk)
, Typeable (PerasVotingCommittee blk)
, FromCBOR (PerasVotingCommittee blk)
, ToCBOR (PerasVotingCommittee blk)
, Show (PerasEpochContextResolver blk)
, Eq (PerasEpochContextResolver blk)
, NoThunks (PerasEpochContextResolver blk)
, Typeable (PerasEpochContextResolver blk)
, FromCBOR (PerasEpochContextResolver blk)
, ToCBOR (PerasEpochContextResolver blk)
, EncodeDisk blk (PerasEpochContextResolver blk)
, DecodeDisk blk (PerasEpochContextResolver blk)
) =>
StateSupportsPerasEpochContext blk
where
type MaybeEraIndexedEpochToPerasRoundInfo blk :: Type
fromMaybeEraIndexedEpochToPerasRoundInfo ::
proxy blk ->
MaybeEraIndexedEpochToPerasRoundInfo blk ->
EpochToPerasRoundInfo
toMaybeEraIndexedEpochToPerasRoundInfo ::
All Top (HardForkIndices blk) =>
proxy blk ->
EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo ->
MaybeEraIndexedEpochToPerasRoundInfo blk
mkBoundedPerasEpochContext ::
( LedgerStateSupportsPeras ledgerState
, ChainDepStateSupportsPeras chainDepState
) =>
MaybeEraIndexedEpochToPerasRoundInfo blk ->
ledgerState EmptyMK ->
chainDepState ->
Either
(PerasError blk)
(BoundedPerasEpochContext blk)
mkBoundedPerasEpochContextWith ::
( LedgerStateSupportsPeras ledgerState
, ChainDepStateSupportsPeras chainDepState
, CryptoSupportsVotingCommittee (PerasCrypto blk) (PerasVotingCommitteeScheme blk)
, MaybeEraIndexedEpochToPerasRoundInfo blk ~ EpochToPerasRoundInfo
, IsPerasError (PerasError blk) blk
) =>
( ( LedgerStateSupportsPeras ledgerState
, ChainDepStateSupportsPeras chainDepState
) =>
ledgerState EmptyMK ->
chainDepState ->
Either
(PerasError blk)
(PerasVotingCommitteeInput blk)
) ->
MaybeEraIndexedEpochToPerasRoundInfo blk ->
ledgerState EmptyMK ->
chainDepState ->
Either
(PerasError blk)
(BoundedPerasEpochContext blk)
mkBoundedPerasEpochContextWith :: forall (ledgerState :: MapKind -> *) chainDepState blk.
(LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState,
CryptoSupportsVotingCommittee
(PerasCrypto blk) (PerasVotingCommitteeScheme blk),
MaybeEraIndexedEpochToPerasRoundInfo blk ~ EpochToPerasRoundInfo,
IsPerasError (PerasError blk) blk) =>
((LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState) =>
ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (PerasVotingCommitteeInput blk))
-> MaybeEraIndexedEpochToPerasRoundInfo blk
-> ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (BoundedPerasEpochContext blk)
mkBoundedPerasEpochContextWith
(LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState) =>
ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (PerasVotingCommitteeInput blk)
mkPerasVotingCommitteeInput
MaybeEraIndexedEpochToPerasRoundInfo blk
epochToRoundInfo
ledgerState EmptyMK
ledgerState
chainDepState
headerState = do
committeeInput <-
ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (PerasVotingCommitteeInput blk)
(LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState) =>
ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (PerasVotingCommitteeInput blk)
mkPerasVotingCommitteeInput ledgerState EmptyMK
ledgerState chainDepState
headerState
committee <-
bimap injectVotingCommitteeError id $
Committee.mkVotingCommittee committeeInput
let params =
Proxy blk -> ledgerState EmptyMK -> PerasParams blk
forall (proxy :: * -> *) blk.
proxy blk -> ledgerState EmptyMK -> PerasParams blk
forall (ledgerState :: MapKind -> *) (proxy :: * -> *) blk.
LedgerStateSupportsPeras ledgerState =>
proxy blk -> ledgerState EmptyMK -> PerasParams blk
getPerasParams Proxy blk
forall {k} (t :: k). Proxy t
Proxy ledgerState EmptyMK
ledgerState
pure
BoundedPerasEpochContext
{ startPerasRoundNo =
etpriEpochStartPerasRound epochToRoundInfo
, endPerasRoundNo =
etpriEpochEndPerasRound epochToRoundInfo
, epochContext =
PerasEpochContext
{ pecParams =
params
, pecCommittee =
committee
}
}
initPerasEpochContextResolver ::
( All Top (HardForkIndices blk)
, StateSupportsPerasEpochContext blk
) =>
LedgerConfig blk ->
LedgerState blk EmptyMK ->
HeaderState blk ->
PerasEpochContextResolver blk
initPerasEpochContextResolver :: forall blk.
(All Top (HardForkIndices blk),
StateSupportsPerasEpochContext blk) =>
LedgerConfig blk
-> LedgerState blk EmptyMK
-> HeaderState blk
-> PerasEpochContextResolver blk
initPerasEpochContextResolver LedgerConfig blk
ledgerConfig LedgerState blk EmptyMK
ledgerState HeaderState blk
headerState =
case WithOrigin SlotNo
chainTipSlot of
WithOrigin SlotNo
Origin ->
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
newPerasEpochContextResolver PerasEnabled (BoundedPerasEpochContext blk)
forall a. PerasEnabled a
NoPerasEnabled
NotOrigin SlotNo
slotNo ->
case SlotNo
-> Either
PastHorizonException
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
resolveEpochToRoundInfo SlotNo
slotNo of
Left PastHorizonException
err ->
String -> PerasEpochContextResolver blk
forall blk. String -> PerasEpochContextResolver blk
PerasEpochContextResolverError (PastHorizonException -> String
forall a. Show a => a -> String
show PastHorizonException
err)
Right EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToPerasRoundInfo ->
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> LedgerState blk EmptyMK
-> HeaderState blk
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
forall blk (ledgerState :: MapKind -> *) chainDepState.
(All Top (HardForkIndices blk),
LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState,
StateSupportsPerasEpochContext blk) =>
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> ledgerState EmptyMK
-> chainDepState
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
embedBoundedEpochContext
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
newPerasEpochContextResolver
LedgerState blk EmptyMK
ledgerState
HeaderState blk
headerState
EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToPerasRoundInfo
where
chainTipSlot :: WithOrigin SlotNo
chainTipSlot =
(AnnTip blk -> SlotNo)
-> WithOrigin (AnnTip blk) -> WithOrigin SlotNo
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AnnTip blk -> SlotNo
forall blk. AnnTip blk -> SlotNo
annTipSlotNo (HeaderState blk -> WithOrigin (AnnTip blk)
forall blk. HeaderState blk -> WithOrigin (AnnTip blk)
headerStateTip HeaderState blk
headerState)
timeResolutionContext :: TimeResolutionContext blk
timeResolutionContext =
LedgerConfig blk
-> LedgerState blk EmptyMK -> TimeResolutionContext blk
forall blk (mk :: MapKind).
LedgerConfig blk -> LedgerState blk mk -> TimeResolutionContext blk
TimeResolutionContext LedgerConfig blk
ledgerConfig LedgerState blk EmptyMK
ledgerState
resolveEpochToRoundInfo :: SlotNo
-> Either
PastHorizonException
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
resolveEpochToRoundInfo SlotNo
slotNo = do
(epochNo, _) <-
TimeResolutionContext blk
-> Qry (EpochNo, Word64)
-> Either PastHorizonException (EpochNo, Word64)
forall blk a.
HasHardForkHistory blk =>
TimeResolutionContext blk -> Qry a -> Either PastHorizonException a
runQueryWithContext
TimeResolutionContext blk
timeResolutionContext
(SlotNo -> Qry (EpochNo, Word64)
slotToEpoch' SlotNo
slotNo)
runQueryEraIndexedWithContext
timeResolutionContext
(epochToPerasRoundInfo epochNo)
tickPerasEpochContextResolver ::
( All Top (HardForkIndices blk)
, StateSupportsPerasEpochContext blk
) =>
LedgerConfig blk ->
(PerasEpochContextResolver blk, LedgerState blk EmptyMK, HeaderState blk) ->
(SlotNo, Ticked LedgerState blk EmptyMK, Ticked (HeaderState blk)) ->
PerasEpochContextResolver blk
tickPerasEpochContextResolver :: forall blk.
(All Top (HardForkIndices blk),
StateSupportsPerasEpochContext blk) =>
LedgerConfig blk
-> (PerasEpochContextResolver blk, LedgerState blk EmptyMK,
HeaderState blk)
-> (SlotNo, Ticked LedgerState blk EmptyMK,
Ticked (HeaderState blk))
-> PerasEpochContextResolver blk
tickPerasEpochContextResolver
LedgerConfig blk
ledgerConfig
(PerasEpochContextResolver blk
perasEpochContextResolver, LedgerState blk EmptyMK
ledgerState, HeaderState blk
headerState)
(SlotNo
targetSlot, Ticked LedgerState blk EmptyMK
tickedLedger, Ticked (HeaderState blk)
tickedHeader) =
case ( TimeResolutionContext blk
-> WithOrigin SlotNo
-> SlotNo
-> Either
DetectNextEpochError
(EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
forall blk.
HasHardForkHistory blk =>
TimeResolutionContext blk
-> WithOrigin SlotNo
-> SlotNo
-> Either
DetectNextEpochError
(EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
isNextEpoch
TimeResolutionContext blk
timeResolutionContext
WithOrigin SlotNo
chainTipSlot
SlotNo
targetSlot
) of
Left DetectNextEpochError
err ->
String -> PerasEpochContextResolver blk
forall a. HasCallStack => String -> a
error (DetectNextEpochError -> String
forall a. Show a => a -> String
show DetectNextEpochError
err)
Right EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
SameEpoch ->
PerasEpochContextResolver blk
perasEpochContextResolver
Right (NextEpoch EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToPerasRoundInfo) ->
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> Ticked LedgerState blk EmptyMK
-> Ticked (HeaderState blk)
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
forall blk (ledgerState :: MapKind -> *) chainDepState.
(All Top (HardForkIndices blk),
LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState,
StateSupportsPerasEpochContext blk) =>
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> ledgerState EmptyMK
-> chainDepState
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
embedBoundedEpochContext
(PerasEpochContextResolver blk
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEpochContextResolver blk
-> PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
advancePerasEpochContextResolver PerasEpochContextResolver blk
perasEpochContextResolver)
Ticked LedgerState blk EmptyMK
tickedLedger
Ticked (HeaderState blk)
tickedHeader
EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToPerasRoundInfo
Right (ManyEpochsCrossed EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToPerasRoundInfo) ->
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> Ticked LedgerState blk EmptyMK
-> Ticked (HeaderState blk)
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
forall blk (ledgerState :: MapKind -> *) chainDepState.
(All Top (HardForkIndices blk),
LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState,
StateSupportsPerasEpochContext blk) =>
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> ledgerState EmptyMK
-> chainDepState
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
embedBoundedEpochContext
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
forall blk.
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
newPerasEpochContextResolver
Ticked LedgerState blk EmptyMK
tickedLedger
Ticked (HeaderState blk)
tickedHeader
EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToPerasRoundInfo
where
chainTipSlot :: WithOrigin SlotNo
chainTipSlot =
(AnnTip blk -> SlotNo)
-> WithOrigin (AnnTip blk) -> WithOrigin SlotNo
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AnnTip blk -> SlotNo
forall blk. AnnTip blk -> SlotNo
annTipSlotNo (HeaderState blk -> WithOrigin (AnnTip blk)
forall blk. HeaderState blk -> WithOrigin (AnnTip blk)
headerStateTip HeaderState blk
headerState)
timeResolutionContext :: TimeResolutionContext blk
timeResolutionContext =
LedgerConfig blk
-> LedgerState blk EmptyMK -> TimeResolutionContext blk
forall blk (mk :: MapKind).
LedgerConfig blk -> LedgerState blk mk -> TimeResolutionContext blk
TimeResolutionContext LedgerConfig blk
ledgerConfig LedgerState blk EmptyMK
ledgerState
embedBoundedEpochContext ::
forall blk ledgerState chainDepState.
( All Top (HardForkIndices blk)
, LedgerStateSupportsPeras ledgerState
, ChainDepStateSupportsPeras chainDepState
, StateSupportsPerasEpochContext blk
) =>
( PerasEnabled (BoundedPerasEpochContext blk) ->
PerasEpochContextResolver blk
) ->
ledgerState EmptyMK ->
chainDepState ->
EraIndexed (HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo) ->
PerasEpochContextResolver blk
embedBoundedEpochContext :: forall blk (ledgerState :: MapKind -> *) chainDepState.
(All Top (HardForkIndices blk),
LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState,
StateSupportsPerasEpochContext blk) =>
(PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk)
-> ledgerState EmptyMK
-> chainDepState
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEpochContextResolver blk
embedBoundedEpochContext
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
embed
ledgerState EmptyMK
ledgerState
chainDepState
chainDepState
EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToRoundInfo =
case EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> PerasEnabled
(EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo)
forall (xs :: [*]) a.
All Top xs =>
EraIndexed xs (PerasEnabled a) -> PerasEnabled (EraIndexed xs a)
collapseEraIndexed EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
eraIndexedEpochToRoundInfo of
PerasEnabled EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo
eiEpochToPerasRoundInfo ->
case ( MaybeEraIndexedEpochToPerasRoundInfo blk
-> ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (BoundedPerasEpochContext blk)
forall blk (ledgerState :: MapKind -> *) chainDepState.
(StateSupportsPerasEpochContext blk,
LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState) =>
MaybeEraIndexedEpochToPerasRoundInfo blk
-> ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (BoundedPerasEpochContext blk)
forall (ledgerState :: MapKind -> *) chainDepState.
(LedgerStateSupportsPeras ledgerState,
ChainDepStateSupportsPeras chainDepState) =>
MaybeEraIndexedEpochToPerasRoundInfo blk
-> ledgerState EmptyMK
-> chainDepState
-> Either (PerasError blk) (BoundedPerasEpochContext blk)
mkBoundedPerasEpochContext
( Proxy blk
-> EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo
-> MaybeEraIndexedEpochToPerasRoundInfo blk
forall blk (proxy :: * -> *).
(StateSupportsPerasEpochContext blk,
All Top (HardForkIndices blk)) =>
proxy blk
-> EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo
-> MaybeEraIndexedEpochToPerasRoundInfo blk
forall (proxy :: * -> *).
All Top (HardForkIndices blk) =>
proxy blk
-> EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo
-> MaybeEraIndexedEpochToPerasRoundInfo blk
toMaybeEraIndexedEpochToPerasRoundInfo
(forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @blk)
EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo
eiEpochToPerasRoundInfo
)
ledgerState EmptyMK
ledgerState
chainDepState
chainDepState
) of
Left PerasError blk
err ->
String -> PerasEpochContextResolver blk
forall blk. String -> PerasEpochContextResolver blk
PerasEpochContextResolverError (VoidPerasError blk -> String
forall a. Show a => a -> String
show VoidPerasError blk
PerasError blk
err)
Right BoundedPerasEpochContext blk
boundedContext ->
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
embed (BoundedPerasEpochContext blk
-> PerasEnabled (BoundedPerasEpochContext blk)
forall a. a -> PerasEnabled a
PerasEnabled BoundedPerasEpochContext blk
boundedContext)
PerasEnabled
(EraIndexed (HardForkIndices blk) EpochToPerasRoundInfo)
NoPerasEnabled ->
PerasEnabled (BoundedPerasEpochContext blk)
-> PerasEpochContextResolver blk
embed PerasEnabled (BoundedPerasEpochContext blk)
forall a. PerasEnabled a
NoPerasEnabled
where
collapseEraIndexed ::
All Top xs =>
EraIndexed xs (PerasEnabled a) ->
PerasEnabled (EraIndexed xs a)
collapseEraIndexed :: forall (xs :: [*]) a.
All Top xs =>
EraIndexed xs (PerasEnabled a) -> PerasEnabled (EraIndexed xs a)
collapseEraIndexed (EraIndexed NS (K (PerasEnabled a)) xs
ns) =
NS (K (PerasEnabled (EraIndexed xs a))) xs
-> CollapseTo NS (PerasEnabled (EraIndexed xs a))
forall (xs :: [*]) a.
SListIN NS xs =>
NS (K a) xs -> CollapseTo NS a
forall k l (h :: (k -> *) -> l -> *) (xs :: l) a.
(HCollapse h, SListIN h xs) =>
h (K a) xs -> CollapseTo h a
hcollapse (NS (K (PerasEnabled (EraIndexed xs a))) xs
-> CollapseTo NS (PerasEnabled (EraIndexed xs a)))
-> NS (K (PerasEnabled (EraIndexed xs a))) xs
-> CollapseTo NS (PerasEnabled (EraIndexed xs a))
forall a b. (a -> b) -> a -> b
$
(forall a.
Index xs a
-> K (PerasEnabled a) a -> K (PerasEnabled (EraIndexed xs a)) a)
-> NS (K (PerasEnabled a)) xs
-> NS (K (PerasEnabled (EraIndexed xs a))) xs
forall {k} (h :: (k -> *) -> [k] -> *) (xs :: [k]) (f1 :: k -> *)
(f2 :: k -> *).
(HAp h, SListI xs, Prod h ~ NP) =>
(forall (a :: k). Index xs a -> f1 a -> f2 a) -> h f1 xs -> h f2 xs
himap
( \Index xs a
idx (K PerasEnabled a
pea) ->
case PerasEnabled a
pea of
PerasEnabled a
a ->
PerasEnabled (EraIndexed xs a)
-> K (PerasEnabled (EraIndexed xs a)) a
forall k a (b :: k). a -> K a b
K (EraIndexed xs a -> PerasEnabled (EraIndexed xs a)
forall a. a -> PerasEnabled a
PerasEnabled (NS (K a) xs -> EraIndexed xs a
forall (xs :: [*]) a. NS (K a) xs -> EraIndexed xs a
EraIndexed (Index xs a -> K a a -> NS (K a) xs
forall {k} (f :: k -> *) (x :: k) (xs :: [k]).
All Top xs =>
Index xs x -> f x -> NS f xs
injectNS Index xs a
idx (a -> K a a
forall k a (b :: k). a -> K a b
K a
a))))
PerasEnabled a
NoPerasEnabled ->
PerasEnabled (EraIndexed xs a)
-> K (PerasEnabled (EraIndexed xs a)) a
forall k a (b :: k). a -> K a b
K PerasEnabled (EraIndexed xs a)
forall a. PerasEnabled a
NoPerasEnabled
)
NS (K (PerasEnabled a)) xs
ns
data TimeResolutionContext blk where
TimeResolutionContext ::
forall blk mk.
LedgerConfig blk ->
LedgerState blk mk ->
TimeResolutionContext blk
runQueryWithContext ::
HasHardForkHistory blk =>
TimeResolutionContext blk ->
Qry a ->
Either PastHorizonException a
runQueryWithContext :: forall blk a.
HasHardForkHistory blk =>
TimeResolutionContext blk -> Qry a -> Either PastHorizonException a
runQueryWithContext (TimeResolutionContext LedgerConfig blk
cfg LedgerState blk mk
state) Qry a
qry =
Qry a
-> Summary (HardForkIndices blk) -> Either PastHorizonException a
forall a (xs :: [*]).
HasCallStack =>
Qry a -> Summary xs -> Either PastHorizonException a
runQuery Qry a
qry (LedgerConfig blk
-> LedgerState blk mk -> Summary (HardForkIndices blk)
forall blk (mk :: MapKind).
HasHardForkHistory blk =>
LedgerConfig blk
-> LedgerState blk mk -> Summary (HardForkIndices blk)
forall (mk :: MapKind).
LedgerConfig blk
-> LedgerState blk mk -> Summary (HardForkIndices blk)
hardForkSummary LedgerConfig blk
cfg LedgerState blk mk
state)
runQueryEraIndexedWithContext ::
HasHardForkHistory blk =>
TimeResolutionContext blk ->
Qry a ->
Either PastHorizonException (EraIndexed (HardForkIndices blk) a)
runQueryEraIndexedWithContext :: forall blk a.
HasHardForkHistory blk =>
TimeResolutionContext blk
-> Qry a
-> Either PastHorizonException (EraIndexed (HardForkIndices blk) a)
runQueryEraIndexedWithContext (TimeResolutionContext LedgerConfig blk
cfg LedgerState blk mk
state) Qry a
qry =
Qry a
-> Summary (HardForkIndices blk)
-> Either PastHorizonException (EraIndexed (HardForkIndices blk) a)
forall a (xs :: [*]).
HasCallStack =>
Qry a
-> Summary xs -> Either PastHorizonException (EraIndexed xs a)
runQueryEraIndexed Qry a
qry (LedgerConfig blk
-> LedgerState blk mk -> Summary (HardForkIndices blk)
forall blk (mk :: MapKind).
HasHardForkHistory blk =>
LedgerConfig blk
-> LedgerState blk mk -> Summary (HardForkIndices blk)
forall (mk :: MapKind).
LedgerConfig blk
-> LedgerState blk mk -> Summary (HardForkIndices blk)
hardForkSummary LedgerConfig blk
cfg LedgerState blk mk
state)
newtype TimeResolutionContextHandle m blk
= TimeResolutionContextHandle
{ forall (m :: * -> *) blk.
TimeResolutionContextHandle m blk
-> STM m (TimeResolutionContext blk)
getTimeResolutionContext :: STM m (TimeResolutionContext blk)
}
runQueryWithContextHandle ::
(HasHardForkHistory blk, MonadSTM m) =>
TimeResolutionContextHandle m blk ->
Qry a ->
STM m (Either PastHorizonException a)
runQueryWithContextHandle :: forall blk (m :: * -> *) a.
(HasHardForkHistory blk, MonadSTM m) =>
TimeResolutionContextHandle m blk
-> Qry a -> STM m (Either PastHorizonException a)
runQueryWithContextHandle TimeResolutionContextHandle m blk
handle Qry a
qry = do
context <- TimeResolutionContextHandle m blk
-> STM m (TimeResolutionContext blk)
forall (m :: * -> *) blk.
TimeResolutionContextHandle m blk
-> STM m (TimeResolutionContext blk)
getTimeResolutionContext TimeResolutionContextHandle m blk
handle
pure (runQueryWithContext context qry)
data EpochCrossing a
=
SameEpoch
|
NextEpoch !a
|
ManyEpochsCrossed !a
deriving (Int -> EpochCrossing a -> ShowS
[EpochCrossing a] -> ShowS
EpochCrossing a -> String
(Int -> EpochCrossing a -> ShowS)
-> (EpochCrossing a -> String)
-> ([EpochCrossing a] -> ShowS)
-> Show (EpochCrossing a)
forall a. Show a => Int -> EpochCrossing a -> ShowS
forall a. Show a => [EpochCrossing a] -> ShowS
forall a. Show a => EpochCrossing a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> EpochCrossing a -> ShowS
showsPrec :: Int -> EpochCrossing a -> ShowS
$cshow :: forall a. Show a => EpochCrossing a -> String
show :: EpochCrossing a -> String
$cshowList :: forall a. Show a => [EpochCrossing a] -> ShowS
showList :: [EpochCrossing a] -> ShowS
Show, (forall a b. (a -> b) -> EpochCrossing a -> EpochCrossing b)
-> (forall a b. a -> EpochCrossing b -> EpochCrossing a)
-> Functor EpochCrossing
forall a b. a -> EpochCrossing b -> EpochCrossing a
forall a b. (a -> b) -> EpochCrossing a -> EpochCrossing b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> EpochCrossing a -> EpochCrossing b
fmap :: forall a b. (a -> b) -> EpochCrossing a -> EpochCrossing b
$c<$ :: forall a b. a -> EpochCrossing b -> EpochCrossing a
<$ :: forall a b. a -> EpochCrossing b -> EpochCrossing a
Functor, (forall m. Monoid m => EpochCrossing m -> m)
-> (forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m)
-> (forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m)
-> (forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b)
-> (forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b)
-> (forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b)
-> (forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b)
-> (forall a. (a -> a -> a) -> EpochCrossing a -> a)
-> (forall a. (a -> a -> a) -> EpochCrossing a -> a)
-> (forall a. EpochCrossing a -> [a])
-> (forall a. EpochCrossing a -> Bool)
-> (forall a. EpochCrossing a -> Int)
-> (forall a. Eq a => a -> EpochCrossing a -> Bool)
-> (forall a. Ord a => EpochCrossing a -> a)
-> (forall a. Ord a => EpochCrossing a -> a)
-> (forall a. Num a => EpochCrossing a -> a)
-> (forall a. Num a => EpochCrossing a -> a)
-> Foldable EpochCrossing
forall a. Eq a => a -> EpochCrossing a -> Bool
forall a. Num a => EpochCrossing a -> a
forall a. Ord a => EpochCrossing a -> a
forall m. Monoid m => EpochCrossing m -> m
forall a. EpochCrossing a -> Bool
forall a. EpochCrossing a -> Int
forall a. EpochCrossing a -> [a]
forall a. (a -> a -> a) -> EpochCrossing a -> a
forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m
forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b
forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => EpochCrossing m -> m
fold :: forall m. Monoid m => EpochCrossing m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> EpochCrossing a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b
foldr :: forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> EpochCrossing a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b
foldl :: forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> EpochCrossing a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> EpochCrossing a -> a
foldr1 :: forall a. (a -> a -> a) -> EpochCrossing a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> EpochCrossing a -> a
foldl1 :: forall a. (a -> a -> a) -> EpochCrossing a -> a
$ctoList :: forall a. EpochCrossing a -> [a]
toList :: forall a. EpochCrossing a -> [a]
$cnull :: forall a. EpochCrossing a -> Bool
null :: forall a. EpochCrossing a -> Bool
$clength :: forall a. EpochCrossing a -> Int
length :: forall a. EpochCrossing a -> Int
$celem :: forall a. Eq a => a -> EpochCrossing a -> Bool
elem :: forall a. Eq a => a -> EpochCrossing a -> Bool
$cmaximum :: forall a. Ord a => EpochCrossing a -> a
maximum :: forall a. Ord a => EpochCrossing a -> a
$cminimum :: forall a. Ord a => EpochCrossing a -> a
minimum :: forall a. Ord a => EpochCrossing a -> a
$csum :: forall a. Num a => EpochCrossing a -> a
sum :: forall a. Num a => EpochCrossing a -> a
$cproduct :: forall a. Num a => EpochCrossing a -> a
product :: forall a. Num a => EpochCrossing a -> a
Foldable, Functor EpochCrossing
Foldable EpochCrossing
(Functor EpochCrossing, Foldable EpochCrossing) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> EpochCrossing a -> f (EpochCrossing b))
-> (forall (f :: * -> *) a.
Applicative f =>
EpochCrossing (f a) -> f (EpochCrossing a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> EpochCrossing a -> m (EpochCrossing b))
-> (forall (m :: * -> *) a.
Monad m =>
EpochCrossing (m a) -> m (EpochCrossing a))
-> Traversable EpochCrossing
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
EpochCrossing (m a) -> m (EpochCrossing a)
forall (f :: * -> *) a.
Applicative f =>
EpochCrossing (f a) -> f (EpochCrossing a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> EpochCrossing a -> m (EpochCrossing b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> EpochCrossing a -> f (EpochCrossing b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> EpochCrossing a -> f (EpochCrossing b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> EpochCrossing a -> f (EpochCrossing b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
EpochCrossing (f a) -> f (EpochCrossing a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
EpochCrossing (f a) -> f (EpochCrossing a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> EpochCrossing a -> m (EpochCrossing b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> EpochCrossing a -> m (EpochCrossing b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
EpochCrossing (m a) -> m (EpochCrossing a)
sequence :: forall (m :: * -> *) a.
Monad m =>
EpochCrossing (m a) -> m (EpochCrossing a)
Traversable)
data DetectNextEpochError
=
DetectNextEpochPastHorizonError
PastHorizonException
|
DetectNextEpochNewSlotInPast
!SlotNo
!EpochNo
!SlotNo
!EpochNo
deriving (Int -> DetectNextEpochError -> ShowS
[DetectNextEpochError] -> ShowS
DetectNextEpochError -> String
(Int -> DetectNextEpochError -> ShowS)
-> (DetectNextEpochError -> String)
-> ([DetectNextEpochError] -> ShowS)
-> Show DetectNextEpochError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DetectNextEpochError -> ShowS
showsPrec :: Int -> DetectNextEpochError -> ShowS
$cshow :: DetectNextEpochError -> String
show :: DetectNextEpochError -> String
$cshowList :: [DetectNextEpochError] -> ShowS
showList :: [DetectNextEpochError] -> ShowS
Show, Show DetectNextEpochError
Typeable DetectNextEpochError
(Typeable DetectNextEpochError, Show DetectNextEpochError) =>
(DetectNextEpochError -> SomeException)
-> (SomeException -> Maybe DetectNextEpochError)
-> (DetectNextEpochError -> String)
-> (DetectNextEpochError -> Bool)
-> Exception DetectNextEpochError
SomeException -> Maybe DetectNextEpochError
DetectNextEpochError -> Bool
DetectNextEpochError -> String
DetectNextEpochError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> (e -> Bool)
-> Exception e
$ctoException :: DetectNextEpochError -> SomeException
toException :: DetectNextEpochError -> SomeException
$cfromException :: SomeException -> Maybe DetectNextEpochError
fromException :: SomeException -> Maybe DetectNextEpochError
$cdisplayException :: DetectNextEpochError -> String
displayException :: DetectNextEpochError -> String
$cbacktraceDesired :: DetectNextEpochError -> Bool
backtraceDesired :: DetectNextEpochError -> Bool
Exception)
isNextEpoch ::
HasHardForkHistory blk =>
TimeResolutionContext blk ->
WithOrigin SlotNo ->
SlotNo ->
Either
DetectNextEpochError
( EpochCrossing
( EraIndexed
(HardForkIndices blk)
(PerasEnabled EpochToPerasRoundInfo)
)
)
isNextEpoch :: forall blk.
HasHardForkHistory blk =>
TimeResolutionContext blk
-> WithOrigin SlotNo
-> SlotNo
-> Either
DetectNextEpochError
(EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
isNextEpoch TimeResolutionContext blk
context WithOrigin SlotNo
mbPrevSlot SlotNo
nextSlot = do
Either DetectNextEpochError (EpochCrossing EpochNo)
resolveEpochCrossing Either DetectNextEpochError (EpochCrossing EpochNo)
-> (EpochCrossing EpochNo
-> Either
DetectNextEpochError
(EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))))
-> Either
DetectNextEpochError
(EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
forall a b.
Either DetectNextEpochError a
-> (a -> Either DetectNextEpochError b)
-> Either DetectNextEpochError b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (EpochNo
-> Either
DetectNextEpochError
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
-> EpochCrossing EpochNo
-> Either
DetectNextEpochError
(EpochCrossing
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> EpochCrossing a -> f (EpochCrossing b)
traverse EpochNo
-> Either
DetectNextEpochError
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
resolvePerasInfoForEpoch
where
slotToEpochOrError :: SlotNo -> Either DetectNextEpochError EpochNo
slotToEpochOrError SlotNo
slot =
(PastHorizonException -> DetectNextEpochError)
-> ((EpochNo, Word64) -> EpochNo)
-> Either PastHorizonException (EpochNo, Word64)
-> Either DetectNextEpochError EpochNo
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: MapKind) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap PastHorizonException -> DetectNextEpochError
DetectNextEpochPastHorizonError (EpochNo, Word64) -> EpochNo
forall a b. (a, b) -> a
fst (Either PastHorizonException (EpochNo, Word64)
-> Either DetectNextEpochError EpochNo)
-> Either PastHorizonException (EpochNo, Word64)
-> Either DetectNextEpochError EpochNo
forall a b. (a -> b) -> a -> b
$
TimeResolutionContext blk
-> Qry (EpochNo, Word64)
-> Either PastHorizonException (EpochNo, Word64)
forall blk a.
HasHardForkHistory blk =>
TimeResolutionContext blk -> Qry a -> Either PastHorizonException a
runQueryWithContext TimeResolutionContext blk
context (Qry (EpochNo, Word64)
-> Either PastHorizonException (EpochNo, Word64))
-> Qry (EpochNo, Word64)
-> Either PastHorizonException (EpochNo, Word64)
forall a b. (a -> b) -> a -> b
$
SlotNo -> Qry (EpochNo, Word64)
slotToEpoch' SlotNo
slot
resolvePerasInfoForEpoch :: EpochNo
-> Either
DetectNextEpochError
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
resolvePerasInfoForEpoch EpochNo
epochNo =
(PastHorizonException -> DetectNextEpochError)
-> (EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
-> Either
PastHorizonException
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
-> Either
DetectNextEpochError
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: MapKind) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap PastHorizonException -> DetectNextEpochError
DetectNextEpochPastHorizonError EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
-> EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)
forall a. a -> a
id (Either
PastHorizonException
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
-> Either
DetectNextEpochError
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo)))
-> Either
PastHorizonException
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
-> Either
DetectNextEpochError
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
forall a b. (a -> b) -> a -> b
$
TimeResolutionContext blk
-> Qry (PerasEnabled EpochToPerasRoundInfo)
-> Either
PastHorizonException
(EraIndexed
(HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))
forall blk a.
HasHardForkHistory blk =>
TimeResolutionContext blk
-> Qry a
-> Either PastHorizonException (EraIndexed (HardForkIndices blk) a)
runQueryEraIndexedWithContext TimeResolutionContext blk
context (EpochNo -> Qry (PerasEnabled EpochToPerasRoundInfo)
epochToPerasRoundInfo EpochNo
epochNo)
resolveEpochCrossing :: Either DetectNextEpochError (EpochCrossing EpochNo)
resolveEpochCrossing =
case WithOrigin SlotNo
mbPrevSlot of
WithOrigin SlotNo
Origin -> do
nextEpoch <- SlotNo -> Either DetectNextEpochError EpochNo
slotToEpochOrError SlotNo
nextSlot
if
| EpochNo 0 <- nextEpoch ->
Right (NextEpoch nextEpoch)
| otherwise ->
Right (ManyEpochsCrossed nextEpoch)
NotOrigin SlotNo
prevSlot -> do
prevEpoch <- SlotNo -> Either DetectNextEpochError EpochNo
slotToEpochOrError SlotNo
prevSlot
nextEpoch <- slotToEpochOrError nextSlot
if
| prevEpoch == nextEpoch ->
Right SameEpoch
| prevEpoch < nextEpoch ->
if EpochNo (unEpochNo prevEpoch + 1) == nextEpoch
then Right (NextEpoch nextEpoch)
else Right (ManyEpochsCrossed nextEpoch)
| otherwise ->
Left
( DetectNextEpochNewSlotInPast
prevSlot
prevEpoch
nextSlot
nextEpoch
)