{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# 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 Cardano.Crypto.VRF (OutputVRF)
import Cardano.Ledger.BHeaderView (BHeaderView)
import Cardano.Ledger.BaseTypes (ProtVer)
import Cardano.Ledger.Crypto (Crypto, VRF)
import Cardano.Ledger.Hashes (EraIndependentBlockBody,
EraIndependentBlockHeader)
import Cardano.Ledger.Keys (Hash, KeyRole (BlockIssuer), VKey)
import qualified Cardano.Ledger.Keys as SL (Hash)
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.Ticked (Ticked)
import Ouroboros.Consensus.Util.Condense (Condense (..))
type family ProtoCrypto proto :: Type
newtype ShelleyHash crypto = ShelleyHash
{ ShelleyHash crypto -> Hash crypto EraIndependentBlockHeader
unShelleyHash :: SL.Hash crypto EraIndependentBlockHeader
}
deriving stock (ShelleyHash crypto -> ShelleyHash crypto -> Bool
(ShelleyHash crypto -> ShelleyHash crypto -> Bool)
-> (ShelleyHash crypto -> ShelleyHash crypto -> Bool)
-> Eq (ShelleyHash crypto)
forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$c/= :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
== :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$c== :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
Eq, Eq (ShelleyHash crypto)
Eq (ShelleyHash crypto)
-> (ShelleyHash crypto -> ShelleyHash crypto -> Ordering)
-> (ShelleyHash crypto -> ShelleyHash crypto -> Bool)
-> (ShelleyHash crypto -> ShelleyHash crypto -> Bool)
-> (ShelleyHash crypto -> ShelleyHash crypto -> Bool)
-> (ShelleyHash crypto -> ShelleyHash crypto -> Bool)
-> (ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto)
-> (ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto)
-> Ord (ShelleyHash crypto)
ShelleyHash crypto -> ShelleyHash crypto -> Bool
ShelleyHash crypto -> ShelleyHash crypto -> Ordering
ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
forall crypto. Eq (ShelleyHash crypto)
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
forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Ordering
forall crypto.
ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
min :: ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
$cmin :: forall crypto.
ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
max :: ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
$cmax :: forall crypto.
ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
>= :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$c>= :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
> :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$c> :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
<= :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$c<= :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
< :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$c< :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Bool
compare :: ShelleyHash crypto -> ShelleyHash crypto -> Ordering
$ccompare :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Ordering
$cp1Ord :: forall crypto. Eq (ShelleyHash crypto)
Ord, Int -> ShelleyHash crypto -> ShowS
[ShelleyHash crypto] -> ShowS
ShelleyHash crypto -> String
(Int -> ShelleyHash crypto -> ShowS)
-> (ShelleyHash crypto -> String)
-> ([ShelleyHash crypto] -> ShowS)
-> Show (ShelleyHash crypto)
forall crypto. Int -> ShelleyHash crypto -> ShowS
forall crypto. [ShelleyHash crypto] -> ShowS
forall crypto. ShelleyHash crypto -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShelleyHash crypto] -> ShowS
$cshowList :: forall crypto. [ShelleyHash crypto] -> ShowS
show :: ShelleyHash crypto -> String
$cshow :: forall crypto. ShelleyHash crypto -> String
showsPrec :: Int -> ShelleyHash crypto -> ShowS
$cshowsPrec :: forall crypto. Int -> ShelleyHash crypto -> ShowS
Show, (forall x. ShelleyHash crypto -> Rep (ShelleyHash crypto) x)
-> (forall x. Rep (ShelleyHash crypto) x -> ShelleyHash crypto)
-> Generic (ShelleyHash crypto)
forall x. Rep (ShelleyHash crypto) x -> ShelleyHash crypto
forall x. ShelleyHash crypto -> Rep (ShelleyHash crypto) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall crypto x. Rep (ShelleyHash crypto) x -> ShelleyHash crypto
forall crypto x. ShelleyHash crypto -> Rep (ShelleyHash crypto) x
$cto :: forall crypto x. Rep (ShelleyHash crypto) x -> ShelleyHash crypto
$cfrom :: forall crypto x. ShelleyHash crypto -> Rep (ShelleyHash crypto) x
Generic)
deriving anyclass (Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
Proxy (ShelleyHash crypto) -> String
(Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo))
-> (Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo))
-> (Proxy (ShelleyHash crypto) -> String)
-> NoThunks (ShelleyHash crypto)
forall crypto.
Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
forall crypto. Proxy (ShelleyHash crypto) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (ShelleyHash crypto) -> String
$cshowTypeOf :: forall crypto. Proxy (ShelleyHash crypto) -> String
wNoThunks :: Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall crypto.
Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
noThunks :: Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
$cnoThunks :: forall crypto.
Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
NoThunks)
deriving newtype instance
( Crypto crypto) =>
FromCBOR (ShelleyHash crypto)
deriving newtype instance
( Crypto crypto) =>
ToCBOR (ShelleyHash crypto)
instance
( Crypto crypto) =>
Serialise (ShelleyHash crypto)
where
encode :: ShelleyHash crypto -> Encoding
encode = ShelleyHash crypto -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
decode :: Decoder s (ShelleyHash crypto)
decode = Decoder s (ShelleyHash crypto)
forall a s. FromCBOR a => Decoder s a
fromCBOR
instance Condense (ShelleyHash crypto) where
condense :: ShelleyHash crypto -> String
condense = Hash (HASH crypto) EraIndependentBlockHeader -> String
forall a. Show a => a -> String
show (Hash (HASH crypto) EraIndependentBlockHeader -> String)
-> (ShelleyHash crypto
-> Hash (HASH crypto) EraIndependentBlockHeader)
-> ShelleyHash crypto
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyHash crypto -> Hash (HASH crypto) EraIndependentBlockHeader
forall crypto.
ShelleyHash crypto -> Hash crypto EraIndependentBlockHeader
unShelleyHash
type family proto = (sh :: Type) | sh -> proto
class
( Eq (EnvelopeCheckError proto),
NoThunks (EnvelopeCheckError proto),
Show (EnvelopeCheckError proto)
) =>
proto
where
:: ShelleyProtocolHeader proto -> ShelleyHash (ProtoCrypto proto)
:: ShelleyProtocolHeader proto -> PrevHash (ProtoCrypto proto)
pHeaderBodyHash :: ShelleyProtocolHeader proto -> Hash (ProtoCrypto proto) EraIndependentBlockBody
:: ShelleyProtocolHeader proto -> SlotNo
:: ShelleyProtocolHeader proto -> BlockNo
:: ShelleyProtocolHeader proto -> Natural
:: ShelleyProtocolHeader proto -> Natural
type EnvelopeCheckError proto :: Type
envelopeChecks ::
ConsensusConfig proto ->
Ticked (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 crypto ->
Hash crypto EraIndependentBlockBody ->
Int ->
ProtVer ->
m (ShelleyProtocolHeader proto)
class proto where
type CannotForgeError proto :: Type
::
ShelleyProtocolHeader proto -> ValidateView proto
::
ShelleyProtocolHeader proto -> VKey 'BlockIssuer (ProtoCrypto proto)
::
ShelleyProtocolHeader proto -> Word64
::
ShelleyProtocolHeader proto -> OutputVRF (VRF (ProtoCrypto proto))
class proto where
:: ShelleyProtocolHeader proto -> BHeaderView (ProtoCrypto proto)
class
( ConsensusProtocol proto,
Typeable (ShelleyProtocolHeader proto),
ProtocolHeaderSupportsEnvelope proto,
ProtocolHeaderSupportsKES proto,
ProtocolHeaderSupportsProtocol proto,
ProtocolHeaderSupportsLedger proto,
Serialise (ChainDepState proto),
SignedHeader (ShelleyProtocolHeader proto)
) =>
ShelleyProtocol proto