{-# 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 Cardano.Crypto.VRF (OutputVRF)
import Cardano.Ledger.BaseTypes (ProtVer)
import Cardano.Ledger.BHeaderView (BHeaderView)
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.Util.Condense (Condense (..))
type family ProtoCrypto proto :: Type
newtype ShelleyHash crypto = ShelleyHash
{ forall crypto.
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
$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
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
$ccompare :: forall crypto. ShelleyHash crypto -> ShelleyHash crypto -> Ordering
compare :: ShelleyHash crypto -> ShelleyHash crypto -> Ordering
$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
>= :: ShelleyHash crypto -> ShelleyHash crypto -> Bool
$cmax :: forall crypto.
ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
max :: ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
$cmin :: forall crypto.
ShelleyHash crypto -> ShelleyHash crypto -> ShelleyHash crypto
min :: ShelleyHash crypto -> ShelleyHash crypto -> 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
$cshowsPrec :: forall crypto. Int -> ShelleyHash crypto -> ShowS
showsPrec :: Int -> ShelleyHash crypto -> ShowS
$cshow :: forall crypto. ShelleyHash crypto -> String
show :: ShelleyHash crypto -> String
$cshowList :: forall crypto. [ShelleyHash crypto] -> ShowS
showList :: [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
$cfrom :: forall crypto x. ShelleyHash crypto -> Rep (ShelleyHash crypto) x
from :: forall x. ShelleyHash crypto -> Rep (ShelleyHash crypto) x
$cto :: forall crypto x. Rep (ShelleyHash crypto) x -> ShelleyHash crypto
to :: forall x. Rep (ShelleyHash crypto) x -> ShelleyHash crypto
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
$cnoThunks :: forall crypto.
Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
noThunks :: Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall crypto.
Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> ShelleyHash crypto -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall crypto. Proxy (ShelleyHash crypto) -> String
showTypeOf :: Proxy (ShelleyHash crypto) -> String
NoThunks)
deriving newtype instance Crypto crypto => ToCBOR (ShelleyHash crypto)
deriving newtype instance Crypto crypto => FromCBOR (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 :: forall s. Decoder s (ShelleyHash crypto)
decode = Decoder s (ShelleyHash crypto)
forall s. 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 ->
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
pTieBreakVRFValue ::
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