{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Consensus.Shelley.Node
( MaxMajorProtVer (..)
, ProtocolParamsShelleyBased (..)
, SL.Nonce (..)
, SL.ProtVer (..)
, SL.ShelleyGenesis (..)
, SL.ShelleyGenesisStaking (..)
, SL.emptyGenesisStaking
, ShelleyLeaderCredentials (..)
, protocolClientInfoShelley
, protocolInfoShelley
, protocolInfoTPraosShelleyBased
, validateGenesis
) where
import qualified Cardano.Ledger.Shelley.API as SL
import Cardano.Protocol.Crypto (Crypto)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.SupportsMempool (TxLimits)
import Ouroboros.Consensus.Ledger.SupportsProtocol
( LedgerSupportsProtocol
)
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Protocol.TPraos
import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Ledger.Inspect ()
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
import Ouroboros.Consensus.Shelley.Node.DiffusionPipelining ()
import Ouroboros.Consensus.Shelley.Node.Serialisation ()
import Ouroboros.Consensus.Shelley.Node.TPraos
import Ouroboros.Consensus.Shelley.Protocol.Abstract
( ProtoCrypto
, pHeaderIssuer
)
protocolClientInfoShelley :: ProtocolClientInfo (ShelleyBlock proto era)
protocolClientInfoShelley :: forall proto era. ProtocolClientInfo (ShelleyBlock proto era)
protocolClientInfoShelley =
ProtocolClientInfo
{
pClientInfoCodecConfig :: CodecConfig (ShelleyBlock proto era)
pClientInfoCodecConfig = CodecConfig (ShelleyBlock proto era)
forall proto era. CodecConfig (ShelleyBlock proto era)
ShelleyCodecConfig
}
instance ShelleyCompatible proto era => BlockSupportsMetrics (ShelleyBlock proto era) where
isSelfIssued :: BlockConfig (ShelleyBlock proto era)
-> Header (ShelleyBlock proto era) -> WhetherSelfIssued
isSelfIssued BlockConfig (ShelleyBlock proto era)
cfg (ShelleyHeader ShelleyProtocolHeader proto
shdr ShelleyHash
_) = case Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer) -> Int
forall k a. Map k a -> Int
Map.size Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer)
issuerVKeys of
Int
0 -> WhetherSelfIssued
IsNotSelfIssued
Int
1
| ShelleyProtocolHeader proto -> VKey 'BlockIssuer
forall proto.
ProtocolHeaderSupportsProtocol proto =>
ShelleyProtocolHeader proto -> VKey 'BlockIssuer
pHeaderIssuer ShelleyProtocolHeader proto
shdr VKey 'BlockIssuer
-> Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer) -> Bool
forall a. Eq a => a -> Map (KeyHash 'BlockIssuer) a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer)
issuerVKeys ->
WhetherSelfIssued
IsSelfIssued
| Bool
otherwise ->
WhetherSelfIssued
IsNotSelfIssued
Int
_
| VKey 'BlockIssuer -> KeyHash 'BlockIssuer
forall (kd :: KeyRole). VKey kd -> KeyHash kd
SL.hashKey (ShelleyProtocolHeader proto -> VKey 'BlockIssuer
forall proto.
ProtocolHeaderSupportsProtocol proto =>
ShelleyProtocolHeader proto -> VKey 'BlockIssuer
pHeaderIssuer ShelleyProtocolHeader proto
shdr) KeyHash 'BlockIssuer
-> Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
`Map.member` Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer)
issuerVKeys ->
WhetherSelfIssued
IsSelfIssued
| Bool
otherwise ->
WhetherSelfIssued
IsNotSelfIssued
where
issuerVKeys ::
Map
(SL.KeyHash 'SL.BlockIssuer)
(SL.VKey 'SL.BlockIssuer)
issuerVKeys :: Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer)
issuerVKeys = BlockConfig (ShelleyBlock proto era)
-> Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer)
forall proto era.
BlockConfig (ShelleyBlock proto era)
-> Map (KeyHash 'BlockIssuer) (VKey 'BlockIssuer)
shelleyBlockIssuerVKeys BlockConfig (ShelleyBlock proto era)
cfg
instance ConsensusProtocol proto => BlockSupportsSanityCheck (ShelleyBlock proto era) where
configAllSecurityParams :: TopLevelConfig (ShelleyBlock proto era) -> NonEmpty SecurityParam
configAllSecurityParams = SecurityParam -> NonEmpty SecurityParam
forall a. a -> NonEmpty a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SecurityParam -> NonEmpty SecurityParam)
-> (TopLevelConfig (ShelleyBlock proto era) -> SecurityParam)
-> TopLevelConfig (ShelleyBlock proto era)
-> NonEmpty SecurityParam
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConsensusConfig proto -> SecurityParam
forall p. ConsensusProtocol p => ConsensusConfig p -> SecurityParam
protocolSecurityParam (ConsensusConfig proto -> SecurityParam)
-> (TopLevelConfig (ShelleyBlock proto era)
-> ConsensusConfig proto)
-> TopLevelConfig (ShelleyBlock proto era)
-> SecurityParam
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TopLevelConfig (ShelleyBlock proto era) -> ConsensusConfig proto
TopLevelConfig (ShelleyBlock proto era)
-> ConsensusConfig (BlockProtocol (ShelleyBlock proto era))
forall blk.
TopLevelConfig blk -> ConsensusConfig (BlockProtocol blk)
topLevelConfigProtocol
instance
( ShelleyCompatible proto era
, LedgerSupportsProtocol (ShelleyBlock proto era)
, BlockSupportsSanityCheck (ShelleyBlock proto era)
, TxLimits (ShelleyBlock proto era)
, SerialiseNodeToClientConstraints (ShelleyBlock proto era)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto era)