-
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
Jared Corduan
committed
Feb 3, 2023
1 parent
69f3ab9
commit 8187bd1
Showing
25 changed files
with
289 additions
and
123 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
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Cardano.Ledger.Alonzo.CostModel ( | ||
costModelParamsCount, | ||
freeCostModel, | ||
freeV1CostModels, | ||
freeV1V2CostModels, | ||
) | ||
where | ||
|
||
import Data.Either (fromRight) | ||
import PlutusPrelude (enumerate) | ||
import qualified Data.Map.Strict as Map | ||
import qualified PlutusLedgerApi.V1 as PV1 (ParamName) | ||
import qualified PlutusLedgerApi.V2 as PV2 (ParamName) | ||
import Cardano.Ledger.Alonzo.Scripts as Alonzo ( | ||
CostModel, | ||
CostModels (..), | ||
mkCostModel, | ||
) | ||
import Cardano.Ledger.Alonzo.Language (Language (..)) | ||
|
||
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.