-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce flexible cost model decoding
Starting in version 9, 'CostModels' can now be deserialized from any map from Word8 values to lists of integers. Only valid cost models are actual converted to cost models. resolves #2902
- Loading branch information
1 parent
c2c7147
commit da48c5b
Showing
26 changed files
with
287 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/CostModel.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Cardano.Ledger.Alonzo.CostModel ( | ||
costModelParamsCount, | ||
freeCostModel, | ||
freeV1CostModels, | ||
freeV1V2CostModels, | ||
) | ||
where | ||
|
||
import Cardano.Ledger.Alonzo.Language (Language (..)) | ||
import Cardano.Ledger.Alonzo.Scripts as Alonzo ( | ||
CostModel, | ||
CostModels (..), | ||
mkCostModel, | ||
) | ||
import Data.Either (fromRight) | ||
import qualified Data.Map.Strict as Map | ||
import qualified PlutusLedgerApi.V1 as PV1 (ParamName) | ||
import qualified PlutusLedgerApi.V2 as PV2 (ParamName) | ||
import PlutusPrelude (enumerate) | ||
|
||
costModelParamsCount :: Language -> Int | ||
costModelParamsCount lang = case lang of | ||
PlutusV1 -> length (enumerate @PV1.ParamName) | ||
PlutusV2 -> length (enumerate @PV2.ParamName) | ||
|
||
-- | A cost model that sets everything as being free | ||
freeCostModel :: Language -> CostModel | ||
freeCostModel lang = | ||
fromRight (error "freeCostModel is not well-formed") $ | ||
Alonzo.mkCostModel lang (replicate (costModelParamsCount lang) 0) | ||
|
||
freeV1CostModels :: CostModels | ||
freeV1CostModels = CostModels (Map.singleton PlutusV1 (freeCostModel PlutusV1)) mempty mempty | ||
|
||
freeV1V2CostModels :: CostModels | ||
freeV1V2CostModels = | ||
CostModels (Map.fromList [(l, freeCostModel l) | l <- [PlutusV1, PlutusV2]]) mempty mempty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.