Skip to content

Commit 43c2190

Browse files
committed
Integrate Consensus changes
mostly propagating the new Ledger `TransitionConfig` concept, see IntersectMBO/cardano-ledger#3737
1 parent 2e649c6 commit 43c2190

File tree

2 files changed

+42
-73
lines changed

2 files changed

+42
-73
lines changed

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ instance ( IOLike m
8989
)
9090
=> Protocol m (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) StandardShelley) where
9191
data ProtocolInfoArgs (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) StandardShelley) = ProtocolInfoArgsShelley
92-
(ProtocolParamsShelleyBased StandardShelley)
92+
(ShelleyGenesis StandardCrypto)
93+
(ProtocolParamsShelleyBased StandardCrypto)
9394
(ProtocolParams (Consensus.ShelleyBlock (Consensus.TPraos StandardCrypto) StandardShelley))
94-
protocolInfo (ProtocolInfoArgsShelley paramsShelleyBased_ paramsShelley_) =
95-
bimap inject (fmap $ map inject) $ protocolInfoShelley paramsShelleyBased_ paramsShelley_
95+
protocolInfo (ProtocolInfoArgsShelley genesis paramsShelleyBased_ paramsShelley_) =
96+
bimap inject (fmap $ map inject) $ protocolInfoShelley genesis paramsShelleyBased_ paramsShelley_
9697

9798
instance Consensus.LedgerSupportsProtocol
9899
(Consensus.ShelleyBlock

0 commit comments

Comments
 (0)