{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}

module Ouroboros.Consensus.Peras.Protocol
  ( PerasLedgerView (..)
  , PerasProtocol (..)
  , defaultGetPerasLedgerView
  ) where

import Cardano.Ledger.BaseTypes (PositiveInterval, UnitInterval)
import Cardano.Slotting.Slot (SlotInterval)
import Data.Maybe.Strict (StrictMaybe)
import Data.Word (Word16, Word32)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import Ouroboros.Consensus.Protocol.Abstract (ConsensusProtocol (..))

-- | The Peras parameters a ledger view carries.
data PerasLedgerView = MkPerasLedgerView
  { PerasLedgerView -> SlotInterval
plvMinCandidateBlockAge :: !SlotInterval
  , PerasLedgerView -> PositiveInterval
plvHealingFactor :: !PositiveInterval
  , PerasLedgerView -> Word16
plvCertBoost :: !Word16
  , PerasLedgerView -> Word16
plvTargetCommitteeSize :: !Word16
  , PerasLedgerView -> StrictMaybe Word32
plvBootstrapRound :: !(StrictMaybe Word32)
  , PerasLedgerView -> UnitInterval
plvQuorumThresholdSafetyMargin :: !UnitInterval
  }
  deriving stock (PerasLedgerView -> PerasLedgerView -> Bool
(PerasLedgerView -> PerasLedgerView -> Bool)
-> (PerasLedgerView -> PerasLedgerView -> Bool)
-> Eq PerasLedgerView
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PerasLedgerView -> PerasLedgerView -> Bool
== :: PerasLedgerView -> PerasLedgerView -> Bool
$c/= :: PerasLedgerView -> PerasLedgerView -> Bool
/= :: PerasLedgerView -> PerasLedgerView -> Bool
Eq, Int -> PerasLedgerView -> ShowS
[PerasLedgerView] -> ShowS
PerasLedgerView -> String
(Int -> PerasLedgerView -> ShowS)
-> (PerasLedgerView -> String)
-> ([PerasLedgerView] -> ShowS)
-> Show PerasLedgerView
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PerasLedgerView -> ShowS
showsPrec :: Int -> PerasLedgerView -> ShowS
$cshow :: PerasLedgerView -> String
show :: PerasLedgerView -> String
$cshowList :: [PerasLedgerView] -> ShowS
showList :: [PerasLedgerView] -> ShowS
Show, (forall x. PerasLedgerView -> Rep PerasLedgerView x)
-> (forall x. Rep PerasLedgerView x -> PerasLedgerView)
-> Generic PerasLedgerView
forall x. Rep PerasLedgerView x -> PerasLedgerView
forall x. PerasLedgerView -> Rep PerasLedgerView x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PerasLedgerView -> Rep PerasLedgerView x
from :: forall x. PerasLedgerView -> Rep PerasLedgerView x
$cto :: forall x. Rep PerasLedgerView x -> PerasLedgerView
to :: forall x. Rep PerasLedgerView x -> PerasLedgerView
Generic)
  deriving anyclass Context -> PerasLedgerView -> IO (Maybe ThunkInfo)
Proxy PerasLedgerView -> String
(Context -> PerasLedgerView -> IO (Maybe ThunkInfo))
-> (Context -> PerasLedgerView -> IO (Maybe ThunkInfo))
-> (Proxy PerasLedgerView -> String)
-> NoThunks PerasLedgerView
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> PerasLedgerView -> IO (Maybe ThunkInfo)
noThunks :: Context -> PerasLedgerView -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> PerasLedgerView -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> PerasLedgerView -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy PerasLedgerView -> String
showTypeOf :: Proxy PerasLedgerView -> String
NoThunks

class ConsensusProtocol p => PerasProtocol p where
  -- | The Peras parameters this ledger view carries, or 'Nothing' if the
  -- protocol has no Peras.
  getPerasLedgerView :: proxy p -> LedgerView p -> Maybe PerasLedgerView

-- | 'getPerasLedgerView' for a protocol that has no Peras.
defaultGetPerasLedgerView :: proxy p -> LedgerView p -> Maybe PerasLedgerView
defaultGetPerasLedgerView :: forall (proxy :: * -> *) p.
proxy p -> LedgerView p -> Maybe PerasLedgerView
defaultGetPerasLedgerView proxy p
_proxy LedgerView p
_view = Maybe PerasLedgerView
forall a. Maybe a
Nothing