{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module Ouroboros.Consensus.Peras.Voting.View
( PerasQryException (..)
, PerasQry
, runPerasQry
, perasRoundStart
, perasChainAtCandidateBlock
, LatestCertSeenView (..)
, LatestCertOnChainView (..)
, PerasVotingView (..)
, mkPerasVotingView
)
where
import Cardano.Slotting.Slot (WithOrigin)
import Control.Exception (Exception)
import Control.Monad.Except (ExceptT, MonadError (..), runExceptT)
import Control.Monad.Reader (MonadReader (..), Reader, runReader)
import Ouroboros.Consensus.Block.Abstract
( GetHeader (..)
, Header
, SlotNo (..)
, castPoint
)
import Ouroboros.Consensus.Block.SupportsPeras
( HasPerasCertRound (..)
, PerasRoundNo (..)
, ValidatedPerasCert
, getPerasCertBoostedBlock
, getPerasCertRound
)
import Ouroboros.Consensus.BlockchainTime.WallClock.Types
( WithArrivalTime (..)
)
import Ouroboros.Consensus.HardFork.History.EraParams
( pattern NoPerasEnabled
, pattern PerasEnabled
)
import qualified Ouroboros.Consensus.HardFork.History.Qry as HF
import qualified Ouroboros.Consensus.HardFork.History.Summary as HF
import Ouroboros.Consensus.Peras.Params
( PerasBlockMinSlots (..)
, PerasParams (..)
)
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
import qualified Ouroboros.Network.AnchoredFragment as AF
data PerasQryException
=
PerasQryExceptionPastHorizon HF.PastHorizonException
|
PerasQryExceptionPerasDisabled
deriving (Int -> PerasQryException -> ShowS
[PerasQryException] -> ShowS
PerasQryException -> String
(Int -> PerasQryException -> ShowS)
-> (PerasQryException -> String)
-> ([PerasQryException] -> ShowS)
-> Show PerasQryException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PerasQryException -> ShowS
showsPrec :: Int -> PerasQryException -> ShowS
$cshow :: PerasQryException -> String
show :: PerasQryException -> String
$cshowList :: [PerasQryException] -> ShowS
showList :: [PerasQryException] -> ShowS
Show, Show PerasQryException
Typeable PerasQryException
(Typeable PerasQryException, Show PerasQryException) =>
(PerasQryException -> SomeException)
-> (SomeException -> Maybe PerasQryException)
-> (PerasQryException -> String)
-> (PerasQryException -> Bool)
-> Exception PerasQryException
SomeException -> Maybe PerasQryException
PerasQryException -> Bool
PerasQryException -> String
PerasQryException -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> (e -> Bool)
-> Exception e
$ctoException :: PerasQryException -> SomeException
toException :: PerasQryException -> SomeException
$cfromException :: SomeException -> Maybe PerasQryException
fromException :: SomeException -> Maybe PerasQryException
$cdisplayException :: PerasQryException -> String
displayException :: PerasQryException -> String
$cbacktraceDesired :: PerasQryException -> Bool
backtraceDesired :: PerasQryException -> Bool
Exception)
newtype PerasQry xs a
= PerasQry (ExceptT PerasQryException (Reader (HF.Summary xs)) a)
deriving newtype ((forall a b. (a -> b) -> PerasQry xs a -> PerasQry xs b)
-> (forall a b. a -> PerasQry xs b -> PerasQry xs a)
-> Functor (PerasQry xs)
forall (xs :: [*]) a b. a -> PerasQry xs b -> PerasQry xs a
forall (xs :: [*]) a b. (a -> b) -> PerasQry xs a -> PerasQry xs b
forall a b. a -> PerasQry xs b -> PerasQry xs a
forall a b. (a -> b) -> PerasQry xs a -> PerasQry xs b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (xs :: [*]) a b. (a -> b) -> PerasQry xs a -> PerasQry xs b
fmap :: forall a b. (a -> b) -> PerasQry xs a -> PerasQry xs b
$c<$ :: forall (xs :: [*]) a b. a -> PerasQry xs b -> PerasQry xs a
<$ :: forall a b. a -> PerasQry xs b -> PerasQry xs a
Functor, Functor (PerasQry xs)
Functor (PerasQry xs) =>
(forall a. a -> PerasQry xs a)
-> (forall a b.
PerasQry xs (a -> b) -> PerasQry xs a -> PerasQry xs b)
-> (forall a b c.
(a -> b -> c) -> PerasQry xs a -> PerasQry xs b -> PerasQry xs c)
-> (forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs b)
-> (forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs a)
-> Applicative (PerasQry xs)
forall (xs :: [*]). Functor (PerasQry xs)
forall (xs :: [*]) a. a -> PerasQry xs a
forall (xs :: [*]) a b.
PerasQry xs a -> PerasQry xs b -> PerasQry xs a
forall (xs :: [*]) a b.
PerasQry xs a -> PerasQry xs b -> PerasQry xs b
forall (xs :: [*]) a b.
PerasQry xs (a -> b) -> PerasQry xs a -> PerasQry xs b
forall (xs :: [*]) a b c.
(a -> b -> c) -> PerasQry xs a -> PerasQry xs b -> PerasQry xs c
forall a. a -> PerasQry xs a
forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs a
forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs b
forall a b. PerasQry xs (a -> b) -> PerasQry xs a -> PerasQry xs b
forall a b c.
(a -> b -> c) -> PerasQry xs a -> PerasQry xs b -> PerasQry xs c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall (xs :: [*]) a. a -> PerasQry xs a
pure :: forall a. a -> PerasQry xs a
$c<*> :: forall (xs :: [*]) a b.
PerasQry xs (a -> b) -> PerasQry xs a -> PerasQry xs b
<*> :: forall a b. PerasQry xs (a -> b) -> PerasQry xs a -> PerasQry xs b
$cliftA2 :: forall (xs :: [*]) a b c.
(a -> b -> c) -> PerasQry xs a -> PerasQry xs b -> PerasQry xs c
liftA2 :: forall a b c.
(a -> b -> c) -> PerasQry xs a -> PerasQry xs b -> PerasQry xs c
$c*> :: forall (xs :: [*]) a b.
PerasQry xs a -> PerasQry xs b -> PerasQry xs b
*> :: forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs b
$c<* :: forall (xs :: [*]) a b.
PerasQry xs a -> PerasQry xs b -> PerasQry xs a
<* :: forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs a
Applicative, Applicative (PerasQry xs)
Applicative (PerasQry xs) =>
(forall a b.
PerasQry xs a -> (a -> PerasQry xs b) -> PerasQry xs b)
-> (forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs b)
-> (forall a. a -> PerasQry xs a)
-> Monad (PerasQry xs)
forall (xs :: [*]). Applicative (PerasQry xs)
forall (xs :: [*]) a. a -> PerasQry xs a
forall (xs :: [*]) a b.
PerasQry xs a -> PerasQry xs b -> PerasQry xs b
forall (xs :: [*]) a b.
PerasQry xs a -> (a -> PerasQry xs b) -> PerasQry xs b
forall a. a -> PerasQry xs a
forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs b
forall a b. PerasQry xs a -> (a -> PerasQry xs b) -> PerasQry xs b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (xs :: [*]) a b.
PerasQry xs a -> (a -> PerasQry xs b) -> PerasQry xs b
>>= :: forall a b. PerasQry xs a -> (a -> PerasQry xs b) -> PerasQry xs b
$c>> :: forall (xs :: [*]) a b.
PerasQry xs a -> PerasQry xs b -> PerasQry xs b
>> :: forall a b. PerasQry xs a -> PerasQry xs b -> PerasQry xs b
$creturn :: forall (xs :: [*]) a. a -> PerasQry xs a
return :: forall a. a -> PerasQry xs a
Monad)
runPerasQry ::
HF.Summary xs ->
PerasQry xs a ->
Either PerasQryException a
runPerasQry :: forall (xs :: [*]) a.
Summary xs -> PerasQry xs a -> Either PerasQryException a
runPerasQry Summary xs
summary (PerasQry ExceptT PerasQryException (Reader (Summary xs)) a
qry) =
Reader (Summary xs) (Either PerasQryException a)
-> Summary xs -> Either PerasQryException a
forall r a. Reader r a -> r -> a
runReader (ExceptT PerasQryException (Reader (Summary xs)) a
-> Reader (Summary xs) (Either PerasQryException a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT PerasQryException (Reader (Summary xs)) a
qry) Summary xs
summary
perasCertArrivalSlot ::
WithArrivalTime cert ->
PerasQry xs SlotNo
perasCertArrivalSlot :: forall cert (xs :: [*]). WithArrivalTime cert -> PerasQry xs SlotNo
perasCertArrivalSlot WithArrivalTime cert
cert = ExceptT PerasQryException (Reader (Summary xs)) SlotNo
-> PerasQry xs SlotNo
forall (xs :: [*]) a.
ExceptT PerasQryException (Reader (Summary xs)) a -> PerasQry xs a
PerasQry (ExceptT PerasQryException (Reader (Summary xs)) SlotNo
-> PerasQry xs SlotNo)
-> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
-> PerasQry xs SlotNo
forall a b. (a -> b) -> a -> b
$ do
summary <- ExceptT PerasQryException (Reader (Summary xs)) (Summary xs)
forall r (m :: * -> *). MonadReader r m => m r
ask
case HF.runQuery (HF.wallclockToSlot (getArrivalTime cert)) summary of
Left PastHorizonException
pastHorizon ->
PerasQryException
-> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
forall a.
PerasQryException
-> ExceptT PerasQryException (Reader (Summary xs)) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PastHorizonException -> PerasQryException
PerasQryExceptionPastHorizon PastHorizonException
pastHorizon)
Right (SlotNo
slotNo, NominalDiffTime
_, NominalDiffTime
_) ->
SlotNo -> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
forall a. a -> ExceptT PerasQryException (Reader (Summary xs)) a
forall (m :: * -> *) a. Monad m => a -> m a
return SlotNo
slotNo
perasRoundStart ::
PerasRoundNo ->
PerasQry xs SlotNo
perasRoundStart :: forall (xs :: [*]). PerasRoundNo -> PerasQry xs SlotNo
perasRoundStart PerasRoundNo
roundNo = ExceptT PerasQryException (Reader (Summary xs)) SlotNo
-> PerasQry xs SlotNo
forall (xs :: [*]) a.
ExceptT PerasQryException (Reader (Summary xs)) a -> PerasQry xs a
PerasQry (ExceptT PerasQryException (Reader (Summary xs)) SlotNo
-> PerasQry xs SlotNo)
-> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
-> PerasQry xs SlotNo
forall a b. (a -> b) -> a -> b
$ do
summary <- ExceptT PerasQryException (Reader (Summary xs)) (Summary xs)
forall r (m :: * -> *). MonadReader r m => m r
ask
case HF.runQuery (HF.perasRoundNoToSlot roundNo) summary of
Left PastHorizonException
pastHorizon ->
PerasQryException
-> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
forall a.
PerasQryException
-> ExceptT PerasQryException (Reader (Summary xs)) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PastHorizonException -> PerasQryException
PerasQryExceptionPastHorizon PastHorizonException
pastHorizon)
Right PerasEnabled (SlotNo, PerasRoundLength)
NoPerasEnabled ->
PerasQryException
-> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
forall a.
PerasQryException
-> ExceptT PerasQryException (Reader (Summary xs)) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PerasQryException
PerasQryExceptionPerasDisabled
Right (PerasEnabled (SlotNo
slotNo, PerasRoundLength
_)) ->
SlotNo -> ExceptT PerasQryException (Reader (Summary xs)) SlotNo
forall a. a -> ExceptT PerasQryException (Reader (Summary xs)) a
forall (m :: * -> *) a. Monad m => a -> m a
return SlotNo
slotNo
perasChainAtCandidateBlock ::
GetHeader blk =>
PerasBlockMinSlots ->
PerasRoundNo ->
AnchoredFragment (Header blk) ->
PerasQry xs (AnchoredFragment (Header blk))
perasChainAtCandidateBlock :: forall blk (xs :: [*]).
GetHeader blk =>
PerasBlockMinSlots
-> PerasRoundNo
-> AnchoredFragment (Header blk)
-> PerasQry xs (AnchoredFragment (Header blk))
perasChainAtCandidateBlock PerasBlockMinSlots
blockMinSlots PerasRoundNo
currRoundNo AnchoredFragment (Header blk)
currChain = do
currRoundStart <- PerasRoundNo -> PerasQry xs SlotNo
forall (xs :: [*]). PerasRoundNo -> PerasQry xs SlotNo
perasRoundStart PerasRoundNo
currRoundNo
let _L = Word64 -> SlotNo
SlotNo (PerasBlockMinSlots -> Word64
unPerasBlockMinSlots PerasBlockMinSlots
blockMinSlots)
let candidateSlotHorizon
| SlotNo
currRoundStart SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
>= SlotNo
_L = SlotNo
currRoundStart SlotNo -> SlotNo -> SlotNo
forall a. Num a => a -> a -> a
- SlotNo
_L
| Bool
otherwise = Word64 -> SlotNo
SlotNo Word64
0
pure $ fst $ AF.splitAtSlot candidateSlotHorizon currChain
data LatestCertSeenView cert
= LatestCertSeenView
{ forall cert. LatestCertSeenView cert -> cert
lcsCert :: !cert
, forall cert. LatestCertSeenView cert -> SlotNo
lcsArrivalSlot :: !SlotNo
, forall cert. LatestCertSeenView cert -> SlotNo
lcsRoundStartSlot :: !SlotNo
, forall cert. LatestCertSeenView cert -> Bool
lcsCandidateBlockExtendsCert :: !Bool
}
deriving Int -> LatestCertSeenView cert -> ShowS
[LatestCertSeenView cert] -> ShowS
LatestCertSeenView cert -> String
(Int -> LatestCertSeenView cert -> ShowS)
-> (LatestCertSeenView cert -> String)
-> ([LatestCertSeenView cert] -> ShowS)
-> Show (LatestCertSeenView cert)
forall cert. Show cert => Int -> LatestCertSeenView cert -> ShowS
forall cert. Show cert => [LatestCertSeenView cert] -> ShowS
forall cert. Show cert => LatestCertSeenView cert -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall cert. Show cert => Int -> LatestCertSeenView cert -> ShowS
showsPrec :: Int -> LatestCertSeenView cert -> ShowS
$cshow :: forall cert. Show cert => LatestCertSeenView cert -> String
show :: LatestCertSeenView cert -> String
$cshowList :: forall cert. Show cert => [LatestCertSeenView cert] -> ShowS
showList :: [LatestCertSeenView cert] -> ShowS
Show
newtype LatestCertOnChainView cert
= LatestCertOnChainView
{ forall cert. LatestCertOnChainView cert -> cert
lcocCert :: cert
}
deriving Int -> LatestCertOnChainView cert -> ShowS
[LatestCertOnChainView cert] -> ShowS
LatestCertOnChainView cert -> String
(Int -> LatestCertOnChainView cert -> ShowS)
-> (LatestCertOnChainView cert -> String)
-> ([LatestCertOnChainView cert] -> ShowS)
-> Show (LatestCertOnChainView cert)
forall cert.
Show cert =>
Int -> LatestCertOnChainView cert -> ShowS
forall cert. Show cert => [LatestCertOnChainView cert] -> ShowS
forall cert. Show cert => LatestCertOnChainView cert -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall cert.
Show cert =>
Int -> LatestCertOnChainView cert -> ShowS
showsPrec :: Int -> LatestCertOnChainView cert -> ShowS
$cshow :: forall cert. Show cert => LatestCertOnChainView cert -> String
show :: LatestCertOnChainView cert -> String
$cshowList :: forall cert. Show cert => [LatestCertOnChainView cert] -> ShowS
showList :: [LatestCertOnChainView cert] -> ShowS
Show
data PerasVotingView cert = PerasVotingView
{ forall cert. PerasVotingView cert -> PerasParams
perasParams :: PerasParams
, forall cert. PerasVotingView cert -> PerasRoundNo
currRoundNo :: !PerasRoundNo
, forall cert.
PerasVotingView cert -> WithOrigin (LatestCertSeenView cert)
latestCertSeen :: !(WithOrigin (LatestCertSeenView cert))
, forall cert.
PerasVotingView cert -> WithOrigin (LatestCertOnChainView cert)
latestCertOnChain :: !(WithOrigin (LatestCertOnChainView cert))
}
deriving Int -> PerasVotingView cert -> ShowS
[PerasVotingView cert] -> ShowS
PerasVotingView cert -> String
(Int -> PerasVotingView cert -> ShowS)
-> (PerasVotingView cert -> String)
-> ([PerasVotingView cert] -> ShowS)
-> Show (PerasVotingView cert)
forall cert. Show cert => Int -> PerasVotingView cert -> ShowS
forall cert. Show cert => [PerasVotingView cert] -> ShowS
forall cert. Show cert => PerasVotingView cert -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall cert. Show cert => Int -> PerasVotingView cert -> ShowS
showsPrec :: Int -> PerasVotingView cert -> ShowS
$cshow :: forall cert. Show cert => PerasVotingView cert -> String
show :: PerasVotingView cert -> String
$cshowList :: forall cert. Show cert => [PerasVotingView cert] -> ShowS
showList :: [PerasVotingView cert] -> ShowS
Show
data WithBoostedBlockStatus cert
=
CertWithImmutableBlock cert
|
CertWithVolatileBlock cert
deriving Int -> WithBoostedBlockStatus cert -> ShowS
[WithBoostedBlockStatus cert] -> ShowS
WithBoostedBlockStatus cert -> String
(Int -> WithBoostedBlockStatus cert -> ShowS)
-> (WithBoostedBlockStatus cert -> String)
-> ([WithBoostedBlockStatus cert] -> ShowS)
-> Show (WithBoostedBlockStatus cert)
forall cert.
Show cert =>
Int -> WithBoostedBlockStatus cert -> ShowS
forall cert. Show cert => [WithBoostedBlockStatus cert] -> ShowS
forall cert. Show cert => WithBoostedBlockStatus cert -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall cert.
Show cert =>
Int -> WithBoostedBlockStatus cert -> ShowS
showsPrec :: Int -> WithBoostedBlockStatus cert -> ShowS
$cshow :: forall cert. Show cert => WithBoostedBlockStatus cert -> String
show :: WithBoostedBlockStatus cert -> String
$cshowList :: forall cert. Show cert => [WithBoostedBlockStatus cert] -> ShowS
showList :: [WithBoostedBlockStatus cert] -> ShowS
Show
forgetBoostedBlockStatus :: WithBoostedBlockStatus cert -> cert
forgetBoostedBlockStatus :: forall cert. WithBoostedBlockStatus cert -> cert
forgetBoostedBlockStatus = \case
CertWithVolatileBlock cert
cert -> cert
cert
CertWithImmutableBlock cert
cert -> cert
cert
mkPerasVotingView ::
( cert ~ WithArrivalTime (ValidatedPerasCert blk)
, GetHeader blk
) =>
PerasParams ->
PerasRoundNo ->
WithOrigin (WithBoostedBlockStatus cert) ->
WithOrigin cert ->
AnchoredFragment (Header blk) ->
PerasQry xs (PerasVotingView cert)
mkPerasVotingView :: forall cert blk (xs :: [*]).
(cert ~ WithArrivalTime (ValidatedPerasCert blk), GetHeader blk) =>
PerasParams
-> PerasRoundNo
-> WithOrigin (WithBoostedBlockStatus cert)
-> WithOrigin cert
-> AnchoredFragment (Header blk)
-> PerasQry xs (PerasVotingView cert)
mkPerasVotingView
PerasParams
perasParams
PerasRoundNo
currRoundNo
WithOrigin (WithBoostedBlockStatus cert)
latestCertSeen
WithOrigin cert
latestCertOnChain
AnchoredFragment (Header blk)
chainAtCandidateBlock = do
latestCertSeenView <- (WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
-> PerasQry
xs (LatestCertSeenView (WithArrivalTime (ValidatedPerasCert blk))))
-> WithOrigin
(WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk)))
-> PerasQry
xs
(WithOrigin
(LatestCertSeenView (WithArrivalTime (ValidatedPerasCert blk))))
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) -> WithOrigin a -> f (WithOrigin b)
traverse WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
-> PerasQry
xs (LatestCertSeenView (WithArrivalTime (ValidatedPerasCert blk)))
mkLatestCertSeenView WithOrigin (WithBoostedBlockStatus cert)
WithOrigin
(WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk)))
latestCertSeen
latestCertOnChainView <- traverse mkLatestCertOnChainView latestCertOnChain
pure $
PerasVotingView
{ perasParams = perasParams
, currRoundNo = currRoundNo
, latestCertSeen = latestCertSeenView
, latestCertOnChain = latestCertOnChainView
}
where
mkLatestCertSeenView :: WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
-> PerasQry
xs (LatestCertSeenView (WithArrivalTime (ValidatedPerasCert blk)))
mkLatestCertSeenView WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
certWithProvenance = do
let lcsCert :: WithArrivalTime (ValidatedPerasCert blk)
lcsCert = WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
-> WithArrivalTime (ValidatedPerasCert blk)
forall cert. WithBoostedBlockStatus cert -> cert
forgetBoostedBlockStatus WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
certWithProvenance
lcsArrivalSlot <- WithArrivalTime (ValidatedPerasCert blk) -> PerasQry xs SlotNo
forall cert (xs :: [*]). WithArrivalTime cert -> PerasQry xs SlotNo
perasCertArrivalSlot WithArrivalTime (ValidatedPerasCert blk)
lcsCert
lcsRoundStartSlot <- perasRoundStart (getPerasCertRound lcsCert)
let lcsCandidateBlockExtendsCert = WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
-> Bool
candidateBlockExtendsCert WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
certWithProvenance
pure $
LatestCertSeenView
{ lcsCert
, lcsArrivalSlot
, lcsRoundStartSlot
, lcsCandidateBlockExtendsCert
}
mkLatestCertOnChainView :: cert -> f (LatestCertOnChainView cert)
mkLatestCertOnChainView cert
lcocCert =
LatestCertOnChainView cert -> f (LatestCertOnChainView cert)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LatestCertOnChainView cert -> f (LatestCertOnChainView cert))
-> LatestCertOnChainView cert -> f (LatestCertOnChainView cert)
forall a b. (a -> b) -> a -> b
$
LatestCertOnChainView
{ cert
lcocCert :: cert
lcocCert :: cert
lcocCert
}
candidateBlockExtendsCert :: WithBoostedBlockStatus (WithArrivalTime (ValidatedPerasCert blk))
-> Bool
candidateBlockExtendsCert (CertWithImmutableBlock WithArrivalTime (ValidatedPerasCert blk)
_) =
Bool
True
candidateBlockExtendsCert (CertWithVolatileBlock WithArrivalTime (ValidatedPerasCert blk)
cert) =
Point (Header blk) -> AnchoredFragment (Header blk) -> Bool
forall block.
HasHeader block =>
Point block -> AnchoredFragment block -> Bool
AF.withinFragmentBounds
(Point blk -> Point (Header blk)
forall {k1} {k2} (b :: k1) (b' :: k2).
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (WithArrivalTime (ValidatedPerasCert blk) -> Point blk
forall cert blk.
HasPerasCertBoostedBlock cert blk =>
cert -> Point blk
getPerasCertBoostedBlock WithArrivalTime (ValidatedPerasCert blk)
cert))
AnchoredFragment (Header blk)
chainAtCandidateBlock