Skip to content

Commit ab9c022

Browse files
Lucsanszkylehins
andauthored
Apply suggestions from code review
Co-authored-by: Alexey Kuleshevich <alexey.kuleshevich@iohk.io>
1 parent 1cf7578 commit ab9c022

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ instance FromJSON AlonzoGenesis where
229229
agCollateralPercentage <- o .: "collateralPercentage"
230230
agMaxCollateralInputs <- o .: "maxCollateralInputs"
231231
agExtraConfig <- o .:? "extraConfig"
232-
let agCostModels = costModelsValid cms ! PlutusV1
232+
agPlutusV1CostModel <-
233+
case Map.toList (costModelsValid cms) of
234+
[] -> fail "Expected \"PlutusV1\" cost model to be supplied"
235+
[(PlutusV1, pv1CostModel)] -> pure pv1CostModel
236+
_ -> fail $ "Only PlutusV1 CostModel is allowed in the AlonzoGenesis, but " <> List.intercalate ", " (Map.keys cms) <> " were supplied. Use \"extraConfig\" if you need to inject other cost models for testing."
233237
return AlonzoGenesis {..}
234238

235239
instance ToKeyValuePairs AlonzoGenesis where
@@ -243,4 +247,4 @@ instance ToKeyValuePairs AlonzoGenesis where
243247
, "collateralPercentage" .= agCollateralPercentage ag
244248
, "maxCollateralInputs" .= agMaxCollateralInputs ag
245249
]
246-
++ ["extraConfig" .= agExtraConfig ag | isJust (agExtraConfig ag)]
250+
++ ["extraConfig" .= extraConfig | Just extraConfig <- [agExtraConfig ag]]

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Transition.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ instance EraTransition AlonzoEra where
3030

3131
mkTransitionConfig = AlonzoTransitionConfig
3232

33-
injectIntoTestState cfg = case agExtraConfig $ cfg ^. tcTranslationContextL of
34-
Nothing -> shelleyRegisterInitialFundsThenStaking cfg
35-
Just aec -> shelleyRegisterInitialFundsThenStaking cfg . overrideCostModels (aecCostModels aec)
33+
injectIntoTestState cfg =
34+
shelleyRegisterInitialFundsThenStaking cfg . alonzoInjectCostModels cfg
35+
36+
alonzoInjectCostModels cfg =
37+
case agExtraConfig $ cfg ^. tcTranslationContextL of
38+
Nothing -> id
39+
Just aec -> overrideCostModels (aecCostModels aec)
3640

3741
tcPreviousEraConfigL =
3842
lens atcMaryTransitionConfig (\atc pc -> atc {atcMaryTransitionConfig = pc})
@@ -48,4 +52,6 @@ overrideCostModels ::
4852
NewEpochState era ->
4953
NewEpochState era
5054
overrideCostModels Nothing nes = nes
51-
overrideCostModels (Just cms) nes = nes & nesEsL . curPParamsEpochStateL . ppCostModelsL %~ (<> cms)
55+
overrideCostModels = \case
56+
Nothing -> id
57+
Just cms -> nesEsL . curPParamsEpochStateL . ppCostModelsL %~ updateCostModels cms

0 commit comments

Comments
 (0)