Skip to content

Commit

Permalink
make it build mk2
Browse files Browse the repository at this point in the history
  • Loading branch information
angerman committed Sep 23, 2022
1 parent 7026e9e commit 473b5db
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 47 deletions.
1 change: 0 additions & 1 deletion cabal.project
Expand Up @@ -43,7 +43,6 @@ constraints:
, witherable >= 0.4

-- Plutus dependency
, algebraic-graphs < 0.7
, Cabal > 3.4.0.0

allow-newer:
Expand Down
11 changes: 11 additions & 0 deletions ouroboros-consensus-cardano-tools/app/db-synthesizer.hs
@@ -1,3 +1,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
-- | This tool synthesizes a valid ChainDB, replicating cardano-node's UX
--
-- Usage: db-synthesizer --config FILE --db PATH
Expand Down Expand Up @@ -27,9 +30,17 @@ import System.Exit

import Cardano.Tools.DBSynthesizer.Run

import Cardano.Ledger.Core (Era (..))
import Cardano.Ledger.Crypto (StandardCrypto)

import DBSynthesizer.Parsers


instance Era StandardCrypto where
type EraCrypto StandardCrypto = StandardCrypto
type ProtVerLow StandardCrypto = 0
type ProtVerHigh StandardCrypto = 1

main :: IO ()
main = do
(paths, creds, forgeOpts) <- parseCommandLine
Expand Down
Expand Up @@ -108,6 +108,7 @@ executable db-analyser
main-is: db-analyser.hs
build-depends: base
, cardano-crypto-wrapper
, cardano-ledger-core
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
Expand Down Expand Up @@ -141,6 +142,7 @@ executable db-synthesizer
, directory
, filepath
, optparse-applicative
, cardano-ledger-core
, ouroboros-consensus
, ouroboros-consensus-cardano-tools
, transformers
Expand Down
Expand Up @@ -19,6 +19,8 @@ module Cardano.Api.Protocol.Types (

import Cardano.Chain.Slotting (EpochSlots)

import Cardano.Ledger.Core (Era)

import Ouroboros.Consensus.Cardano
import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC)
Expand Down Expand Up @@ -59,7 +61,7 @@ instance IOLike m => Protocol m ByronBlockHFC where
data ProtocolInfoArgs m ByronBlockHFC = ProtocolInfoArgsByron ProtocolParamsByron
protocolInfo (ProtocolInfoArgsByron params) = inject $ protocolInfoByron params

instance (CardanoHardForkConstraints StandardCrypto, IOLike m) => Protocol m (CardanoBlock StandardCrypto) where
instance (Era StandardCrypto, CardanoHardForkConstraints StandardCrypto, IOLike m) => Protocol m (CardanoBlock StandardCrypto) where
data ProtocolInfoArgs m (CardanoBlock StandardCrypto) =
ProtocolInfoArgsCardano
ProtocolParamsByron
Expand Down
@@ -1,4 +1,5 @@
-- DUPLICATE -- adapted from: cardano-node/src/Cardano/Node/Protocol.hs
{-# LANGUAGE FlexibleContexts #-}

module Cardano.Node.Protocol (
ProtocolInstantiationError (..)
Expand All @@ -11,6 +12,9 @@ import Control.Monad.Trans.Except.Extra (firstExceptT)

import Cardano.Api.Any

import Cardano.Ledger.Core (Era)
import Cardano.Ledger.Crypto (StandardCrypto)

import Cardano.Node.Protocol.Byron
import Cardano.Node.Protocol.Cardano
import Cardano.Node.Protocol.Shelley
Expand All @@ -23,7 +27,8 @@ import Cardano.Node.Types
--

mkConsensusProtocol
:: NodeProtocolConfiguration
:: (Era StandardCrypto)
=> NodeProtocolConfiguration
-> Maybe ProtocolFilepaths
-> ExceptT ProtocolInstantiationError IO SomeConsensusProtocol
mkConsensusProtocol ncProtocolConfig mProtocolFiles =
Expand Down
Expand Up @@ -14,6 +14,8 @@ module Cardano.Node.Protocol.Cardano (
, CardanoProtocolInstantiationError (..)
) where

import Cardano.Ledger.Core (Era)
import Cardano.Ledger.Crypto (StandardCrypto)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT)

Expand Down Expand Up @@ -54,7 +56,8 @@ import Cardano.Node.Types
-- type class instances available.
--
mkSomeConsensusProtocolCardano
:: NodeByronProtocolConfiguration
:: (Era StandardCrypto)
=> NodeByronProtocolConfiguration
-> NodeShelleyProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
-> NodeHardForkProtocolConfiguration
Expand Down
Expand Up @@ -74,6 +74,7 @@ import Cardano.Tools.DBAnalyser.HasAnalysis


analyseBlock ::
(Core.Era StandardCrypto) =>
(forall blk. HasAnalysis blk => blk -> a)
-> CardanoBlock StandardCrypto -> a
analyseBlock f =
Expand All @@ -88,6 +89,7 @@ analyseBlock f =
-- | Lift a function polymorphic over all block types supporting `HasAnalysis`
-- into a corresponding function over `CardanoBlock.`
analyseWithLedgerState ::
(Core.Era StandardCrypto) =>
forall a.
(forall blk. HasAnalysis blk => WithLedgerState blk -> a) ->
WithLedgerState (CardanoBlock StandardCrypto) ->
Expand Down Expand Up @@ -118,7 +120,7 @@ analyseWithLedgerState f (WithLedgerState cb sb sa) =
. getHardForkState
. hardForkLedgerStatePerEra

instance HasProtocolInfo (CardanoBlock StandardCrypto) where
instance (Core.Era StandardCrypto) => HasProtocolInfo (CardanoBlock StandardCrypto) where
data Args (CardanoBlock StandardCrypto) = CardanoBlockArgs {
configFile :: FilePath
, threshold :: Maybe PBftSignatureThreshold
Expand Down Expand Up @@ -252,7 +254,7 @@ instance Aeson.FromJSON CardanoConfig where
, hardForkTriggers = hardForkTriggers
}

instance (HasAnnTip (CardanoBlock StandardCrypto), GetPrevHash (CardanoBlock StandardCrypto)) => HasAnalysis (CardanoBlock StandardCrypto) where
instance (Core.Era StandardCrypto, HasAnnTip (CardanoBlock StandardCrypto), GetPrevHash (CardanoBlock StandardCrypto)) => HasAnalysis (CardanoBlock StandardCrypto) where
countTxOutputs = analyseBlock countTxOutputs
blockTxSizes = analyseBlock blockTxSizes
knownEBBs _ =
Expand All @@ -264,7 +266,8 @@ instance (HasAnnTip (CardanoBlock StandardCrypto), GetPrevHash (CardanoBlock Sta
type CardanoBlockArgs = Args (CardanoBlock StandardCrypto)

mkCardanoProtocolInfo ::
Byron.Genesis.Config
(Core.Era StandardCrypto)
=> Byron.Genesis.Config
-> Maybe PBftSignatureThreshold
-> ShelleyGenesis StandardShelley
-> SL.AlonzoGenesis
Expand Down
Expand Up @@ -2,6 +2,8 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.Tools.DBAnalyser.Run (analyse) where

Expand All @@ -13,6 +15,9 @@ import System.IO

import Control.Tracer (Tracer (..), nullTracer)

import Cardano.Ledger.Core (Era (..))
import Cardano.Ledger.Crypto (StandardCrypto)

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import qualified Ouroboros.Consensus.Fragment.InFuture as InFuture
Expand All @@ -39,6 +44,10 @@ import Cardano.Tools.DBAnalyser.Analysis
import Cardano.Tools.DBAnalyser.HasAnalysis
import Cardano.Tools.DBAnalyser.Types

instance Era StandardCrypto where
type EraCrypto StandardCrypto = StandardCrypto
type ProtVerLow StandardCrypto = 0
type ProtVerHigh StandardCrypto = 1

{-------------------------------------------------------------------------------
Analyse
Expand Down
@@ -1,5 +1,6 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}

module Cardano.Tools.DBSynthesizer.Run (
initialize
Expand All @@ -18,6 +19,9 @@ import System.FilePath (takeDirectory, (</>))

import Control.Tracer (nullTracer)

import Cardano.Ledger.Core (Era)
import Cardano.Ledger.Crypto (StandardCrypto)

import Ouroboros.Consensus.Config (configSecurityParam, configStorage)
import qualified Ouroboros.Consensus.Fragment.InFuture as InFuture (dontCheck)
import qualified Ouroboros.Consensus.Node as Node (mkChainDbArgs,
Expand Down Expand Up @@ -48,7 +52,8 @@ import Cardano.Tools.DBSynthesizer.Types


initialize
:: NodeFilePaths
:: (Era StandardCrypto)
=> NodeFilePaths
-> NodeCredentials
-> DBSynthesizerOptions
-> IO (Either String (DBSynthesizerConfig, SomeConsensusProtocol))
Expand Down
Expand Up @@ -501,7 +501,7 @@ data ProtocolTransitionParamsShelleyBased era = ProtocolTransitionParamsShelleyB
-- PRECONDITION: only a single set of Shelley credentials is allowed when used
-- for mainnet (check against @'SL.gNetworkId' 'shelleyBasedGenesis'@).
protocolInfoCardano ::
forall c m. (IOLike m, CardanoHardForkConstraints c)
forall c m. (Core.Era c, IOLike m, CardanoHardForkConstraints c)
=> ProtocolParamsByron
-> ProtocolParamsShelleyBased (ShelleyEra c)
-> ProtocolParamsShelley c
Expand Down
Expand Up @@ -11,6 +11,7 @@
{-# LANGUAGE UndecidableSuperClasses #-}
module Ouroboros.Consensus.Cardano.ShelleyBased (overShelleyBasedLedgerState) where

import Cardano.Ledger.Core (Era)
import Data.SOP.Strict hiding (All2)
import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.HardFork.Combinator
Expand All @@ -24,7 +25,7 @@ import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock,
-- given function to it.
overShelleyBasedLedgerState ::
forall c.
(TPraos.PraosCrypto c, Praos.PraosCrypto c)
(Era c, TPraos.PraosCrypto c, Praos.PraosCrypto c)
=> ( forall era proto. (EraCrypto era ~ c, ShelleyCompatible proto era)
=> LedgerState (ShelleyBlock proto era)
-> LedgerState (ShelleyBlock proto era)
Expand Down
Expand Up @@ -362,13 +362,13 @@ deriving instance PraosCrypto c => NoThunks (PraosValidationErr c)
deriving instance PraosCrypto c => Show (PraosValidationErr c)

instance PraosCrypto c => ConsensusProtocol (Praos c) where
type ChainDepState _ = PraosState c
type IsLeader _ = PraosIsLeader c
type CanBeLeader _ = PraosCanBeLeader c
type SelectView _ = PraosChainSelectView c
type LedgerView _ = Views.LedgerView c
type ValidationErr _ = PraosValidationErr c
type ValidateView _ = PraosValidateView c
type ChainDepState (Praos c) = PraosState c
type IsLeader (Praos c) = PraosIsLeader c
type CanBeLeader (Praos c) = PraosCanBeLeader c
type SelectView (Praos c) = PraosChainSelectView c
type LedgerView (Praos c) = Views.LedgerView c
type ValidationErr (Praos c) = PraosValidationErr c
type ValidateView (Praos c) = PraosValidateView c

protocolSecurityParam = praosSecurityParam . praosParams

Expand Down
Expand Up @@ -7,6 +7,8 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}

-- | Block header associated with Praos.
--
Expand Down Expand Up @@ -48,7 +50,8 @@ import Cardano.Slotting.Block (BlockNo)
import Cardano.Slotting.Slot (SlotNo)
import qualified Data.ByteString.Short as SBS
import Data.Coders
import Data.MemoBytes (Mem, MemoBytes (Memo), memoBytes)
import Cardano.Ledger.MemoBytes (Mem, MemoBytes (Memo), memoBytes)
import Cardano.Ledger.Core (Era, EraCrypto)
import Data.Word (Word32)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
Expand Down Expand Up @@ -105,16 +108,21 @@ instance
NoThunks (HeaderRaw crypto)

-- | Full header type, carrying its own memoised bytes.
newtype Header crypto = HeaderConstr (MemoBytes (HeaderRaw crypto))
deriving newtype (Eq, Show, NoThunks, ToCBOR)
newtype Header crypto = HeaderConstr (MemoBytes HeaderRaw crypto)
deriving newtype (Eq, NoThunks, ToCBOR)

instance
Hash.HashAlgorithm (CC.HASH (EraCrypto crypto)) =>
Show (Header crypto)


deriving via
(Mem (HeaderRaw crypto))
(Mem HeaderRaw crypto)
instance
CC.Crypto crypto => (FromCBOR (Annotator (Header crypto)))
(Era crypto, CC.Crypto crypto) => (FromCBOR (Annotator (Header crypto)))

pattern Header ::
CC.Crypto crypto =>
(Era crypto, CC.Crypto crypto) =>
HeaderBody crypto ->
SignedKES crypto (HeaderBody crypto) ->
Header crypto
Expand All @@ -134,7 +142,7 @@ pattern Header {headerBody, headerSig} <-
{-# COMPLETE Header #-}

-- | Compute the size of the header
headerSize :: Header crypto -> Int
headerSize :: Era crypto => Header crypto -> Int
headerSize (HeaderConstr (Memo _ bytes)) = SBS.length bytes

-- | Hash a header
Expand Down
Expand Up @@ -8,6 +8,7 @@ module Test.Consensus.Protocol.Serialisation.Generators where
import Cardano.Crypto.KES (signedKES)
import Cardano.Crypto.VRF (evalCertified)
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.Core (Era)
import Cardano.Protocol.TPraos.BHeader (HashHeader, PrevHash (..))
import Cardano.Protocol.TPraos.OCert (KESPeriod (KESPeriod),
OCert (OCert))
Expand Down Expand Up @@ -56,7 +57,7 @@ instance Praos.PraosCrypto c => Arbitrary (HeaderBody c) where
<*> ocert
<*> arbitrary

instance Praos.PraosCrypto c => Arbitrary (Header c) where
instance (Era c, Praos.PraosCrypto c) => Arbitrary (Header c) where
arbitrary = do
hBody <- arbitrary
period <- arbitrary
Expand Down
Expand Up @@ -65,8 +65,7 @@ import Cardano.Ledger.Mary.Translation ()
import Cardano.Ledger.Shelley (ShelleyEra)
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Ledger.Shelley.LedgerState as SL
import qualified Cardano.Ledger.Shelley.Rules.Ledger as SL
import qualified Cardano.Ledger.Shelley.Rules.Utxow as SL
import qualified Cardano.Ledger.Shelley.Rules as SL
import Cardano.Ledger.ShelleyMA ()
import qualified Cardano.Protocol.TPraos.API as SL
import Control.State.Transition (PredicateFailure, State)
Expand Down Expand Up @@ -94,16 +93,6 @@ type StandardAlonzo = AlonzoEra StandardCrypto
-- | The Babbage era with standard crypto
type StandardBabbage = BabbageEra StandardCrypto

{-------------------------------------------------------------------------------
Type synonyms for convenience
-------------------------------------------------------------------------------}

-- | The 'Cardano.Ledger.Era.Crypto' type family conflicts with the
-- 'Cardano.Ledger.Crypto.Crypto' class. To avoid having to import one or both
-- of them qualified, define 'EraCrypto' as an alias of the former: /return the
-- crypto used by this era/.
type EraCrypto era = Crypto era

{-------------------------------------------------------------------------------
Era polymorphism
-------------------------------------------------------------------------------}
Expand Down
Expand Up @@ -19,6 +19,7 @@ module Ouroboros.Consensus.Shelley.HFEras (
import Cardano.Crypto.DSIGN (Signable)
import Cardano.Crypto.Hash (Hash)
import Cardano.Ledger.Crypto (DSIGN, HASH)
import Cardano.Ledger.Core (Era)
import Cardano.Ledger.Hashes (EraIndependentTxBody)
import Ouroboros.Consensus.Protocol.Praos (Praos)
import qualified Ouroboros.Consensus.Protocol.Praos as Praos
Expand Down Expand Up @@ -77,4 +78,4 @@ instance
ShelleyCompatible (TPraos c) (BabbageEra c)

instance
(Praos.PraosCrypto c) => ShelleyCompatible (Praos c) (BabbageEra c)
(Era c, Praos.PraosCrypto c) => ShelleyCompatible (Praos c) (BabbageEra c)

0 comments on commit 473b5db

Please sign in to comment.