Skip to content

Commit 41ce2a0

Browse files
committed
Add ability to properly restrict languages when parsing cost models
1 parent c6148bc commit 41ce2a0

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ instance FromJSON AlonzoExtraConfig where
112112
parseJSON = Aeson.withObject "Extra Config" $ \o ->
113113
o .:? "costModels" >>= \case
114114
Nothing -> pure $ AlonzoExtraConfig Nothing
115-
Just val -> AlonzoExtraConfig . Just <$> parseCostModels True val
115+
Just val -> AlonzoExtraConfig . Just <$> parseCostModels True [] val
116116

117117
instance ToJSON AlonzoExtraConfig where
118118
toJSON (AlonzoExtraConfig cms) = Aeson.object ["costModels" .= cms]
@@ -221,7 +221,7 @@ instance ToCBOR AlonzoGenesis where
221221
instance FromJSON AlonzoGenesis where
222222
parseJSON = Aeson.withObject "Alonzo Genesis" $ \o -> do
223223
agCoinsPerUTxOWord <- o .: "lovelacePerUTxOWord"
224-
cms <- parseCostModels False =<< o .: "costModels"
224+
cms <- parseCostModels False [PlutusV1] =<< o .: "costModels"
225225
agPrices <- o .: "executionPrices"
226226
agMaxTxExUnits <- o .: "maxTxExUnits"
227227
agMaxBlockExUnits <- o .: "maxBlockExUnits"

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.19.0.0
44

5+
* Changed type of `parseCostModels` by adding `[Language]` argument
56
* Add `cddl` sub-library.
67
* Limit `DecCBORGroup` decoding of `ProtVer` fields to `Word32` starting from protocol version `12`
78
* Change `Relation` type to only be visible at the type level

libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/CostModels.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,24 @@ instance NFData CostModel where
134134
rnf (CostModel lang cm ectx) = lang `deepseq` cm `deepseq` rnf ectx
135135

136136
instance FromJSON CostModels where
137-
parseJSON = parseCostModels True
137+
parseJSON = parseCostModels True []
138138

139139
parseCostModels ::
140140
-- | Do not restrict number of parameters to the initial count and allow parsing of cost models
141141
-- for unknown plutus versions.
142142
Bool ->
143+
-- | Restrict parsable Plutus language versions to the given list.
144+
-- If left empty, no restrictions are applied and all non-native languages
145+
-- are parsed.
146+
[Language] ->
143147
Value ->
144148
Parser CostModels
145-
parseCostModels isLenient =
149+
parseCostModels isLenient languages =
146150
withObject "CostModels" $ \o -> do
147-
cms <- mapM (parseCostModel isLenient o) nonNativeLanguages
151+
cms <-
152+
if null languages
153+
then mapM (parseCostModel isLenient o) nonNativeLanguages
154+
else mapM (parseCostModel isLenient o) languages
148155
let cmsMap = Map.fromList [(cmLanguage cm, cm) | Just cm <- cms]
149156
unknownCostModels <-
150157
if isLenient

0 commit comments

Comments
 (0)