Skip to content

Commit 904e04f

Browse files
authored
Merge pull request #270 from input-output-hk/amesgen/releng-8.5
Integrate Ledger and Consensus for 8.5
2 parents 4990305 + e3f5e27 commit 904e04f

File tree

10 files changed

+191
-229
lines changed

10 files changed

+191
-229
lines changed

cabal.project

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repository cardano-haskell-packages
1414
-- you need to run if you change them
1515
index-state:
1616
, hackage.haskell.org 2023-08-06T23:58:58Z
17-
, cardano-haskell-packages 2023-09-07T15:55:30Z
17+
, cardano-haskell-packages 2023-09-28T08:17:07Z
1818

1919
packages:
2020
cardano-api
@@ -41,4 +41,3 @@ write-ghc-environment-files: always
4141
-- IMPORTANT
4242
-- Do NOT add more source-repository-package stanzas here unless they are strictly
4343
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
44-

cardano-api/cardano-api.cabal

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ library internal
175175
, mtl
176176
, network
177177
, optparse-applicative-fork
178-
, ouroboros-consensus >= 0.9
179-
, ouroboros-consensus-cardano >= 0.8
180-
, ouroboros-consensus-diffusion >= 0.7
181-
, ouroboros-consensus-protocol >= 0.5.0.4
178+
, ouroboros-consensus ^>= 0.12
179+
, ouroboros-consensus-cardano ^>= 0.10
180+
, ouroboros-consensus-diffusion ^>= 0.8.0.1
181+
, ouroboros-consensus-protocol ^>= 0.5.0.7
182182
, ouroboros-network
183183
, ouroboros-network-api
184184
, ouroboros-network-framework
185185
, ouroboros-network-protocols
186186
, parsec
187-
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.9
187+
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.11
188188
, prettyprinter
189-
, prettyprinter-configurable ^>= 1.9
189+
, prettyprinter-configurable ^>= 1.11
190190
, random
191191
, scientific
192192
, serialise
@@ -350,8 +350,8 @@ test-suite cardano-api-golden
350350
, hedgehog >= 1.1
351351
, hedgehog-extras ^>= 0.4.7.0
352352
, microlens
353-
, plutus-core ^>= 1.9
354-
, plutus-ledger-api ^>= 1.9
353+
, plutus-core ^>= 1.11
354+
, plutus-ledger-api ^>= 1.11
355355
, tasty
356356
, tasty-hedgehog
357357
, time

cardano-api/internal/Cardano/Api/Eon/ConwayEraOnwards.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import qualified Cardano.Ledger.Api as L
3434
import qualified Cardano.Ledger.BaseTypes as L
3535
import qualified Cardano.Ledger.Conway.Core as L
3636
import qualified Cardano.Ledger.Conway.Governance as L
37+
import qualified Cardano.Ledger.Conway.PParams as L
3738
import qualified Cardano.Ledger.Conway.TxCert as L
3839
import qualified Cardano.Ledger.SafeHash as L
3940
import qualified Cardano.Ledger.UTxO as L

cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,15 @@ toGovernanceAction _ (ProposeNewConstitution prevGovAction anchor) =
8181
, Gov.constitutionScript = SNothing -- TODO: Conway era
8282
}
8383
toGovernanceAction _ (ProposeNewCommittee prevGovId oldCommitteeMembers newCommitteeMembers quor) =
84-
Gov.NewCommittee
85-
prevGovId
86-
(Set.fromList $ map toCommitteeMember oldCommitteeMembers)
87-
Gov.Committee
88-
{ Gov.committeeMembers = Map.mapKeys toCommitteeMember newCommitteeMembers
89-
, Gov.committeeQuorum =
90-
fromMaybe
91-
(error $ mconcat ["toGovernanceAction: the given quorum "
84+
Gov.UpdateCommittee
85+
prevGovId -- previous governance action id
86+
(Set.fromList $ map toCommitteeMember oldCommitteeMembers) -- members to remove
87+
(Map.mapKeys toCommitteeMember newCommitteeMembers) -- members to add
88+
(fromMaybe (error $ mconcat ["toGovernanceAction: the given quorum "
9289
, show quor
9390
, " was outside of the unit interval!"
9491
])
95-
$ boundRational @UnitInterval quor
96-
}
92+
$ boundRational @UnitInterval quor)
9793
toGovernanceAction _ InfoAct = Gov.InfoAction
9894
toGovernanceAction _ (TreasuryWithdrawal withdrawals) =
9995
let m = Map.fromList [(L.mkRwdAcnt nw (toShelleyStakeCredential sc), toShelleyLovelace l) | (nw,sc,l) <- withdrawals]
@@ -124,16 +120,12 @@ fromGovernanceAction sbe = \case
124120
| (rwdAcnt, coin) <- Map.toList withdrawlMap
125121
]
126122
in TreasuryWithdrawal res
127-
Gov.NewCommittee prevGovId oldCommitteeMembers newCommittee ->
128-
let Gov.Committee
129-
{ Gov.committeeMembers = newCommitteeMembers
130-
, Gov.committeeQuorum = quor
131-
} = newCommittee
132-
in ProposeNewCommittee
133-
prevGovId
134-
(map fromCommitteeMember $ Set.toList oldCommitteeMembers)
135-
(Map.mapKeys fromCommitteeMember newCommitteeMembers)
136-
(unboundRational quor)
123+
Gov.UpdateCommittee prevGovId oldCommitteeMembers newCommitteeMembers quor ->
124+
ProposeNewCommittee
125+
prevGovId
126+
(map fromCommitteeMember $ Set.toList oldCommitteeMembers)
127+
(Map.mapKeys fromCommitteeMember newCommitteeMembers)
128+
(unboundRational quor)
137129
Gov.InfoAction ->
138130
InfoAct
139131

cardano-api/internal/Cardano/Api/LedgerState.hs

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ import qualified Cardano.Crypto.ProtocolMagic
116116
import qualified Cardano.Crypto.VRF as Crypto
117117
import qualified Cardano.Crypto.VRF.Class as VRF
118118
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..))
119+
import qualified Cardano.Ledger.Api.Era as Ledger
120+
import qualified Cardano.Ledger.Api.Transition as Ledger
119121
import Cardano.Ledger.BaseTypes (Globals (..), Nonce, ProtVer (..), natVersion, (⭒))
120122
import qualified Cardano.Ledger.BaseTypes as Ledger
121123
import qualified Cardano.Ledger.BHeaderView as Ledger
@@ -126,7 +128,6 @@ import qualified Cardano.Ledger.PoolDistr as SL
126128
import qualified Cardano.Ledger.Shelley.API as ShelleyAPI
127129
import qualified Cardano.Ledger.Shelley.Core as Core
128130
import qualified Cardano.Ledger.Shelley.Genesis as Ledger
129-
import Cardano.Ledger.Shelley.Translation (emptyFromByronTranslationContext)
130131
import qualified Cardano.Protocol.TPraos.API as TPraos
131132
import Cardano.Protocol.TPraos.BHeader (checkLeaderNatValue)
132133
import qualified Cardano.Protocol.TPraos.BHeader as TPraos
@@ -156,7 +157,6 @@ import Ouroboros.Consensus.Protocol.Abstract (ChainDepState, Consensus
156157
import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus
157158
import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus
158159
import Ouroboros.Consensus.Protocol.Praos.VRF (mkInputVRF, vrfLeaderValue)
159-
import Ouroboros.Consensus.Protocol.TPraos (TPraos)
160160
import qualified Ouroboros.Consensus.Protocol.TPraos as TPraos
161161
import qualified Ouroboros.Consensus.Shelley.Eras as Shelley
162162
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Shelley
@@ -760,18 +760,18 @@ genesisConfigToEnv
760760
-- enp
761761
genCfg =
762762
case genCfg of
763-
GenesisCardano _ bCfg sCfg _ _
764-
| Cardano.Crypto.ProtocolMagic.unProtocolMagicId (Cardano.Chain.Genesis.configProtocolMagicId bCfg) /= Ledger.sgNetworkMagic (scConfig sCfg) ->
763+
GenesisCardano _ bCfg _ transCfg
764+
| Cardano.Crypto.ProtocolMagic.unProtocolMagicId (Cardano.Chain.Genesis.configProtocolMagicId bCfg) /= Ledger.sgNetworkMagic shelleyGenesis ->
765765
Left . NECardanoConfig $
766766
mconcat
767767
[ "ProtocolMagicId ", textShow (Cardano.Crypto.ProtocolMagic.unProtocolMagicId $ Cardano.Chain.Genesis.configProtocolMagicId bCfg)
768-
, " /= ", textShow (Ledger.sgNetworkMagic $ scConfig sCfg)
768+
, " /= ", textShow (Ledger.sgNetworkMagic shelleyGenesis)
769769
]
770-
| Cardano.Chain.Genesis.gdStartTime (Cardano.Chain.Genesis.configGenesisData bCfg) /= Ledger.sgSystemStart (scConfig sCfg) ->
770+
| Cardano.Chain.Genesis.gdStartTime (Cardano.Chain.Genesis.configGenesisData bCfg) /= Ledger.sgSystemStart shelleyGenesis ->
771771
Left . NECardanoConfig $
772772
mconcat
773773
[ "SystemStart ", textShow (Cardano.Chain.Genesis.gdStartTime $ Cardano.Chain.Genesis.configGenesisData bCfg)
774-
, " /= ", textShow (Ledger.sgSystemStart $ scConfig sCfg)
774+
, " /= ", textShow (Ledger.sgSystemStart shelleyGenesis)
775775
]
776776
| otherwise ->
777777
let
@@ -781,6 +781,8 @@ genesisConfigToEnv
781781
{ envLedgerConfig = Consensus.topLevelConfigLedger topLevelConfig
782782
, envProtocolConfig = Consensus.topLevelConfigProtocol topLevelConfig
783783
}
784+
where
785+
shelleyGenesis = transCfg ^. Ledger.tcShelleyGenesisL
784786

785787
readNodeConfig :: NodeConfigFile 'In -> ExceptT Text IO NodeConfig
786788
readNodeConfig (File ncf) = do
@@ -804,23 +806,7 @@ data NodeConfig = NodeConfig
804806
, ncConwayGenesisHash :: !GenesisHashConway
805807
, ncRequiresNetworkMagic :: !Cardano.Crypto.RequiresNetworkMagic
806808
, ncByronProtocolVersion :: !Cardano.Chain.Update.ProtocolVersion
807-
808-
-- Per-era parameters for the hardfok transitions:
809-
, ncByronToShelley :: !(Consensus.ProtocolTransitionParams
810-
Byron.ByronBlock
811-
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardShelley)
812-
)
813-
, ncShelleyToAllegra :: !(Consensus.ProtocolTransitionParams
814-
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardShelley)
815-
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardAllegra)
816-
)
817-
, ncAllegraToMary :: !(Consensus.ProtocolTransitionParams
818-
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardAllegra)
819-
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardMary)
820-
)
821-
, ncMaryToAlonzo :: !Consensus.TriggerHardFork
822-
, ncAlonzoToBabbage :: !Consensus.TriggerHardFork
823-
, ncBabbageToConway :: !Consensus.TriggerHardFork
809+
, ncHardForkTriggers :: !Consensus.CardanoHardForkTriggers
824810
}
825811

826812
instance FromJSON NodeConfig where
@@ -841,15 +827,7 @@ instance FromJSON NodeConfig where
841827
<*> fmap GenesisHashConway (o .: "ConwayGenesisHash")
842828
<*> o .: "RequiresNetworkMagic"
843829
<*> parseByronProtocolVersion o
844-
<*> (Consensus.ProtocolTransitionParamsByronToShelley emptyFromByronTranslationContext
845-
<$> parseShelleyHardForkEpoch o)
846-
<*> (Consensus.ProtocolTransitionParamsIntraShelley ()
847-
<$> parseAllegraHardForkEpoch o)
848-
<*> (Consensus.ProtocolTransitionParamsIntraShelley ()
849-
<$> parseMaryHardForkEpoch o)
850-
<*> parseAlonzoHardForkEpoch o
851-
<*> parseBabbageHardForkEpoch o
852-
<*> parseConwayHardForkEpoch o
830+
<*> parseHardForkTriggers o
853831

854832
parseByronProtocolVersion :: Object -> Parser Cardano.Chain.Update.ProtocolVersion
855833
parseByronProtocolVersion o =
@@ -858,6 +836,16 @@ instance FromJSON NodeConfig where
858836
<*> o .: "LastKnownBlockVersion-Minor"
859837
<*> o .: "LastKnownBlockVersion-Alt"
860838

839+
parseHardForkTriggers :: Object -> Parser Consensus.CardanoHardForkTriggers
840+
parseHardForkTriggers o =
841+
Consensus.CardanoHardForkTriggers'
842+
<$> parseShelleyHardForkEpoch o
843+
<*> parseAllegraHardForkEpoch o
844+
<*> parseMaryHardForkEpoch o
845+
<*> parseAlonzoHardForkEpoch o
846+
<*> parseBabbageHardForkEpoch o
847+
<*> parseConwayHardForkEpoch o
848+
861849
parseShelleyHardForkEpoch :: Object -> Parser Consensus.TriggerHardFork
862850
parseShelleyHardForkEpoch o =
863851
asum
@@ -982,9 +970,8 @@ data GenesisConfig
982970
= GenesisCardano
983971
!NodeConfig
984972
!Cardano.Chain.Genesis.Config
985-
!ShelleyConfig
986-
!AlonzoGenesis
987-
!(ConwayGenesis Shelley.StandardCrypto)
973+
!GenesisHashShelley
974+
!(Ledger.TransitionConfig (Ledger.LatestKnownEra Shelley.StandardCrypto))
988975

989976
newtype LedgerStateDir = LedgerStateDir
990977
{ unLedgerStateDir :: FilePath
@@ -1003,7 +990,7 @@ mkProtocolInfoCardano ::
1003990
(Consensus.CardanoEras Consensus.StandardCrypto))
1004991
, IO [BlockForging IO (HFC.HardForkBlock
1005992
(Consensus.CardanoEras Consensus.StandardCrypto))])
1006-
mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis alonzoGenesis conwayGenesis)
993+
mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesisHash transCfg)
1007994
= Consensus.protocolInfoCardano Consensus.CardanoProtocolParams
1008995
{ Consensus.paramsByron =
1009996
Consensus.ProtocolParamsByron
@@ -1016,8 +1003,7 @@ mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis alonzoGene
10161003
}
10171004
, Consensus.paramsShelleyBased =
10181005
Consensus.ProtocolParamsShelleyBased
1019-
{ Consensus.shelleyBasedGenesis = scConfig shelleyGenesis
1020-
, Consensus.shelleyBasedInitialNonce = shelleyPraosNonce shelleyGenesis
1006+
{ Consensus.shelleyBasedInitialNonce = shelleyPraosNonce shelleyGenesisHash
10211007
, Consensus.shelleyBasedLeaderCredentials = []
10221008
}
10231009
, Consensus.paramsShelley =
@@ -1050,43 +1036,25 @@ mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis alonzoGene
10501036
{ Consensus.conwayProtVer = ProtVer (natVersion @10) 0
10511037
, Consensus.conwayMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
10521038
}
1053-
, Consensus.transitionParamsByronToShelley =
1054-
ncByronToShelley dnc
1055-
, Consensus.transitionParamsShelleyToAllegra =
1056-
ncShelleyToAllegra dnc
1057-
, Consensus.transitionParamsAllegraToMary =
1058-
ncAllegraToMary dnc
1059-
, Consensus.transitionParamsMaryToAlonzo =
1060-
Consensus.ProtocolTransitionParamsIntraShelley
1061-
{ Consensus.transitionIntraShelleyTranslationContext = alonzoGenesis
1062-
, Consensus.transitionIntraShelleyTrigger = ncMaryToAlonzo dnc
1063-
}
1064-
, Consensus.transitionParamsAlonzoToBabbage =
1065-
Consensus.ProtocolTransitionParamsIntraShelley
1066-
{ Consensus.transitionIntraShelleyTranslationContext = ()
1067-
, Consensus.transitionIntraShelleyTrigger = ncAlonzoToBabbage dnc
1068-
}
1069-
, Consensus.transitionParamsBabbageToConway =
1070-
Consensus.ProtocolTransitionParamsIntraShelley
1071-
{ Consensus.transitionIntraShelleyTranslationContext = conwayGenesis
1072-
, Consensus.transitionIntraShelleyTrigger = ncBabbageToConway dnc
1073-
}
1039+
, Consensus.hardForkTriggers = ncHardForkTriggers dnc
1040+
, Consensus.ledgerTransitionConfig = transCfg
10741041
}
10751042

1076-
-- | Compute the Nonce from the ShelleyGenesis file.
1077-
shelleyPraosNonce :: ShelleyConfig -> Ledger.Nonce
1078-
shelleyPraosNonce sCfg =
1079-
Ledger.Nonce (Cardano.Crypto.Hash.Class.castHash . unGenesisHashShelley $ scGenesisHash sCfg)
1043+
-- | Compute the Nonce from the hash of the Genesis file.
1044+
shelleyPraosNonce :: GenesisHashShelley -> Ledger.Nonce
1045+
shelleyPraosNonce genesisHash =
1046+
Ledger.Nonce (Cardano.Crypto.Hash.Class.castHash $ unGenesisHashShelley genesisHash)
10801047

10811048
readCardanoGenesisConfig
10821049
:: NodeConfig
10831050
-> ExceptT GenesisConfigError IO GenesisConfig
1084-
readCardanoGenesisConfig enc =
1085-
GenesisCardano enc
1086-
<$> readByronGenesisConfig enc
1087-
<*> readShelleyGenesisConfig enc
1088-
<*> readAlonzoGenesisConfig enc
1089-
<*> readConwayGenesisConfig enc
1051+
readCardanoGenesisConfig enc = do
1052+
byronGenesis <- readByronGenesisConfig enc
1053+
ShelleyConfig shelleyGenesis shelleyGenesisHash <- readShelleyGenesisConfig enc
1054+
alonzoGenesis <- readAlonzoGenesisConfig enc
1055+
conwayGenesis <- readConwayGenesisConfig enc
1056+
let transCfg = Ledger.mkLatestTransitionConfig shelleyGenesis alonzoGenesis conwayGenesis
1057+
pure $ GenesisCardano enc byronGenesis shelleyGenesisHash transCfg
10901058

10911059
data GenesisConfigError
10921060
= NEError !Text

0 commit comments

Comments
 (0)