Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate protocol parameters across eras #282

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Patch

- A bullet item for the Patch category.

-->

### Non-Breaking
nfrisby marked this conversation as resolved.
Show resolved Hide resolved

- Add a `ProtocolTransitionParams` data family, and provide instances for
transitions from Byron to Shelley and Shelley-based eras to Shelley-based
eras.
- Add a data instance of `ProtocolParams` for the Cardano block.
- Provide a `CardanoProtocolParams` type synonym and associated pattern synonym
(with record syntax).
- Export all `ProtocolParams` and `ProtocolTransitionParams` instances from
`Ouroboros.Consensus.Cardano` and `Ouroboros.Consensus.Cardano.Node`.

### Breaking

- Refactor `ProtocolParamsByron` to a data instance of `ProtocolParams`.
- Refactor protocol parameters for Shelley eras (e.g, `ProtocolParamsAlonzo` and `ProtocolParamsBabbage`) to data instances of `ProtocolParams`.
- Export all Shelley `ProtocolParams` data instances from `Ouroboros.Consensus.Shelley.Node`.
- Remove the `ProtocolTransitionParamsShelleyBased` datatype in favour of
`ProtocolTransitionParams`.
- Make `protocolInfoCardano` require a `CardanoProtocolParams` type as its only
argument, instead of a long list of arguments.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mkProtocolByron params coreNodeId genesisConfig genesisSecrets =
blockForging :: [BlockForging m ByronBlock]
blockForging = blockForgingByron protocolParams

protocolParams :: ProtocolParamsByron
protocolParams :: ProtocolParams ByronBlock
protocolParams = ProtocolParamsByron {
byronGenesis = genesisConfig
, byronPbftSignatureThreshold = Just $ pbftSignatureThreshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

module Ouroboros.Consensus.Byron.Node (
PBftSignatureThreshold (..)
, ProtocolParamsByron (..)
, blockForgingByron
, byronBlockForging
, defaultPBftSignatureThreshold
, mkByronConfig
, protocolClientInfoByron
, protocolInfoByron
-- * Secrets
, ByronLeaderCredentials (..)
, ByronLeaderCredentialsError
, mkByronLeaderCredentials
, mkPBftCanBeLeader
-- * ProtocolInfo
, ProtocolParams (..)
, defaultPBftSignatureThreshold
, mkByronConfig
, protocolClientInfoByron
, protocolInfoByron
jorisdral marked this conversation as resolved.
Show resolved Hide resolved
) where

import qualified Cardano.Chain.Delegation as Delegation
Expand Down Expand Up @@ -151,7 +152,7 @@ mkPBftCanBeLeader (ByronLeaderCredentials sk cert nid _) = PBftCanBeLeader {
}

blockForgingByron :: Monad m
=> ProtocolParamsByron
=> ProtocolParams ByronBlock
-> [BlockForging m ByronBlock]
blockForgingByron ProtocolParamsByron { byronLeaderCredentials = mLeaderCreds
, byronMaxTxCapacityOverrides = maxTxCapacityOverrides
Expand All @@ -169,7 +170,7 @@ defaultPBftSignatureThreshold :: PBftSignatureThreshold
defaultPBftSignatureThreshold = PBftSignatureThreshold 0.22

-- | Parameters needed to run Byron
data ProtocolParamsByron = ProtocolParamsByron {
data instance ProtocolParams ByronBlock = ProtocolParamsByron {
byronGenesis :: Genesis.Config
, byronPbftSignatureThreshold :: Maybe PBftSignatureThreshold
, byronProtocolVersion :: Update.ProtocolVersion
Expand All @@ -178,7 +179,7 @@ data ProtocolParamsByron = ProtocolParamsByron {
, byronMaxTxCapacityOverrides :: Mempool.TxOverrides ByronBlock
}

protocolInfoByron :: ProtocolParamsByron
protocolInfoByron :: ProtocolParams ByronBlock
-> ProtocolInfo ByronBlock
protocolInfoByron ProtocolParamsByron {
byronGenesis = genesisConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,24 @@ import Data.Word (Word64)
import Ouroboros.Consensus.Block.Forging (BlockForging)
import Ouroboros.Consensus.BlockchainTime (SlotLength)
import Ouroboros.Consensus.Byron.Node (ByronLeaderCredentials,
ProtocolParamsByron (..), byronGenesis,
ProtocolParams (..), byronGenesis,
byronMaxTxCapacityOverrides, byronPbftSignatureThreshold,
byronSoftwareVersion)
import Ouroboros.Consensus.Cardano.Block (CardanoBlock)
import Ouroboros.Consensus.Cardano.Node (CardanoHardForkConstraints,
ProtocolTransitionParamsShelleyBased (..),
ProtocolParams (..), ProtocolTransitionParams (..),
TriggerHardFork (TriggerHardForkAtEpoch, TriggerHardForkNever),
protocolInfoCardano, transitionTranslationContext,
transitionTrigger)
protocolInfoCardano)
import Ouroboros.Consensus.Config.SecurityParam (SecurityParam (..))
import qualified Ouroboros.Consensus.Mempool as Mempool
import Ouroboros.Consensus.Node.ProtocolInfo (NumCoreNodes (..),
ProtocolInfo)
import Ouroboros.Consensus.NodeId (CoreNodeId (..))
import Ouroboros.Consensus.Protocol.PBFT (PBftParams,
PBftSignatureThreshold (..))
import Ouroboros.Consensus.Shelley.Node (ProtocolParamsAllegra (..),
ProtocolParamsAlonzo (..), ProtocolParamsMary (..),
ProtocolParamsShelley (..),
ProtocolParamsShelleyBased (..), ShelleyGenesis,
ShelleyLeaderCredentials, allegraMaxTxCapacityOverrides,
allegraProtVer, alonzoMaxTxCapacityOverrides,
alonzoProtVer, maryMaxTxCapacityOverrides, maryProtVer,
sgGenDelegs, shelleyBasedGenesis, shelleyBasedInitialNonce,
shelleyBasedLeaderCredentials,
shelleyMaxTxCapacityOverrides, shelleyProtVer)
import Ouroboros.Consensus.Shelley.Node.Praos
(ProtocolParamsBabbage (..), ProtocolParamsConway (..))
import Ouroboros.Consensus.Shelley.Node
(ProtocolParamsShelleyBased (..), ShelleyGenesis,
ShelleyLeaderCredentials, sgGenDelegs)
import Ouroboros.Consensus.Util.IOLike (IOLike)
import qualified Test.ThreadNet.Infra.Alonzo as Alonzo
import qualified Test.ThreadNet.Infra.Byron as Byron
Expand Down Expand Up @@ -280,70 +270,72 @@ mkTestProtocolInfo
hardForkSpec
=
protocolInfoCardano
ProtocolParamsByron {
byronGenesis = genesisByron
, byronPbftSignatureThreshold = aByronPbftSignatureThreshold
, byronProtocolVersion = aByronProtocolVersion
, byronSoftwareVersion = softVerByron
, byronLeaderCredentials = Just leaderCredentialsByron
, byronMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsShelleyBased {
shelleyBasedGenesis = shelleyGenesis
, shelleyBasedInitialNonce = initialNonce
, shelleyBasedLeaderCredentials = [leaderCredentialsShelley]
}
ProtocolParamsShelley {
shelleyProtVer = hfSpecProtVer Shelley hardForkSpec
, shelleyMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsAllegra {
allegraProtVer = hfSpecProtVer Allegra hardForkSpec
, allegraMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsMary {
maryProtVer = hfSpecProtVer Mary hardForkSpec
, maryMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsAlonzo {
alonzoProtVer = hfSpecProtVer Alonzo hardForkSpec
, alonzoMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsBabbage {
babbageProtVer = hfSpecProtVer Babbage hardForkSpec
, babbageMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsConway {
conwayProtVer = hfSpecProtVer Conway hardForkSpec
, conwayMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = SL.toFromByronTranslationContext shelleyGenesis
, transitionTrigger = hfSpecTransitionTrigger Shelley hardForkSpec
}
ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = ()
, transitionTrigger = hfSpecTransitionTrigger Allegra hardForkSpec
}
ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = ()
, transitionTrigger = hfSpecTransitionTrigger Mary hardForkSpec
}
ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = Alonzo.degenerateAlonzoGenesis
, transitionTrigger = hfSpecTransitionTrigger Alonzo hardForkSpec
}
ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = ()
, transitionTrigger = hfSpecTransitionTrigger Babbage hardForkSpec
}
ProtocolTransitionParamsShelleyBased {
transitionTranslationContext =
-- Note that this is effectively a no-op, which is fine for
-- testing, at least for now.
SL.ConwayGenesis $ SL.GenDelegs $ sgGenDelegs shelleyGenesis
, transitionTrigger = hfSpecTransitionTrigger Conway hardForkSpec
(CardanoProtocolParams
ProtocolParamsByron {
byronGenesis = genesisByron
, byronPbftSignatureThreshold = aByronPbftSignatureThreshold
, byronProtocolVersion = aByronProtocolVersion
, byronSoftwareVersion = softVerByron
, byronLeaderCredentials = Just leaderCredentialsByron
, byronMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsShelleyBased {
shelleyBasedGenesis = shelleyGenesis
, shelleyBasedInitialNonce = initialNonce
, shelleyBasedLeaderCredentials = [leaderCredentialsShelley]
}
ProtocolParamsShelley {
shelleyProtVer = hfSpecProtVer Shelley hardForkSpec
, shelleyMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsAllegra {
allegraProtVer = hfSpecProtVer Allegra hardForkSpec
, allegraMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsMary {
maryProtVer = hfSpecProtVer Mary hardForkSpec
, maryMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsAlonzo {
alonzoProtVer = hfSpecProtVer Alonzo hardForkSpec
, alonzoMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsBabbage {
babbageProtVer = hfSpecProtVer Babbage hardForkSpec
, babbageMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolParamsConway {
conwayProtVer = hfSpecProtVer Conway hardForkSpec
, conwayMaxTxCapacityOverrides = Mempool.mkOverrides Mempool.noOverridesMeasure
}
ProtocolTransitionParamsByronToShelley {
transitionByronToShelleyTranslationContext = SL.toFromByronTranslationContext shelleyGenesis
, transitionByronToShelleyTrigger = hfSpecTransitionTrigger Shelley hardForkSpec
}
ProtocolTransitionParamsIntraShelley {
transitionIntraShelleyTranslationContext = ()
, transitionIntraShelleyTrigger = hfSpecTransitionTrigger Allegra hardForkSpec
}
ProtocolTransitionParamsIntraShelley {
transitionIntraShelleyTranslationContext = ()
, transitionIntraShelleyTrigger = hfSpecTransitionTrigger Mary hardForkSpec
}
ProtocolTransitionParamsIntraShelley {
transitionIntraShelleyTranslationContext = Alonzo.degenerateAlonzoGenesis
, transitionIntraShelleyTrigger = hfSpecTransitionTrigger Alonzo hardForkSpec
}
ProtocolTransitionParamsIntraShelley {
transitionIntraShelleyTranslationContext = ()
, transitionIntraShelleyTrigger = hfSpecTransitionTrigger Babbage hardForkSpec
}
ProtocolTransitionParamsIntraShelley {
transitionIntraShelleyTranslationContext =
-- Note that this is effectively a no-op, which is fine for
-- testing, at least for now.
SL.ConwayGenesis $ SL.GenDelegs $ sgGenDelegs shelleyGenesis
, transitionIntraShelleyTrigger = hfSpecTransitionTrigger Conway hardForkSpec
}
)

where
leaderCredentialsByron :: ByronLeaderCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import Ouroboros.Consensus.Cardano.CanHardFork
(ShelleyPartialLedgerConfig (..), forecastAcrossShelley,
translateChainDepStateAcrossShelley)
import Ouroboros.Consensus.Cardano.Node
(ProtocolTransitionParamsShelleyBased (..),
TriggerHardFork (..))
(ProtocolTransitionParams (..), TriggerHardFork (..))
import Ouroboros.Consensus.HardFork.Combinator
import Ouroboros.Consensus.HardFork.Combinator.Embed.Binary
import Ouroboros.Consensus.HardFork.Combinator.Serialisation
Expand Down Expand Up @@ -228,7 +227,7 @@ protocolInfoShelleyBasedHardFork ::
-> SL.ProtVer
-> SL.ProtVer
-> SL.TranslationContext era1
-> ProtocolTransitionParamsShelleyBased era2
-> ProtocolTransitionParams (ShelleyBlock proto1 era1) (ShelleyBlock proto2 era2)
-> ( ProtocolInfo (ShelleyBasedHardForkBlock proto1 era1 proto2 era2)
, m [BlockForging m (ShelleyBasedHardForkBlock proto1 era1 proto2 era2)]
)
Expand Down Expand Up @@ -274,17 +273,17 @@ protocolInfoShelleyBasedHardFork protocolParamsShelleyBased
eraParams1 :: History.EraParams
eraParams1 = shelleyEraParams genesis

ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = transCtxt2
, transitionTrigger
ProtocolTransitionParamsIntraShelley {
transitionIntraShelleyTranslationContext = transCtxt2
, transitionIntraShelleyTrigger
} = protocolTransitionParams

toPartialLedgerConfig1 ::
LedgerConfig (ShelleyBlock proto1 era1)
-> PartialLedgerConfig (ShelleyBlock proto1 era1)
toPartialLedgerConfig1 cfg = ShelleyPartialLedgerConfig {
shelleyLedgerConfig = cfg
, shelleyTriggerHardFork = transitionTrigger
, shelleyTriggerHardFork = transitionIntraShelleyTrigger
}

-- Era 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ module Ouroboros.Consensus.Cardano (
, ProtocolCardano
, ProtocolShelley
-- * Abstract over the various protocols
, ProtocolParamsAllegra (..)
, ProtocolParamsAlonzo (..)
, ProtocolParamsByron (..)
, ProtocolParamsMary (..)
, ProtocolParamsShelley (..)
, ProtocolTransitionParamsShelleyBased (..)
, ProtocolParams (..)
jorisdral marked this conversation as resolved.
Show resolved Hide resolved
, ProtocolTransitionParams (..)
, module X
) where

Expand Down
Loading