From 6ced601eb6fba892358ef3257a18ad8941d04f9f Mon Sep 17 00:00:00 2001 From: Thomas Winant Date: Mon, 23 Nov 2020 13:54:52 +0100 Subject: [PATCH] Update dependency on ouroboros-network Notable changes: * Share a single set of credentials for all Shelley-based eras: https://github.com/input-output-hk/ouroboros-network/pull/2753 * Add a pure Mary mode https://github.com/input-output-hk/ouroboros-network/pull/2754 --- cabal.project | 4 +- .../src/Cardano/Node/Configuration/Logging.hs | 3 ++ .../src/Cardano/Node/Protocol/Cardano.hs | 24 ++++----- .../src/Cardano/Node/Protocol/Shelley.hs | 22 ++++---- cardano-node/src/Cardano/Node/Query.hs | 54 ++++++++++++------- cardano-node/src/Cardano/Tracing/Metrics.hs | 12 +++-- cardano-node/src/Cardano/Tracing/Queries.hs | 2 +- 7 files changed, 70 insertions(+), 51 deletions(-) diff --git a/cabal.project b/cabal.project index 4221df0da9d..abda5714a2b 100644 --- a/cabal.project +++ b/cabal.project @@ -159,8 +159,8 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 9aa3cb03deb367f5f237ab694d2c9e01b6cf431f - --sha256: 0nn1ywww0drvvdsr0yqlgg0dmhjgz9zpdp3rmq94zihbpl4sms99 + tag: 57ab00435e6c38d146e029ac2d3f824ff6e738a8 + --sha256: 0l9nv0lr9wxf9z7gs91dvpci7ghfbk9d4mcly1mm5xd76d21jbbb subdir: io-sim io-sim-classes diff --git a/cardano-node/src/Cardano/Node/Configuration/Logging.hs b/cardano-node/src/Cardano/Node/Configuration/Logging.hs index 9c24ee1582f..8b527b9cfa8 100644 --- a/cardano-node/src/Cardano/Node/Configuration/Logging.hs +++ b/cardano-node/src/Cardano/Node/Configuration/Logging.hs @@ -259,6 +259,9 @@ nodeBasicInfo nc p nodeStartTime' = do Consensus.ProtocolShelley {} -> let DegenLedgerConfig cfgShelley = Consensus.configLedger cfg in getGenesisValues "Shelley" cfgShelley + Consensus.ProtocolMary {} -> + let DegenLedgerConfig cfgMary = Consensus.configLedger cfg + in getGenesisValues "Mary" cfgMary Consensus.ProtocolCardano {} -> let CardanoLedgerConfig cfgByron cfgShelley cfgAllegra cfgMary = Consensus.configLedger cfg in getGenesisValuesByron cfg cfgByron diff --git a/cardano-node/src/Cardano/Node/Protocol/Cardano.hs b/cardano-node/src/Cardano/Node/Protocol/Cardano.hs index c18ea74e0db..e3c490910f9 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Cardano.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Cardano.hs @@ -153,34 +153,30 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration { byronLeaderCredentials = byronLeaderCredentials } - Consensus.ProtocolParamsShelley { - shelleyGenesis = shelleyGenesis, - shelleyInitialNonce = + Consensus.ProtocolParamsShelleyBased { + shelleyBasedGenesis = shelleyGenesis, + shelleyBasedInitialNonce = Shelley.genesisHashToPraosNonce shelleyGenesisHash, + shelleyBasedLeaderCredentials = + shelleyLeaderCredentials + } + Consensus.ProtocolParamsShelley { shelleyProtVer = ProtVer npcShelleySupportedProtocolVersionMajor - npcShelleySupportedProtocolVersionMinor, - shelleyLeaderCredentials = - shelleyLeaderCredentials + npcShelleySupportedProtocolVersionMinor } Consensus.ProtocolParamsAllegra { allegraProtVer = ProtVer npcShelleySupportedProtocolVersionMajor - npcShelleySupportedProtocolVersionMinor, - allegraLeaderCredentials = - -- TODO: separate credentials for Allega - Nothing + npcShelleySupportedProtocolVersionMinor } Consensus.ProtocolParamsMary { maryProtVer = ProtVer npcShelleySupportedProtocolVersionMajor - npcShelleySupportedProtocolVersionMinor, - maryLeaderCredentials = - -- TODO: separate credentials for Mary - Nothing + npcShelleySupportedProtocolVersionMinor } -- ProtocolParamsTransition specifies the parameters needed to transition between two eras -- The comments below also apply for the Shelley -> Allegra and Allegra -> Mary hard forks. diff --git a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs index 23ad66280a5..fa9a45a3f2b 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs @@ -36,9 +36,9 @@ import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Cardano.ShelleyHFC -import Ouroboros.Consensus.Shelley.Node (Nonce (..), - ProtocolParamsShelley (..), ShelleyGenesis, TPraosLeaderCredentials (..)) -import Ouroboros.Consensus.Shelley.Protocol (TPraosCanBeLeader (..), StandardCrypto) +import Ouroboros.Consensus.Shelley.Node (Nonce (..), ProtocolParamsShelley (..), + ProtocolParamsShelleyBased (..), ShelleyGenesis, TPraosLeaderCredentials (..)) +import Ouroboros.Consensus.Shelley.Protocol (StandardCrypto, TPraosCanBeLeader (..)) import Shelley.Spec.Ledger.Genesis (ValidationErr (..), describeValidationErr, validateGenesis) @@ -101,16 +101,18 @@ mkConsensusProtocolShelley NodeShelleyProtocolConfiguration { firstExceptT GenesisValidationFailure . hoistEither $ validateGenesis genesis optionalLeaderCredentials <- readLeaderCredentials files - return $ - Consensus.ProtocolShelley $ Consensus.ProtocolParamsShelley { - shelleyGenesis = genesis, - shelleyInitialNonce = genesisHashToPraosNonce genesisHash, + return $ Consensus.ProtocolShelley + Consensus.ProtocolParamsShelleyBased { + shelleyBasedGenesis = genesis, + shelleyBasedInitialNonce = genesisHashToPraosNonce genesisHash, + shelleyBasedLeaderCredentials = + maybeToList optionalLeaderCredentials + } + Consensus.ProtocolParamsShelley { shelleyProtVer = ProtVer npcShelleySupportedProtocolVersionMajor - npcShelleySupportedProtocolVersionMinor, - shelleyLeaderCredentials = - maybeToList optionalLeaderCredentials + npcShelleySupportedProtocolVersionMinor } genesisHashToPraosNonce :: GenesisHash -> Nonce diff --git a/cardano-node/src/Cardano/Node/Query.hs b/cardano-node/src/Cardano/Node/Query.hs index 348d7365843..1dd061714c8 100644 --- a/cardano-node/src/Cardano/Node/Query.hs +++ b/cardano-node/src/Cardano/Node/Query.hs @@ -36,11 +36,13 @@ import qualified Cardano.Chain.Genesis as Byron import qualified Ouroboros.Consensus.Byron.Ledger.Conversions as Byron -- Shelley -import Ouroboros.Consensus.Shelley.Ledger.Ledger (shelleyLedgerGenesis) +import Ouroboros.Consensus.Shelley.Ledger (shelleyLedgerGenesis) import qualified Shelley.Spec.Ledger.API as SL -- Cardano import qualified Ouroboros.Consensus.Cardano as Consensus +import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) +import Ouroboros.Consensus.Cardano.ShelleyHFC (ShelleyBlockHFC) import qualified Ouroboros.Consensus.Cardano.CanHardFork as CanHardFork import Cardano.Tracing.Kernel @@ -68,26 +70,11 @@ answerQueryWithLedgerState answerQueryWithLedgerState protocol extLedgerState query = runIdentity $ case protocol of Consensus.ProtocolByron {} -> - let DegenLedgerConfig ledgerConfig = configLedger cfg - genesis = CanHardFork.byronLedgerConfig ledgerConfig - epochSize = Byron.fromByronEpochSlots $ Byron.configEpochSlots genesis - slotLength = Byron.fromByronSlotLength $ Byron.genesisSlotLength genesis - in HF.singleEraCompatQuery - epochSize - slotLength - answerQueryHelper - query + byronQuery Consensus.ProtocolShelley {} -> - let DegenLedgerConfig ledgerConfig = configLedger cfg - genesis = shelleyLedgerGenesis $ - CanHardFork.shelleyLedgerConfig ledgerConfig - epochSize = SL.sgEpochLength genesis - slotLength = WCT.mkSlotLength $ SL.sgSlotLength genesis - in HF.singleEraCompatQuery - epochSize - slotLength - answerQueryHelper - query + shelleyBasedQuery + Consensus.ProtocolMary {} -> + shelleyBasedQuery Consensus.ProtocolCardano {} -> HF.forwardCompatQuery answerQueryHelper @@ -103,6 +90,33 @@ answerQueryWithLedgerState protocol extLedgerState query = runIdentity $ answerQueryHelper q = pure $ Consensus.answerQuery (ExtLedgerCfg cfg) q extLedgerState + byronQuery :: blk ~ ByronBlockHFC => Identity result + byronQuery = + HF.singleEraCompatQuery + epochSize + slotLength + answerQueryHelper + query + where + DegenLedgerConfig ledgerConfig = configLedger cfg + genesis = CanHardFork.byronLedgerConfig ledgerConfig + epochSize = Byron.fromByronEpochSlots $ Byron.configEpochSlots genesis + slotLength = Byron.fromByronSlotLength $ Byron.genesisSlotLength genesis + + shelleyBasedQuery :: blk ~ ShelleyBlockHFC era => Identity result + shelleyBasedQuery = + HF.singleEraCompatQuery + epochSize + slotLength + answerQueryHelper + query + where + DegenLedgerConfig ledgerConfig = configLedger cfg + genesis = shelleyLedgerGenesis $ + CanHardFork.shelleyLedgerConfig ledgerConfig + epochSize = SL.sgEpochLength genesis + slotLength = WCT.mkSlotLength $ SL.sgSlotLength genesis + -- | To avoid confusing 'HFI.Qry' with 'HF.Query' and 'HF.HardForkCompatQuery, -- we introduce a type synonym for the former which we can use in docstrings -- (and type signatures, of course). diff --git a/cardano-node/src/Cardano/Tracing/Metrics.hs b/cardano-node/src/Cardano/Tracing/Metrics.hs index 0e3d6cc2218..c67f90e1f32 100644 --- a/cardano-node/src/Cardano/Tracing/Metrics.hs +++ b/cardano-node/src/Cardano/Tracing/Metrics.hs @@ -4,6 +4,7 @@ {-# LANGUAGE DisambiguateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE UndecidableInstances #-} @@ -77,10 +78,13 @@ instance HasKESMetricsData ByronBlock where instance All HasKESMetricsData xs => HasKESMetricsData (HardForkBlock xs) where getKESMetricsData _ forgeStateInfo = - hcollapse - . hcmap (Proxy @HasKESMetricsData) getOne - . getOneEraForgeStateInfo - $ forgeStateInfo + case forgeStateInfo of + CurrentEraLacksBlockForging _ -> NoKESMetricsData + CurrentEraForgeStateUpdated currentEraForgeStateInfo -> + hcollapse + . hcmap (Proxy @HasKESMetricsData) getOne + . getOneEraForgeStateInfo + $ currentEraForgeStateInfo where getOne :: forall blk. HasKESMetricsData blk => WrapForgeStateInfo blk diff --git a/cardano-node/src/Cardano/Tracing/Queries.hs b/cardano-node/src/Cardano/Tracing/Queries.hs index d2435a56b88..234a39e6fa2 100644 --- a/cardano-node/src/Cardano/Tracing/Queries.hs +++ b/cardano-node/src/Cardano/Tracing/Queries.hs @@ -11,7 +11,7 @@ import Prelude (Int, (.)) import qualified Data.Map.Strict as Map import Ouroboros.Consensus.HardFork.Combinator -import Ouroboros.Consensus.HardFork.Combinator.Unary +import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary import qualified Cardano.Chain.Block as Byron import qualified Cardano.Chain.UTxO as Byron