diff --git a/ouroboros-consensus-cardano/changelog.d/20240823_131440_damian.nadales_324_simplify_protver_arguments.md b/ouroboros-consensus-cardano/changelog.d/20240823_131440_damian.nadales_324_simplify_protver_arguments.md new file mode 100644 index 0000000000..79d1c65364 --- /dev/null +++ b/ouroboros-consensus-cardano/changelog.d/20240823_131440_damian.nadales_324_simplify_protver_arguments.md @@ -0,0 +1,5 @@ +### Breaking + +- ProtocolParams (CardanoBlock c) was monomorphized to `CardanoProtocolParams` +- Remove `cardanoProtocolParamsPerEra` from `CardanoProtocolParams` in favour of a single `cardanoProtocolVersion`. + This patch intentionally removes the flexibility the n-ary product of versions per-era gave us, in favour of a simpler interface, as the current one has caused a lot of confusion and led to several mistakes in the past. diff --git a/ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs b/ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs index 9f5f868d99..5e0b6ddff7 100644 --- a/ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs +++ b/ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs @@ -18,7 +18,7 @@ module Ouroboros.Consensus.Byron.Node ( , mkByronLeaderCredentials , mkPBftCanBeLeader -- * ProtocolInfo - , ProtocolParams (..) + , ProtocolParamsByron (..) , defaultPBftSignatureThreshold , mkByronConfig , protocolClientInfoByron @@ -152,7 +152,7 @@ mkPBftCanBeLeader (ByronLeaderCredentials sk cert nid _) = PBftCanBeLeader { } blockForgingByron :: Monad m - => ProtocolParams ByronBlock + => ProtocolParamsByron -> [BlockForging m ByronBlock] blockForgingByron ProtocolParamsByron { byronLeaderCredentials = mLeaderCreds } = @@ -169,7 +169,7 @@ defaultPBftSignatureThreshold :: PBftSignatureThreshold defaultPBftSignatureThreshold = PBftSignatureThreshold 0.22 -- | Parameters needed to run Byron -data instance ProtocolParams ByronBlock = ProtocolParamsByron { +data ProtocolParamsByron = ProtocolParamsByron { byronGenesis :: Genesis.Config , byronPbftSignatureThreshold :: Maybe PBftSignatureThreshold , byronProtocolVersion :: Update.ProtocolVersion @@ -177,7 +177,7 @@ data instance ProtocolParams ByronBlock = ProtocolParamsByron { , byronLeaderCredentials :: Maybe ByronLeaderCredentials } -protocolInfoByron :: ProtocolParams ByronBlock +protocolInfoByron :: ProtocolParamsByron -> ProtocolInfo ByronBlock protocolInfoByron ProtocolParamsByron { byronGenesis = genesisConfig diff --git a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano.hs b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano.hs index 8c0f78f6d4..6d8768be45 100644 --- a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano.hs +++ b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano.hs @@ -9,7 +9,6 @@ module Ouroboros.Consensus.Cardano ( , ProtocolShelley -- * Abstract over the various protocols , CardanoHardForkTriggers (..) - , ProtocolParams (..) , module X ) where diff --git a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs index 058a947345..700626382a 100644 --- a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs +++ b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs @@ -34,9 +34,8 @@ module Ouroboros.Consensus.Cardano.Node ( CardanoHardForkConstraints , CardanoHardForkTriggers (.., CardanoHardForkTriggers', triggerHardForkShelley, triggerHardForkAllegra, triggerHardForkMary, triggerHardForkAlonzo, triggerHardForkBabbage, triggerHardForkConway) - , CardanoProtocolParams + , CardanoProtocolParams (..) , MaxMajorProtVer (..) - , ProtocolParams (.., CardanoProtocolParams, paramsByron, paramsShelleyBased, paramsShelley, paramsAllegra, paramsMary, paramsAlonzo, paramsBabbage, paramsConway, hardForkTriggers, ledgerTransitionConfig, checkpoints) , TriggerHardFork (..) , protocolClientInfoCardano , protocolInfoCardano @@ -77,7 +76,6 @@ import qualified Data.Map.Strict as Map import Data.SOP.BasicFunctors import Data.SOP.Counting import Data.SOP.Index (Index (..)) -import Data.SOP.NonEmpty import Data.SOP.OptNP (NonEmptyOptNP, OptNP (OptSkip)) import qualified Data.SOP.OptNP as OptNP import Data.SOP.Strict @@ -93,8 +91,6 @@ import Ouroboros.Consensus.Cardano.Block import Ouroboros.Consensus.Cardano.CanHardFork import Ouroboros.Consensus.Config import Ouroboros.Consensus.HardFork.Combinator -import Ouroboros.Consensus.HardFork.Combinator.AcrossEras - (PerEraProtocolParams (..)) import Ouroboros.Consensus.HardFork.Combinator.Embed.Nary import Ouroboros.Consensus.HardFork.Combinator.Serialisation import qualified Ouroboros.Consensus.HardFork.History as History @@ -521,61 +517,57 @@ pattern CardanoHardForkTriggers' { {-# COMPLETE CardanoHardForkTriggers' #-} -- | Parameters needed to run Cardano. -data instance ProtocolParams (CardanoBlock c) = ProtocolParamsCardano { - cardanoProtocolParamsPerEra :: PerEraProtocolParams (CardanoEras c) +-- +-- __On the relation between 'cardanoHardForkTriggers' and 'cardanoProtocolVersion'__: +-- +-- The 'cardanoHardForkTriggers' can mention __ledger__ protocol +-- version versions at which the hard fork will occur. In principle +-- there is no relation between the versions mentioned in +-- 'cardanoProtocolVerson' (if any) and 'cardanoHardForkTriggers', +-- however their relationship might indicate experimental eras or +-- intra-era hard forks. For instance if the last era in the +-- 'CardanoHardForkTriggers' is set to @9 0@, ie: +-- +-- > ... :* TriggerHardForkAtVersion (ProtVer (SL.natVersion @9) 0) +-- +-- Setting 'cardanoProtocolVersion' to @ProtVer (SL.natVersion @8) 0@ +-- will mark that last era as experimental because the obsolete node +-- checks determine that the highest version we support is @8 0@. +-- +-- If, on the other hand, we would set 'cardanoProtocolVersion' to +-- @ProtVer (SL.natVersion @10) 0@, this indicates that the node is +-- ready to perform an intra-era hardfork (from version @9@ to version +-- @10@). +-- +data CardanoProtocolParams c = CardanoProtocolParams { + byronProtocolParams :: ProtocolParamsByron , shelleyBasedProtocolParams :: ProtocolParamsShelleyBased c , cardanoHardForkTriggers :: CardanoHardForkTriggers , cardanoLedgerTransitionConfig :: L.TransitionConfig (L.LatestKnownEra c) , cardanoCheckpoints :: CheckpointsMap (CardanoBlock c) + -- | The greatest protocol version that this node's software and config + -- files declare to handle correctly. + -- + -- This parameter has three consequences. First, the blocks minted + -- will include the protocol version in their header, but + -- essentially only for public signaling (eg measuring the + -- percentage of adoption of software updates). + -- + -- Second, and more importantly, it's passed to the protocol logic. In + -- particular, the node's envelope check will begin rejecting all blocks + -- (actually, their headers) if the chain moves to a greater protocol + -- version. This should never happen in a node that is using up-to-date + -- software and config files. Note that the missing software update is + -- not necessarily a 'HardForkBlock' era transition: it might be an + -- /intra-era hard fork/ (ie conditionals in the ledger rules). + -- + -- Third, it's passed to the ledger rules---but that's entirely + -- vestigial. See + -- . + -- + , cardanoProtocolVersion :: ProtVer } -type CardanoProtocolParams c = ProtocolParams (CardanoBlock c) - -pattern CardanoProtocolParams :: - ProtocolParams ByronBlock - -> ProtocolParamsShelleyBased c - -> ProtocolParams (ShelleyBlock (TPraos c) (ShelleyEra c)) - -> ProtocolParams (ShelleyBlock (TPraos c) (AllegraEra c)) - -> ProtocolParams (ShelleyBlock (TPraos c) (MaryEra c)) - -> ProtocolParams (ShelleyBlock (TPraos c) (AlonzoEra c)) - -> ProtocolParams (ShelleyBlock (Praos c) (BabbageEra c)) - -> ProtocolParams (ShelleyBlock (Praos c) (ConwayEra c)) - -> CardanoHardForkTriggers - -> L.TransitionConfig (L.LatestKnownEra c) - -> CheckpointsMap (CardanoBlock c) - -> CardanoProtocolParams c -pattern CardanoProtocolParams { - paramsByron - , paramsShelleyBased - , paramsShelley - , paramsAllegra - , paramsMary - , paramsAlonzo - , paramsBabbage - , paramsConway - , hardForkTriggers - , ledgerTransitionConfig - , checkpoints - } = - ProtocolParamsCardano { - cardanoProtocolParamsPerEra = PerEraProtocolParams - ( paramsByron - :* paramsShelley - :* paramsAllegra - :* paramsMary - :* paramsAlonzo - :* paramsBabbage - :* paramsConway - :* Nil - ) - , shelleyBasedProtocolParams = paramsShelleyBased - , cardanoHardForkTriggers = hardForkTriggers - , cardanoLedgerTransitionConfig = ledgerTransitionConfig - , cardanoCheckpoints = checkpoints - } - -{-# COMPLETE CardanoProtocolParams #-} - -- | Create a 'ProtocolInfo' for 'CardanoBlock' -- -- NOTE: For testing and benchmarking purposes, the 'ShelleyGenesis' can contain @@ -607,15 +599,9 @@ protocolInfoCardano paramsCardano ) where CardanoProtocolParams { - paramsByron - , paramsShelleyBased - , paramsShelley - , paramsAllegra - , paramsMary - , paramsAlonzo - , paramsBabbage - , paramsConway - , hardForkTriggers = CardanoHardForkTriggers' { + byronProtocolParams + , shelleyBasedProtocolParams + , cardanoHardForkTriggers = CardanoHardForkTriggers' { triggerHardForkShelley , triggerHardForkAllegra , triggerHardForkMary @@ -623,68 +609,34 @@ protocolInfoCardano paramsCardano , triggerHardForkBabbage , triggerHardForkConway } - , ledgerTransitionConfig - , checkpoints + , cardanoLedgerTransitionConfig + , cardanoCheckpoints + , cardanoProtocolVersion } = paramsCardano - genesisShelley = ledgerTransitionConfig ^. L.tcShelleyGenesisL + genesisShelley = cardanoLedgerTransitionConfig ^. L.tcShelleyGenesisL ProtocolParamsByron { byronGenesis = genesisByron , byronLeaderCredentials = mCredsByron - } = paramsByron + } = byronProtocolParams ProtocolParamsShelleyBased { shelleyBasedInitialNonce = initialNonceShelley , shelleyBasedLeaderCredentials = credssShelleyBased - } = paramsShelleyBased - ProtocolParamsShelley { - shelleyProtVer = protVerShelley - } = paramsShelley - ProtocolParamsAllegra { - allegraProtVer = protVerAllegra - } = paramsAllegra - ProtocolParamsMary { - maryProtVer = protVerMary - } = paramsMary - ProtocolParamsAlonzo { - alonzoProtVer = protVerAlonzo - } = paramsAlonzo - ProtocolParamsBabbage { - babbageProtVer = protVerBabbage - } = paramsBabbage - ProtocolParamsConway { - conwayProtVer = protVerConway - } = paramsConway + } = shelleyBasedProtocolParams transitionConfigShelley = transitionConfigAllegra ^. L.tcPreviousEraConfigL transitionConfigAllegra = transitionConfigMary ^. L.tcPreviousEraConfigL transitionConfigMary = transitionConfigAlonzo ^. L.tcPreviousEraConfigL transitionConfigAlonzo = transitionConfigBabbage ^. L.tcPreviousEraConfigL transitionConfigBabbage = transitionConfigConway ^. L.tcPreviousEraConfigL - transitionConfigConway = ledgerTransitionConfig + transitionConfigConway = cardanoLedgerTransitionConfig -- The major protocol version of the last era is the maximum major protocol -- version we support. -- - -- TODO: use index of CardanoProtocolParams NP maxMajorProtVer :: MaxMajorProtVer - maxMajorProtVer = - MaxMajorProtVer - $ pvMajor - $ nonEmptyLast - $ exactlyWeakenNonEmpty - $ protVers - where - protVers :: Exactly (CardanoShelleyEras StandardCrypto) ProtVer - protVers = Exactly $ - -- ensure that these have the same order as 'CardanoShelleyEras'! - K protVerShelley :* - K protVerAllegra :* - K protVerMary :* - K protVerAlonzo :* - K protVerBabbage :* - K protVerConway :* - Nil + maxMajorProtVer = MaxMajorProtVer $ pvMajor cardanoProtocolVersion -- Byron @@ -695,7 +647,7 @@ protocolInfoCardano paramsCardano , topLevelConfigBlock = blockConfigByron } , pInfoInitLedger = initExtLedgerStateByron - } = protocolInfoByron paramsByron + } = protocolInfoByron byronProtocolParams partialConsensusConfigByron :: PartialConsensusConfig (BlockProtocol ByronBlock) partialConsensusConfigByron = consensusConfigByron @@ -744,7 +696,7 @@ protocolInfoCardano paramsCardano blockConfigShelley :: BlockConfig (ShelleyBlock (TPraos c) (ShelleyEra c)) blockConfigShelley = Shelley.mkShelleyBlockConfig - protVerShelley + cardanoProtocolVersion genesisShelley (shelleyBlockIssuerVKey <$> credssShelleyBased) @@ -767,7 +719,7 @@ protocolInfoCardano paramsCardano blockConfigAllegra :: BlockConfig (ShelleyBlock (TPraos c) (AllegraEra c)) blockConfigAllegra = Shelley.mkShelleyBlockConfig - protVerAllegra + cardanoProtocolVersion genesisShelley (shelleyBlockIssuerVKey <$> credssShelleyBased) @@ -787,7 +739,7 @@ protocolInfoCardano paramsCardano blockConfigMary :: BlockConfig (ShelleyBlock (TPraos c) (MaryEra c)) blockConfigMary = Shelley.mkShelleyBlockConfig - protVerMary + cardanoProtocolVersion genesisShelley (shelleyBlockIssuerVKey <$> credssShelleyBased) @@ -807,7 +759,7 @@ protocolInfoCardano paramsCardano blockConfigAlonzo :: BlockConfig (ShelleyBlock (TPraos c) (AlonzoEra c)) blockConfigAlonzo = Shelley.mkShelleyBlockConfig - protVerAlonzo + cardanoProtocolVersion genesisShelley (shelleyBlockIssuerVKey <$> credssShelleyBased) @@ -827,7 +779,7 @@ protocolInfoCardano paramsCardano blockConfigBabbage :: BlockConfig (ShelleyBlock (Praos c) (BabbageEra c)) blockConfigBabbage = Shelley.mkShelleyBlockConfig - protVerBabbage + cardanoProtocolVersion genesisShelley (shelleyBlockIssuerVKey <$> credssShelleyBased) @@ -857,7 +809,7 @@ protocolInfoCardano paramsCardano blockConfigConway :: BlockConfig (ShelleyBlock (Praos c) (ConwayEra c)) blockConfigConway = Shelley.mkShelleyBlockConfig - protVerConway + cardanoProtocolVersion genesisShelley (shelleyBlockIssuerVKey <$> credssShelleyBased) @@ -944,7 +896,7 @@ protocolInfoCardano paramsCardano (Shelley.ShelleyStorageConfig tpraosSlotsPerKESPeriod k) (Shelley.ShelleyStorageConfig tpraosSlotsPerKESPeriod k) (Shelley.ShelleyStorageConfig tpraosSlotsPerKESPeriod k) - , topLevelConfigCheckpoints = checkpoints + , topLevelConfigCheckpoints = cardanoCheckpoints } -- When the initial ledger state is not in the Byron era, register the diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node.hs index ab0e23cd81..b0b9349bea 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node.hs @@ -14,7 +14,6 @@ module Ouroboros.Consensus.Shelley.Node ( MaxMajorProtVer (..) - , ProtocolParams (..) , ProtocolParamsShelleyBased (..) , SL.Nonce (..) , SL.ProtVer (..) @@ -44,7 +43,6 @@ 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.Praos import Ouroboros.Consensus.Shelley.Node.Serialisation () import Ouroboros.Consensus.Shelley.Node.TPraos import Ouroboros.Consensus.Shelley.Protocol.Abstract (pHeaderIssuer) diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Praos.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Praos.hs index dac56748d3..b388395280 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Praos.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Praos.hs @@ -16,26 +16,21 @@ module Ouroboros.Consensus.Shelley.Node.Praos ( -- * BlockForging praosBlockForging , praosSharedBlockForging - -- * ProtocolInfo - , ProtocolParams (..) ) where import qualified Cardano.Ledger.Api.Era as L -import qualified Cardano.Ledger.Shelley.API as SL import qualified Cardano.Protocol.TPraos.OCert as Absolute import qualified Cardano.Protocol.TPraos.OCert as SL import qualified Data.Text as T import Ouroboros.Consensus.Block import Ouroboros.Consensus.Config (configConsensus) import qualified Ouroboros.Consensus.Mempool as Mempool -import Ouroboros.Consensus.Node.ProtocolInfo import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..), praosCheckCanForge) import Ouroboros.Consensus.Protocol.Praos.Common (PraosCanBeLeader (praosCanBeLeaderOpCert)) -import Ouroboros.Consensus.Shelley.Eras (BabbageEra, ConwayEra, - EraCrypto) +import Ouroboros.Consensus.Shelley.Eras (EraCrypto) import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock, ShelleyCompatible, forgeShelleyBlock) import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto, @@ -112,17 +107,3 @@ praosSharedBlockForging canBeLeader cfg } - -{------------------------------------------------------------------------------- - ProtocolInfo --------------------------------------------------------------------------------} - -data instance ProtocolParams (ShelleyBlock (Praos c) (BabbageEra c)) = ProtocolParamsBabbage { - babbageProtVer :: SL.ProtVer - -- ^ see 'Ouroboros.Consensus.Shelley.Node.TPraos.shelleyProtVer', mutatis mutandi - } - -data instance ProtocolParams (ShelleyBlock (Praos c) (ConwayEra c)) = ProtocolParamsConway { - conwayProtVer :: SL.ProtVer - -- ^ see 'Ouroboros.Consensus.Shelley.Node.TPraos.shelleyProtVer', mutatis mutandi - } diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs index da55810792..d6ed3ab460 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs @@ -18,7 +18,6 @@ module Ouroboros.Consensus.Shelley.Node.TPraos ( MaxMajorProtVer (..) - , ProtocolParams (..) , ProtocolParamsShelleyBased (..) , SL.Nonce (..) , SL.ProtVer (..) @@ -170,59 +169,6 @@ validateGenesis = first errsToString . SL.validateGenesis Text.unpack $ Text.unlines ("Invalid genesis config:" : map SL.describeValidationErr errs) --- | Parameters needed to run Shelley -data instance ProtocolParams (ShelleyBlock (TPraos c) (ShelleyEra c)) = ProtocolParamsShelley { - -- | The greatest protocol version that this node's software and config - -- files declare to handle correctly in the Shelley era (ie the Cardano - -- era that is after Byron and before Allegra) - -- - -- This parameter has three consequences. First, the blocks minted in the - -- (first) Shelley era will include it in their header, but essentially - -- only for public signaling (eg measuring the adoption of software - -- updates). - -- - -- Second, and more importantly, it's passed to the protocol logic. In - -- particular, the node's envelope check will begin rejecting all blocks - -- (actually, their headers) if the chain moves to a greater protocol - -- version. This should never happen in a node that is using up-to-date - -- software and config files. Note that the missing software update is - -- not necessarily a 'HardForkBlock' era transition: it might be an - -- /intra-era hard fork/ (ie conditionals in the ledger rules). - -- - -- Third, it's passed to the ledger rules---but that's entirely - -- vestigial. See - -- . - -- - -- TODO 'Ouroboros.Consensus.Cardano.Node.protocolInfoCardano' always - -- passes this parameter to the Shelley era block minting thread. - -- However, the protocol and the ledger rules instead receive this - -- parameter from the final - -- 'Ouroboros.Consensus.HardFork.Combinator.Basics.HardForkBlock' era. - -- Since the HFC doesn't use the 'ShelleyEra' code when the protocol - -- version increments past 'shelleyProtVer', this isn't an important - -- discrepancy. The key aspects of the comment before this TODO are only - -- important for the last era prot ver limit, anyway. - shelleyProtVer :: SL.ProtVer - } - --- | Parameters needed to run Allegra -data instance ProtocolParams (ShelleyBlock (TPraos c) (AllegraEra c)) = ProtocolParamsAllegra { - allegraProtVer :: SL.ProtVer - -- ^ see 'shelleyProtVer', mutatis mutandi - } - --- | Parameters needed to run Mary -data instance ProtocolParams (ShelleyBlock (TPraos c) (MaryEra c)) = ProtocolParamsMary { - maryProtVer :: SL.ProtVer - -- ^ see 'shelleyProtVer', mutatis mutandi - } - --- | Parameters needed to run Alonzo -data instance ProtocolParams (ShelleyBlock (TPraos c) (AlonzoEra c)) = ProtocolParamsAlonzo { - alonzoProtVer :: SL.ProtVer - -- ^ see 'shelleyProtVer', mutatis mutandi - } - protocolInfoShelley :: forall m c. ( IOLike m @@ -232,15 +178,13 @@ protocolInfoShelley :: ) => SL.ShelleyGenesis c -> ProtocolParamsShelleyBased c - -> ProtocolParams (ShelleyBlock (TPraos c) (ShelleyEra c)) + -> SL.ProtVer -> ( ProtocolInfo (ShelleyBlock (TPraos c) (ShelleyEra c) ) , m [BlockForging m (ShelleyBlock (TPraos c) (ShelleyEra c))] ) protocolInfoShelley shelleyGenesis protocolParamsShelleyBased - ProtocolParamsShelley { - shelleyProtVer = protVer - } = + protVer = protocolInfoTPraosShelleyBased protocolParamsShelleyBased (L.mkShelleyTransitionConfig shelleyGenesis) diff --git a/ouroboros-consensus-cardano/src/unstable-byron-testlib/Test/ThreadNet/Infra/Byron/ProtocolInfo.hs b/ouroboros-consensus-cardano/src/unstable-byron-testlib/Test/ThreadNet/Infra/Byron/ProtocolInfo.hs index 8628828395..7f2844daf8 100644 --- a/ouroboros-consensus-cardano/src/unstable-byron-testlib/Test/ThreadNet/Infra/Byron/ProtocolInfo.hs +++ b/ouroboros-consensus-cardano/src/unstable-byron-testlib/Test/ThreadNet/Infra/Byron/ProtocolInfo.hs @@ -58,7 +58,7 @@ mkProtocolByron params coreNodeId genesisConfig genesisSecrets = blockForging :: [BlockForging m ByronBlock] blockForging = blockForgingByron protocolParams - protocolParams :: ProtocolParams ByronBlock + protocolParams :: ProtocolParamsByron protocolParams = ProtocolParamsByron { byronGenesis = genesisConfig , byronPbftSignatureThreshold = Just $ pbftSignatureThreshold diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/ProtocolInfo.hs b/ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/ProtocolInfo.hs index 04996e4978..ecae697118 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/ProtocolInfo.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/ProtocolInfo.hs @@ -20,6 +20,7 @@ module Test.Consensus.Cardano.ProtocolInfo ( -- * ProtocolInfo elaboration , mkSimpleTestProtocolInfo , mkTestProtocolInfo + , protocolVersionZero ) where import qualified Cardano.Chain.Genesis as CC.Genesis @@ -34,11 +35,11 @@ import Data.Word (Word64) import Ouroboros.Consensus.Block.Forging (BlockForging) import Ouroboros.Consensus.BlockchainTime (SlotLength) import Ouroboros.Consensus.Byron.Node (ByronLeaderCredentials, - ProtocolParams (..), byronGenesis, + ProtocolParamsByron (..), byronGenesis, byronPbftSignatureThreshold, byronSoftwareVersion) import Ouroboros.Consensus.Cardano.Block (CardanoBlock) import Ouroboros.Consensus.Cardano.Node (CardanoHardForkConstraints, - CardanoHardForkTriggers (..), ProtocolParams (..), + CardanoHardForkTriggers (..), CardanoProtocolParams (..), TriggerHardFork (TriggerHardForkAtEpoch, TriggerHardForkNotDuringThisExecution), protocolInfoCardano) import Ouroboros.Consensus.Config (emptyCheckpointsMap) @@ -81,12 +82,12 @@ instance ToSlotLength ShelleySlotLengthInSeconds where -- for examples. data HardForkSpec = HardForkSpec { - shelleyHardForkSpec :: (SL.ProtVer, TriggerHardFork) - , allegraHardForkSpec :: (SL.ProtVer, TriggerHardFork) - , maryHardForkSpec :: (SL.ProtVer, TriggerHardFork) - , alonzoHardForkSpec :: (SL.ProtVer, TriggerHardFork) - , babbageHardForkSpec :: (SL.ProtVer, TriggerHardFork) - , conwayHardForkSpec :: (SL.ProtVer, TriggerHardFork) + shelleyHardForkSpec :: TriggerHardFork + , allegraHardForkSpec :: TriggerHardFork + , maryHardForkSpec :: TriggerHardFork + , alonzoHardForkSpec :: TriggerHardFork + , babbageHardForkSpec :: TriggerHardFork + , conwayHardForkSpec :: TriggerHardFork } data Era = Byron @@ -98,7 +99,7 @@ data Era = Byron | Conway deriving (Show, Eq, Ord, Enum) -selectEra :: Era -> HardForkSpec -> (SL.ProtVer, TriggerHardFork) +selectEra :: Era -> HardForkSpec -> TriggerHardFork selectEra Byron _ = error "Byron is the first era, therefore there is no hard fork spec." selectEra Shelley HardForkSpec { shelleyHardForkSpec } = shelleyHardForkSpec selectEra Allegra HardForkSpec { allegraHardForkSpec } = allegraHardForkSpec @@ -107,48 +108,43 @@ selectEra Alonzo HardForkSpec { alonzoHardForkSpec } = alonzoHardForkSpec selectEra Babbage HardForkSpec { babbageHardForkSpec } = babbageHardForkSpec selectEra Conway HardForkSpec { conwayHardForkSpec } = conwayHardForkSpec -hfSpecProtVer :: Era -> HardForkSpec -> SL.ProtVer -hfSpecProtVer era = fst . selectEra era - -hfSpecTransitionTrigger :: Era -> HardForkSpec -> TriggerHardFork -hfSpecTransitionTrigger era = snd . selectEra era - stayInByron :: HardForkSpec stayInByron = HardForkSpec { - shelleyHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkNotDuringThisExecution) - , allegraHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkNotDuringThisExecution) - , maryHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkNotDuringThisExecution) - , alonzoHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkNotDuringThisExecution) - , babbageHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkNotDuringThisExecution) - , conwayHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkNotDuringThisExecution) + shelleyHardForkSpec = TriggerHardForkNotDuringThisExecution + , allegraHardForkSpec = TriggerHardForkNotDuringThisExecution + , maryHardForkSpec = TriggerHardForkNotDuringThisExecution + , alonzoHardForkSpec = TriggerHardForkNotDuringThisExecution + , babbageHardForkSpec = TriggerHardForkNotDuringThisExecution + , conwayHardForkSpec = TriggerHardForkNotDuringThisExecution } -versionZero :: SL.Version -versionZero = SL.natVersion @0 +protocolVersionZero :: SL.ProtVer +protocolVersionZero = SL.ProtVer versionZero 0 + where + versionZero :: SL.Version + versionZero = SL.natVersion @0 --- TODO: could be simplified once we implement something like --- ouroboros-network#4115. hardForkInto :: Era -> HardForkSpec hardForkInto Byron = stayInByron hardForkInto Shelley = stayInByron - { shelleyHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) } + { shelleyHardForkSpec = TriggerHardForkAtEpoch 0 } hardForkInto Allegra = (hardForkInto Shelley) - { allegraHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) } + { allegraHardForkSpec = TriggerHardForkAtEpoch 0 } hardForkInto Mary = (hardForkInto Allegra) - { maryHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) } + { maryHardForkSpec = TriggerHardForkAtEpoch 0 } hardForkInto Alonzo = (hardForkInto Mary) - { alonzoHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) } + { alonzoHardForkSpec = TriggerHardForkAtEpoch 0 } hardForkInto Babbage = (hardForkInto Alonzo) - { babbageHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) } + { babbageHardForkSpec = TriggerHardForkAtEpoch 0 } hardForkInto Conway = (hardForkInto Babbage) - { conwayHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) } + { conwayHardForkSpec = TriggerHardForkAtEpoch 0 } {------------------------------------------------------------------------------- ProtocolInfo elaboration @@ -183,6 +179,7 @@ mkSimpleTestProtocolInfo :: -> SecurityParam -> ByronSlotLengthInSeconds -> ShelleySlotLengthInSeconds + -> SL.ProtVer -> HardForkSpec -> ProtocolInfo (CardanoBlock c) mkSimpleTestProtocolInfo @@ -190,6 +187,7 @@ mkSimpleTestProtocolInfo securityParam byronSlotLenghtInSeconds shelleySlotLengthInSeconds + protocolVersion hardForkSpec = fst $ mkTestProtocolInfo @IO @@ -200,6 +198,7 @@ mkSimpleTestProtocolInfo genesisByron generatedSecretsByron (Just $ PBftSignatureThreshold 1) + protocolVersion hardForkSpec where byronProtocolVersion = @@ -223,7 +222,7 @@ mkSimpleTestProtocolInfo shelleyGenesis :: ShelleyGenesis c shelleyGenesis = Shelley.mkGenesisConfig - (hfSpecProtVer Shelley hardForkSpec) + protocolVersion securityParam activeSlotCoeff decentralizationParam @@ -256,6 +255,10 @@ mkTestProtocolInfo :: -> CC.Genesis.Config -> CC.Genesis.GeneratedSecrets -> Maybe PBftSignatureThreshold + -> SL.ProtVer + -- ^ See 'protocolInfoCardano' for the details of what is the + -- relation between this version and any 'TriggerHardForkAtVersion' + -- that __might__ appear in the 'HardForkSpec' parameter. -> HardForkSpec -- ^ Specification of the era to which the initial state should hard-fork to. -> (ProtocolInfo (CardanoBlock c), m [BlockForging m (CardanoBlock c)]) @@ -267,6 +270,7 @@ mkTestProtocolInfo genesisByron generatedSecretsByron aByronPbftSignatureThreshold + protocolVersion hardForkSpec = protocolInfoCardano @@ -282,31 +286,13 @@ mkTestProtocolInfo shelleyBasedInitialNonce = initialNonce , shelleyBasedLeaderCredentials = [leaderCredentialsShelley] } - ProtocolParamsShelley { - shelleyProtVer = hfSpecProtVer Shelley hardForkSpec - } - ProtocolParamsAllegra { - allegraProtVer = hfSpecProtVer Allegra hardForkSpec - } - ProtocolParamsMary { - maryProtVer = hfSpecProtVer Mary hardForkSpec - } - ProtocolParamsAlonzo { - alonzoProtVer = hfSpecProtVer Alonzo hardForkSpec - } - ProtocolParamsBabbage { - babbageProtVer = hfSpecProtVer Babbage hardForkSpec - } - ProtocolParamsConway { - conwayProtVer = hfSpecProtVer Conway hardForkSpec - } CardanoHardForkTriggers' { - triggerHardForkShelley = hfSpecTransitionTrigger Shelley hardForkSpec - , triggerHardForkAllegra = hfSpecTransitionTrigger Allegra hardForkSpec - , triggerHardForkMary = hfSpecTransitionTrigger Mary hardForkSpec - , triggerHardForkAlonzo = hfSpecTransitionTrigger Alonzo hardForkSpec - , triggerHardForkBabbage = hfSpecTransitionTrigger Babbage hardForkSpec - , triggerHardForkConway = hfSpecTransitionTrigger Conway hardForkSpec + triggerHardForkShelley = selectEra Shelley hardForkSpec + , triggerHardForkAllegra = selectEra Allegra hardForkSpec + , triggerHardForkMary = selectEra Mary hardForkSpec + , triggerHardForkAlonzo = selectEra Alonzo hardForkSpec + , triggerHardForkBabbage = selectEra Babbage hardForkSpec + , triggerHardForkConway = selectEra Conway hardForkSpec } ( L.mkLatestTransitionConfig shelleyGenesis @@ -321,6 +307,7 @@ mkTestProtocolInfo SL.exampleConwayGenesis ) emptyCheckpointsMap + protocolVersion ) where diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs index 1a83bc8844..713624368b 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs @@ -20,7 +20,6 @@ module Cardano.Api.Protocol.Types ( import Cardano.Chain.Slotting (EpochSlots) import Data.Bifunctor (bimap) import Ouroboros.Consensus.Block.Forging (BlockForging) -import qualified Ouroboros.Consensus.Byron.Ledger.Block as Consensus import Ouroboros.Consensus.Cardano import Ouroboros.Consensus.Cardano.Block import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) @@ -58,7 +57,7 @@ class RunNode blk => ProtocolClient blk where -- | Run PBFT against the Byron ledger instance IOLike m => Protocol m ByronBlockHFC where - data ProtocolInfoArgs m ByronBlockHFC = ProtocolInfoArgsByron (ProtocolParams Consensus.ByronBlock) + data ProtocolInfoArgs m ByronBlockHFC = ProtocolInfoArgsByron ProtocolParamsByron protocolInfo (ProtocolInfoArgsByron params) = ( inject $ protocolInfoByron params , pure . map inject $ blockForgingByron params ) @@ -92,9 +91,9 @@ instance ( IOLike m data ProtocolInfoArgs m (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) StandardShelley) = ProtocolInfoArgsShelley (ShelleyGenesis StandardCrypto) (ProtocolParamsShelleyBased StandardCrypto) - (ProtocolParams (Consensus.ShelleyBlock (Consensus.TPraos StandardCrypto) (ShelleyEra StandardCrypto))) - protocolInfo (ProtocolInfoArgsShelley genesis paramsShelleyBased' paramsShelley') = - bimap inject (fmap $ map inject) $ protocolInfoShelley genesis paramsShelleyBased' paramsShelley' + ProtVer + protocolInfo (ProtocolInfoArgsShelley genesis shelleyBasedProtocolParams' protVer) = + bimap inject (fmap $ map inject) $ protocolInfoShelley genesis shelleyBasedProtocolParams' protVer instance Consensus.LedgerSupportsProtocol (Consensus.ShelleyBlock diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs index a23e1bd99d..f4ca22f109 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs @@ -20,8 +20,8 @@ module Cardano.Node.Protocol.Cardano ( import Cardano.Api.Any import Cardano.Api.Protocol.Types import qualified Cardano.Chain.Update as Byron -import qualified Cardano.Ledger.Api.Transition as L -import Cardano.Ledger.BaseTypes (natVersion) +import qualified Cardano.Ledger.Api.Era as L +import qualified Cardano.Ledger.Api.Transition as SL import qualified Cardano.Node.Protocol.Alonzo as Alonzo import qualified Cardano.Node.Protocol.Byron as Byron import qualified Cardano.Node.Protocol.Conway as Conway @@ -34,7 +34,7 @@ import Ouroboros.Consensus.Cardano import qualified Ouroboros.Consensus.Cardano as Consensus import qualified Ouroboros.Consensus.Cardano.CanHardFork as Consensus import Ouroboros.Consensus.Cardano.Condense () -import Ouroboros.Consensus.Cardano.Node (CardanoProtocolParams) +import Ouroboros.Consensus.Cardano.Node (CardanoProtocolParams (..)) import Ouroboros.Consensus.Config (emptyCheckpointsMap) import Ouroboros.Consensus.HardFork.Combinator.Condense () import Ouroboros.Consensus.Shelley.Crypto (StandardCrypto) @@ -151,7 +151,7 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration { Shelley.readLeaderCredentials files let transitionLedgerConfig = - L.mkLatestTransitionConfig shelleyGenesis alonzoGenesis conwayGenesis + SL.mkLatestTransitionConfig shelleyGenesis alonzoGenesis conwayGenesis --TODO: all these protocol versions below are confusing and unnecessary. -- It could and should all be automated and these config entries eliminated. @@ -186,46 +186,6 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration { shelleyGenesisHash, shelleyBasedLeaderCredentials = shelleyLeaderCredentials } - Consensus.ProtocolParamsShelley { - -- This is /not/ the Shelley protocol version. It is the protocol - -- version that this node will declare that it understands, when it - -- is in the Shelley era. That is, it is the version of protocol - -- /after/ Shelley, i.e. Allegra. - shelleyProtVer = ProtVer (natVersion @3) 0 - } - Consensus.ProtocolParamsAllegra { - -- This is /not/ the Allegra protocol version. It is the protocol - -- version that this node will declare that it understands, when it - -- is in the Allegra era. That is, it is the version of protocol - -- /after/ Allegra, i.e. Mary. - allegraProtVer = ProtVer (natVersion @4) 0 - } - Consensus.ProtocolParamsMary { - -- This is /not/ the Mary protocol version. It is the protocol - -- version that this node will declare that it understands, when it - -- is in the Mary era. That is, it is the version of protocol - -- /after/ Mary, i.e. Alonzo. - maryProtVer = ProtVer (natVersion @5) 0 - } - Consensus.ProtocolParamsAlonzo { - -- This is /not/ the Alonzo protocol version. It is the protocol - -- version that this node will declare that it understands, when it - -- is in the Alonzo era. That is, it is the version of protocol - -- /after/ Alonzo, i.e. Babbage. - alonzoProtVer = ProtVer (natVersion @7) 0 - } - Consensus.ProtocolParamsBabbage { - -- This is /not/ the Babbage protocol version. It is the protocol - -- version that this node will declare that it understands, when it - -- is in the Babbage era. - Consensus.babbageProtVer = ProtVer (natVersion @9) 0 - } - Consensus.ProtocolParamsConway { - -- This is /not/ the Conway protocol version. It is the protocol - -- version that this node will declare that it understands, when it - -- is in the Conway era. - Consensus.conwayProtVer = ProtVer (natVersion @9) 0 - } -- The 'CardanoHardForkTriggers' specify the parameters needed to -- transition between two eras. The comments below also apply for all -- subsequent hard forks. @@ -292,6 +252,7 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration { } transitionLedgerConfig emptyCheckpointsMap + (ProtVer (L.eraProtVerHigh @(L.LatestKnownEra StandardCrypto)) 0) ------------------------------------------------------------------------------ -- Errors diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs index 10d5e506ac..356afa204d 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs @@ -47,8 +47,8 @@ import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Protocol.Praos.Common (PraosCanBeLeader (..)) import Ouroboros.Consensus.Shelley.Node (Nonce (..), - ProtocolParams (..), ProtocolParamsShelleyBased (..), - ShelleyGenesis (..), ShelleyLeaderCredentials (..)) + ProtocolParamsShelleyBased (..), ShelleyGenesis (..), + ShelleyLeaderCredentials (..)) import Prelude (String, id) @@ -85,9 +85,7 @@ mkSomeConsensusProtocolShelley NodeShelleyProtocolConfiguration { shelleyBasedLeaderCredentials = leaderCredentials } - Consensus.ProtocolParamsShelley { - shelleyProtVer = ProtVer (natVersion @2) 0 - } + (ProtVer (natVersion @2) 0) genesisHashToPraosNonce :: GenesisHash -> Nonce genesisHashToPraosNonce (GenesisHash h) = Nonce (Crypto.castHash h) diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Byron.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Byron.hs index 08248df351..9ec57056a4 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Byron.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Byron.hs @@ -25,7 +25,7 @@ import qualified Data.ByteString.Lazy as BL import Ouroboros.Consensus.Byron.Ledger (ByronBlock) import qualified Ouroboros.Consensus.Byron.Ledger as Byron import Ouroboros.Consensus.Byron.Node (PBftSignatureThreshold (..), - ProtocolParams (..), protocolInfoByron) + ProtocolParamsByron (..), protocolInfoByron) import Ouroboros.Consensus.Node.ProtocolInfo import Text.Builder (decimal) diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Cardano.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Cardano.hs index 4000591d49..81abd626d5 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Cardano.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Cardano.hs @@ -31,8 +31,7 @@ import qualified Cardano.Crypto as Crypto import qualified Cardano.Crypto.Hash.Class as CryptoClass import Cardano.Crypto.Raw (Raw) import qualified Cardano.Ledger.Api.Era as L -import qualified Cardano.Ledger.Api.Transition as L -import qualified Cardano.Ledger.BaseTypes as SL (natVersion) +import qualified Cardano.Ledger.Api.Transition as SL import Cardano.Ledger.Binary.Version (getVersion) import Cardano.Ledger.Core (TxOut) import Cardano.Ledger.Crypto @@ -61,8 +60,8 @@ import qualified Ouroboros.Consensus.Byron.Ledger.Ledger as Byron.Ledger import Ouroboros.Consensus.Cardano import Ouroboros.Consensus.Cardano.Block (CardanoEras) import qualified Ouroboros.Consensus.Cardano.Block as Cardano.Block -import Ouroboros.Consensus.Cardano.Node (TriggerHardFork (..), - protocolInfoCardano) +import Ouroboros.Consensus.Cardano.Node (CardanoProtocolParams (..), + TriggerHardFork (..), protocolInfoCardano) import Ouroboros.Consensus.Config (emptyCheckpointsMap) import Ouroboros.Consensus.HardFork.Combinator (HardForkBlock (..), OneEraBlock (..), OneEraHash (..), getHardForkState, @@ -150,7 +149,7 @@ instance HasProtocolInfo (CardanoBlock StandardCrypto) where Aeson.eitherDecodeFileStrict' (conwayGenesisPath cc) let transCfg = - L.mkLatestTransitionConfig genesisShelley genesisAlonzo genesisConway + SL.mkLatestTransitionConfig genesisShelley genesisAlonzo genesisConway initialNonce <- case shelleyGenesisHash cc of Just h -> pure h @@ -362,7 +361,7 @@ type CardanoBlockArgs = Args (CardanoBlock StandardCrypto) mkCardanoProtocolInfo :: Byron.Genesis.Config -> Maybe PBftSignatureThreshold - -> L.TransitionConfig (L.LatestKnownEra StandardCrypto) + -> SL.TransitionConfig (L.LatestKnownEra StandardCrypto) -> Nonce -> CardanoHardForkTriggers -> ProtocolInfo (CardanoBlock StandardCrypto) @@ -380,30 +379,10 @@ mkCardanoProtocolInfo genesisByron signatureThreshold transitionConfig initialNo shelleyBasedInitialNonce = initialNonce , shelleyBasedLeaderCredentials = [] } - ProtocolParamsShelley { - -- Note that this is /not/ the Shelley protocol version, see - -- https://github.com/IntersectMBO/cardano-node/blob/daeae61a005776ee7b7514ce47de3933074234a8/cardano-node/src/Cardano/Node/Protocol/Cardano.hs#L167-L170 - -- and the succeeding comments. - shelleyProtVer = ProtVer (SL.natVersion @3) 0 - } - ProtocolParamsAllegra { - allegraProtVer = ProtVer (SL.natVersion @4) 0 - } - ProtocolParamsMary { - maryProtVer = ProtVer (SL.natVersion @5) 0 - } - ProtocolParamsAlonzo { - alonzoProtVer = ProtVer (SL.natVersion @7) 0 - } - ProtocolParamsBabbage { - babbageProtVer = ProtVer (SL.natVersion @9) 0 - } - ProtocolParamsConway { - conwayProtVer = ProtVer (SL.natVersion @9) 0 - } triggers transitionConfig emptyCheckpointsMap + (ProtVer (L.eraProtVerHigh @(L.LatestKnownEra StandardCrypto)) 0) ) where diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Shelley.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Shelley.hs index c164a1343e..87fc82e00e 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Shelley.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Shelley.hs @@ -47,8 +47,8 @@ import Ouroboros.Consensus.Shelley.Ledger (ShelleyCompatible, import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBlock) import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Shelley import Ouroboros.Consensus.Shelley.Node (Nonce (..), - ProtocolParams (..), ProtocolParamsShelleyBased (..), - ShelleyGenesis, protocolInfoShelley) + ProtocolParamsShelleyBased (..), ShelleyGenesis, + protocolInfoShelley) import Text.Builder (decimal) -- | Usable for each Shelley-based era @@ -154,6 +154,4 @@ mkShelleyProtocolInfo genesis initialNonce = shelleyBasedInitialNonce = initialNonce , shelleyBasedLeaderCredentials = [] } - ProtocolParamsShelley { - shelleyProtVer = SL.ProtVer (CL.natVersion @2) 0 - } + (SL.ProtVer (CL.natVersion @2) 0) diff --git a/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs b/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs index 23f4e83b9d..647d684aab 100644 --- a/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs +++ b/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs @@ -420,10 +420,7 @@ mkProtocolShelley genesis initialNonce protVer coreNode = shelleyBasedInitialNonce = initialNonce , shelleyBasedLeaderCredentials = [mkLeaderCredentials coreNode] } - ProtocolParamsShelley { - shelleyProtVer = protVer - } - + protVer {------------------------------------------------------------------------------- Necessary transactions for updating the 'DecentralizationParam' -------------------------------------------------------------------------------} diff --git a/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/MiniProtocol/LocalTxSubmission/Server.hs b/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/MiniProtocol/LocalTxSubmission/Server.hs index 91ad3db689..2d26cff5ca 100644 --- a/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/MiniProtocol/LocalTxSubmission/Server.hs +++ b/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/MiniProtocol/LocalTxSubmission/Server.hs @@ -37,7 +37,7 @@ import Test.Consensus.Cardano.MiniProtocol.LocalTxSubmission.ByteStrin import Test.Consensus.Cardano.ProtocolInfo (ByronSlotLengthInSeconds (..), Era (..), ShelleySlotLengthInSeconds (..), hardForkInto, - mkSimpleTestProtocolInfo) + mkSimpleTestProtocolInfo, protocolVersionZero) import qualified Test.Consensus.Mempool.Mocked as Mocked import Test.Consensus.Mempool.Mocked (MockedMempool) import Test.Tasty (TestTree, testGroup) @@ -58,6 +58,7 @@ tests = (Consensus.SecurityParam 10) (ByronSlotLengthInSeconds 1) (ShelleySlotLengthInSeconds 1) + protocolVersionZero (hardForkInto era) eraIndex = index_NS diff --git a/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/SupportsSanityCheck.hs b/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/SupportsSanityCheck.hs index 3fe4ef9166..96bcde5f95 100644 --- a/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/SupportsSanityCheck.hs +++ b/ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/SupportsSanityCheck.hs @@ -52,6 +52,7 @@ genSimpleTestProtocolInfo = do (securityParam setup) (byronSlotLength setup) (shelleySlotLength setup) + protocolVersionZero (hardForkSpec setup) data SimpleTestProtocolInfoSetup = SimpleTestProtocolInfoSetup diff --git a/ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/Cardano.hs b/ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/Cardano.hs index 8cf4a5dbb9..509d7be84f 100644 --- a/ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/Cardano.hs +++ b/ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/Cardano.hs @@ -478,31 +478,22 @@ mkProtocolCardanoAndHardForkTxs -- window so that the forks induced by -- the network partition are as deep -- as possible. + (SL.ProtVer conwayMajorVersion 0) -- During the tests, we + -- want to hard fork all + -- the way to Conway, so we + -- need to signal that we + -- support that era. This + -- version will have to be + -- changed if this test has + -- to hard fork to eras + -- beyond Conway. HardForkSpec { - shelleyHardForkSpec = - ( SL.ProtVer shelleyMajorVersion 0 - , TriggerHardForkAtVersion $ SL.getVersion shelleyMajorVersion - ) - , allegraHardForkSpec = - ( SL.ProtVer allegraMajorVersion 0 - , TriggerHardForkAtVersion $ SL.getVersion allegraMajorVersion - ) - , maryHardForkSpec = - ( SL.ProtVer maryMajorVersion 0 - , TriggerHardForkAtVersion $ SL.getVersion maryMajorVersion - ) - , alonzoHardForkSpec = - ( SL.ProtVer alonzoMajorVersion 0 - , TriggerHardForkAtVersion $ SL.getVersion alonzoMajorVersion - ) - , babbageHardForkSpec = - ( SL.ProtVer babbageMajorVersion 0 - , TriggerHardForkAtVersion $ SL.getVersion babbageMajorVersion - ) - , conwayHardForkSpec = - ( SL.ProtVer conwayMajorVersion 0 - , TriggerHardForkAtVersion $ SL.getVersion conwayMajorVersion - ) + shelleyHardForkSpec = TriggerHardForkAtVersion $ SL.getVersion shelleyMajorVersion + , allegraHardForkSpec = TriggerHardForkAtVersion $ SL.getVersion allegraMajorVersion + , maryHardForkSpec = TriggerHardForkAtVersion $ SL.getVersion maryMajorVersion + , alonzoHardForkSpec = TriggerHardForkAtVersion $ SL.getVersion alonzoMajorVersion + , babbageHardForkSpec = TriggerHardForkAtVersion $ SL.getVersion babbageMajorVersion + , conwayHardForkSpec = TriggerHardForkAtVersion $ SL.getVersion conwayMajorVersion } {------------------------------------------------------------------------------- diff --git a/ouroboros-consensus-protocol/changelog.d/20240823_131313_damian.nadales_324_simplify_protver_arguments.md b/ouroboros-consensus-protocol/changelog.d/20240823_131313_damian.nadales_324_simplify_protver_arguments.md new file mode 100644 index 0000000000..0cf98ba71b --- /dev/null +++ b/ouroboros-consensus-protocol/changelog.d/20240823_131313_damian.nadales_324_simplify_protver_arguments.md @@ -0,0 +1,3 @@ + diff --git a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Common.hs b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Common.hs index 73f0be2679..e5cd92c8f2 100644 --- a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Common.hs +++ b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Common.hs @@ -18,7 +18,8 @@ module Ouroboros.Consensus.Protocol.Praos.Common ( ) where import qualified Cardano.Crypto.VRF as VRF -import Cardano.Ledger.BaseTypes (Nonce, Version) +import Cardano.Ledger.BaseTypes (Nonce) +import qualified Cardano.Ledger.BaseTypes as SL import Cardano.Ledger.Crypto (Crypto, VRF) import Cardano.Ledger.Keys (KeyHash, KeyRole (BlockIssuer)) import qualified Cardano.Ledger.Shelley.API as SL @@ -35,10 +36,26 @@ import Ouroboros.Consensus.Protocol.Abstract -- | The maximum major protocol version. -- --- Must be at least the current major protocol version. For Cardano mainnet, the --- Shelley era has major protocol verison __2__. +-- This refers to the largest __ledger__ version that this node supports. +-- +-- Once the ledger protocol version (as reported by the ledger state) +-- exceeds this version we will consider all blocks invalid. This is +-- called the "obsolete node check" (see the 'ObsoleteNode' error +-- constructor). +-- +-- Major ledger protocol versions are used to trigger both intra and +-- inter era hard forks, which can potentially change the set of +-- ledger rules that are applied. +-- +-- Minor ledger protocol versions were intended to signal soft forks +-- but they're currently unused, and they're irrelevant for the +-- consensus logic. +-- +-- For Cardano mainnet, the Shelley era has major protocol version +-- __2__. For more details, see [this +-- table](https://github.com/cardano-foundation/CIPs/blob/master/CIP-0059/feature-table.md) newtype MaxMajorProtVer = MaxMajorProtVer - { getMaxMajorProtVer :: Version + { getMaxMajorProtVer :: SL.Version } deriving (Eq, Show, Generic) deriving newtype NoThunks diff --git a/ouroboros-consensus/changelog.d/20240823_130814_damian.nadales_324_simplify_protver_arguments.md b/ouroboros-consensus/changelog.d/20240823_130814_damian.nadales_324_simplify_protver_arguments.md new file mode 100644 index 0000000000..6facf82535 --- /dev/null +++ b/ouroboros-consensus/changelog.d/20240823_130814_damian.nadales_324_simplify_protver_arguments.md @@ -0,0 +1,4 @@ +### Breaking + +- Remove `PerEraProtocolParams` newtype. +- Remove `ProtocolParams` data family. diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/AcrossEras.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/AcrossEras.hs index 0fa2e469a6..304b521764 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/AcrossEras.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/AcrossEras.hs @@ -25,7 +25,6 @@ module Ouroboros.Consensus.HardFork.Combinator.AcrossEras ( , PerEraCodecConfig (..) , PerEraConsensusConfig (..) , PerEraLedgerConfig (..) - , PerEraProtocolParams (..) , PerEraStorageConfig (..) -- * Values for /some/ eras , SomeErasCanBeLeader (..) @@ -88,7 +87,6 @@ import Ouroboros.Consensus.HardFork.Combinator.Info import Ouroboros.Consensus.HardFork.Combinator.Lifting import Ouroboros.Consensus.HardFork.Combinator.PartialConfig import Ouroboros.Consensus.Ledger.SupportsMempool -import Ouroboros.Consensus.Node.ProtocolInfo import Ouroboros.Consensus.TypeFamilyWrappers import Ouroboros.Consensus.Util (allEqual) import Ouroboros.Consensus.Util.Assert @@ -105,8 +103,6 @@ newtype PerEraConsensusConfig xs = PerEraConsensusConfig { getPerEraConsensusC newtype PerEraLedgerConfig xs = PerEraLedgerConfig { getPerEraLedgerConfig :: NP WrapPartialLedgerConfig xs } newtype PerEraStorageConfig xs = PerEraStorageConfig { getPerEraStorageConfig :: NP StorageConfig xs } -newtype PerEraProtocolParams xs = PerEraProtocolParams { getPerEraProtocolParams :: NP ProtocolParams xs } - {------------------------------------------------------------------------------- Values for /some/ eras diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Node/ProtocolInfo.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Node/ProtocolInfo.hs index 72e44c78d1..1d509b98c0 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Node/ProtocolInfo.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Node/ProtocolInfo.hs @@ -7,11 +7,8 @@ module Ouroboros.Consensus.Node.ProtocolInfo ( , ProtocolClientInfo (..) , ProtocolInfo (..) , enumCoreNodes - -- * Protocol parameters - , ProtocolParams ) where -import Data.Kind (Type) import Data.Word import NoThunks.Class (NoThunks) import Ouroboros.Consensus.Block @@ -45,9 +42,3 @@ data ProtocolInfo b = ProtocolInfo { data ProtocolClientInfo b = ProtocolClientInfo { pClientInfoCodecConfig :: CodecConfig b } - -{------------------------------------------------------------------------------- - Protocol parameters --------------------------------------------------------------------------------} - -data family ProtocolParams blk :: Type