{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Ouroboros.Consensus.Shelley.Protocol.Abstract (
ProtoCrypto
, ProtocolHeaderSupportsEnvelope (..)
, ProtocolHeaderSupportsKES (..)
, ProtocolHeaderSupportsLedger (..)
, ProtocolHeaderSupportsProtocol (..)
, ShelleyHash (..)
, ShelleyProtocol
, ShelleyProtocolHeader
) where
import Cardano.Binary (FromCBOR (fromCBOR), ToCBOR (toCBOR))
import qualified Cardano.Crypto.Hash as Hash
import Cardano.Crypto.VRF (OutputVRF)
import Cardano.Ledger.BaseTypes (ProtVer)
import Cardano.Ledger.BHeaderView (BHeaderView)
import Cardano.Ledger.Hashes (EraIndependentBlockBody,
EraIndependentBlockHeader, HASH)
import Cardano.Ledger.Keys (KeyRole (BlockIssuer), VKey)
import Cardano.Protocol.Crypto (Crypto, VRF)
import Cardano.Protocol.TPraos.BHeader (PrevHash)
import Cardano.Slotting.Block (BlockNo)
import Cardano.Slotting.Slot (SlotNo)
import Codec.Serialise (Serialise (..))
import Control.Monad.Except (Except)
import Data.Kind (Type)
import Data.Typeable (Typeable)
import Data.Word (Word64)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import Numeric.Natural (Natural)
import Ouroboros.Consensus.Protocol.Abstract (CanBeLeader,
ChainDepState, ConsensusConfig, ConsensusProtocol,
IsLeader, LedgerView, ValidateView)
import Ouroboros.Consensus.Protocol.Ledger.HotKey (HotKey)
import Ouroboros.Consensus.Protocol.Signed (SignedHeader)
import Ouroboros.Consensus.Util.Condense (Condense (..))
type family ProtoCrypto proto :: Type
newtype ShelleyHash = ShelleyHash
{ ShelleyHash -> Hash HASH EraIndependentBlockHeader
unShelleyHash :: Hash.Hash HASH EraIndependentBlockHeader
}
deriving stock (ShelleyHash -> ShelleyHash -> Bool
(ShelleyHash -> ShelleyHash -> Bool)
-> (ShelleyHash -> ShelleyHash -> Bool) -> Eq ShelleyHash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShelleyHash -> ShelleyHash -> Bool
== :: ShelleyHash -> ShelleyHash -> Bool
$c/= :: ShelleyHash -> ShelleyHash -> Bool
/= :: ShelleyHash -> ShelleyHash -> Bool
Eq, Eq ShelleyHash
Eq ShelleyHash =>
(ShelleyHash -> ShelleyHash -> Ordering)
-> (ShelleyHash -> ShelleyHash -> Bool)
-> (ShelleyHash -> ShelleyHash -> Bool)
-> (ShelleyHash -> ShelleyHash -> Bool)
-> (ShelleyHash -> ShelleyHash -> Bool)
-> (ShelleyHash -> ShelleyHash -> ShelleyHash)
-> (ShelleyHash -> ShelleyHash -> ShelleyHash)
-> Ord ShelleyHash
ShelleyHash -> ShelleyHash -> Bool
ShelleyHash -> ShelleyHash -> Ordering
ShelleyHash -> ShelleyHash -> ShelleyHash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ShelleyHash -> ShelleyHash -> Ordering
compare :: ShelleyHash -> ShelleyHash -> Ordering
$c< :: ShelleyHash -> ShelleyHash -> Bool
< :: ShelleyHash -> ShelleyHash -> Bool
$c<= :: ShelleyHash -> ShelleyHash -> Bool
<= :: ShelleyHash -> ShelleyHash -> Bool
$c> :: ShelleyHash -> ShelleyHash -> Bool
> :: ShelleyHash -> ShelleyHash -> Bool
$c>= :: ShelleyHash -> ShelleyHash -> Bool
>= :: ShelleyHash -> ShelleyHash -> Bool
$cmax :: ShelleyHash -> ShelleyHash -> ShelleyHash
max :: ShelleyHash -> ShelleyHash -> ShelleyHash
$cmin :: ShelleyHash -> ShelleyHash -> ShelleyHash
min :: ShelleyHash -> ShelleyHash -> ShelleyHash
Ord, Int -> ShelleyHash -> ShowS
[ShelleyHash] -> ShowS
ShelleyHash -> String
(Int -> ShelleyHash -> ShowS)
-> (ShelleyHash -> String)
-> ([ShelleyHash] -> ShowS)
-> Show ShelleyHash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShelleyHash -> ShowS
showsPrec :: Int -> ShelleyHash -> ShowS
$cshow :: ShelleyHash -> String
show :: ShelleyHash -> String
$cshowList :: [ShelleyHash] -> ShowS
showList :: [ShelleyHash] -> ShowS
Show, (forall x. ShelleyHash -> Rep ShelleyHash x)
-> (forall x. Rep ShelleyHash x -> ShelleyHash)
-> Generic ShelleyHash
forall x. Rep ShelleyHash x -> ShelleyHash
forall x. ShelleyHash -> Rep ShelleyHash x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ShelleyHash -> Rep ShelleyHash x
from :: forall x. ShelleyHash -> Rep ShelleyHash x
$cto :: forall x. Rep ShelleyHash x -> ShelleyHash
to :: forall x. Rep ShelleyHash x -> ShelleyHash
Generic)
deriving anyclass (Context -> ShelleyHash -> IO (Maybe ThunkInfo)
Proxy ShelleyHash -> String
(Context -> ShelleyHash -> IO (Maybe ThunkInfo))
-> (Context -> ShelleyHash -> IO (Maybe ThunkInfo))
-> (Proxy ShelleyHash -> String)
-> NoThunks ShelleyHash
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> ShelleyHash -> IO (Maybe ThunkInfo)
noThunks :: Context -> ShelleyHash -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ShelleyHash -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> ShelleyHash -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy ShelleyHash -> String
showTypeOf :: Proxy ShelleyHash -> String
NoThunks)
deriving newtype instance ToCBOR ShelleyHash
deriving newtype instance FromCBOR ShelleyHash
instance
Serialise ShelleyHash
where
encode :: ShelleyHash -> Encoding
encode = ShelleyHash -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
decode :: forall s. Decoder s ShelleyHash
decode = Decoder s ShelleyHash
forall s. Decoder s ShelleyHash
forall a s. FromCBOR a => Decoder s a
fromCBOR
instance Condense ShelleyHash where
condense :: ShelleyHash -> String
condense = Hash HASH EraIndependentBlockHeader -> String
forall a. Show a => a -> String
show (Hash HASH EraIndependentBlockHeader -> String)
-> (ShelleyHash -> Hash HASH EraIndependentBlockHeader)
-> ShelleyHash
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyHash -> Hash HASH EraIndependentBlockHeader
unShelleyHash
type family proto = (sh :: Type) | sh -> proto
class
( Eq (EnvelopeCheckError proto),
NoThunks (EnvelopeCheckError proto),
Show (EnvelopeCheckError proto)
) =>
proto
where
:: ShelleyProtocolHeader proto -> ShelleyHash
:: ShelleyProtocolHeader proto -> PrevHash
pHeaderBodyHash :: ShelleyProtocolHeader proto -> Hash.Hash HASH EraIndependentBlockBody
:: ShelleyProtocolHeader proto -> SlotNo
:: ShelleyProtocolHeader proto -> BlockNo
:: ShelleyProtocolHeader proto -> Natural
:: ShelleyProtocolHeader proto -> Natural
type EnvelopeCheckError proto :: Type
envelopeChecks ::
ConsensusConfig proto ->
LedgerView proto ->
ShelleyProtocolHeader proto ->
Except (EnvelopeCheckError proto) ()
class proto where
configSlotsPerKESPeriod :: ConsensusConfig proto -> Word64
::
Word64 ->
ShelleyProtocolHeader proto ->
Bool
::
forall crypto m.
(Crypto crypto, Monad m, crypto ~ ProtoCrypto proto) =>
HotKey crypto m ->
CanBeLeader proto ->
IsLeader proto ->
SlotNo ->
BlockNo ->
PrevHash ->
Hash.Hash HASH EraIndependentBlockBody ->
Int ->
ProtVer ->
m (ShelleyProtocolHeader proto)
class proto where
type CannotForgeError proto :: Type
::
ShelleyProtocolHeader proto -> ValidateView proto
::
ShelleyProtocolHeader proto -> VKey 'BlockIssuer
::
ShelleyProtocolHeader proto -> Word64
pTieBreakVRFValue ::
ShelleyProtocolHeader proto -> OutputVRF (VRF (ProtoCrypto proto))
class proto where
:: ShelleyProtocolHeader proto -> BHeaderView
class
( ConsensusProtocol proto,
Typeable (ShelleyProtocolHeader proto),
ProtocolHeaderSupportsEnvelope proto,
ProtocolHeaderSupportsKES proto,
ProtocolHeaderSupportsProtocol proto,
ProtocolHeaderSupportsLedger proto,
Serialise (ChainDepState proto),
SignedHeader (ShelleyProtocolHeader proto)
) =>
ShelleyProtocol proto