| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Ledger.Plutus.CostModels
Contents
Synopsis
- data CostModel
- mkCostModel ∷ Language → [Int64] → Either CostModelApplyError CostModel
- mkCostModelsLenient ∷ MonadFail m ⇒ Map Word8 [Int64] → m CostModels
- encodeCostModel ∷ CostModel → Encoding
- getCostModelLanguage ∷ CostModel → Language
- getCostModelParams ∷ CostModel → [Int64]
- getCostModelEvaluationContext ∷ CostModel → EvaluationContext
- getEvaluationContext ∷ CostModel → EvaluationContext
- costModelParamNames ∷ Language → [Text]
- costModelToMap ∷ CostModel → Map Text Int64
- costModelFromMap ∷ MonadFail m ⇒ Language → Map Text Int64 → m CostModel
- decodeCostModel ∷ Language → Decoder s CostModel
- costModelInitParamNames ∷ Language → [Text]
- costModelInitParamCount ∷ Language → Int
- parseCostModelAsMap ∷ Bool → Language → Object → Parser CostModel
- parseCostModelAsArray ∷ Bool → Language → Array → Parser CostModel
- data CostModels
- mkCostModels ∷ Map Language CostModel → CostModels
- emptyCostModels ∷ CostModels
- updateCostModels ∷ CostModels → CostModels → CostModels
- parseCostModels ∷ Bool → [Language] → Value → Parser CostModels
- decodeCostModelsLenient ∷ Decoder s CostModels
- decodeCostModelsFailing ∷ Decoder s CostModels
- costModelsValid ∷ CostModels → Map Language CostModel
- costModelsUnknown ∷ CostModels → Map Word8 [Int64]
- flattenCostModels ∷ CostModels → Map Word8 [Int64]
Cost Model
A language dependent cost model for the Plutus evaluator.
Note that the EvaluationContext is entirely dependent on the
cost model parameters (ie the Map Text Integer) and that
this type uses the smart constructor mkCostModel
to hide the evaluation context.
Instances
mkCostModel ∷ Language → [Int64] → Either CostModelApplyError CostModel Source #
Convert cost model parameters to a cost model, making use of the conversion function mkEvaluationContext from the Plutus API.
Note that we always retain the original values that were supplied.
mkCostModelsLenient ∷ MonadFail m ⇒ Map Word8 [Int64] → m CostModels Source #
This function attempts to convert a Map with potential cost models into validated
CostModels. If it is a valid cost model for a known version of Plutus, it is added
to costModelsValid. If it is an invalid cost model for a known version of Plutus, the
function will fail with a string version of CostModelApplyError. Lastly, if the
Plutus version is unknown, the cost model is also stored in costModelsUnknown.
encodeCostModel ∷ CostModel → Encoding Source #
Encoding for the CostModel. Important to note that it differs from Encoding used
by getLanguageView
getCostModelParams ∷ CostModel → [Int64] Source #
costModelParamNames ∷ Language → [Text] Source #
decodeCostModel ∷ Language → Decoder s CostModel Source #
Prior to version 9, each CostModel was expected to be serialized as an array of
integers of a specific length (depending on the version of Plutus). Starting in
version 9, we allow the decoders to accept lists longer or shorter than what they
require, so that new fields can be added in the future. For this reason, we must hard
code the length expectation into the deserializers prior to version 9.
Note that the number of elements in the V1 and V2 cost models are allowed to change in the future, they are only fixed prior to version 9.
See https://github.com/intersectmbo/cardano-ledger/issues/2902 and https://github.com/intersectmbo/cardano-ledger/blob/master/docs/adr/2022-12-05_006-cost-model-serialization.md
costModelInitParamNames ∷ Language → [Text] Source #
List of parameter names as when they were introduced upon a hard fork to a specific era for a corresponding plutus version.
costModelInitParamCount ∷ Language → Int Source #
Number of CostModel parameters for a specified plutus version as when it was initially
added. This is useful for genesis files, which shouldn't have the number of parameters vary over
time.
Cost Models
data CostModels Source #
For a known version of Plutus, attempting to construct a cost model with
too few parameters (depending on the version) will result in an error.
CostModelApplyError exists to collect these errors in the CostModels type.
The CostModels type itself needs to be flexible enough to accept any map
of Word8 to '[Int64]', so that cost models can be placed in the protocol parameters
ahead of changes to the Plutus evaluation context. In this way, serializing a cost model,
updating software, and deserializing can result in errors going away.
Additionally, CostModels needs to be able to store cost models for future version
of Plutus, which we cannot yet even validate. These are stored in
costModelsUnknown.
Instances
| FromJSON CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods parseJSON ∷ Value → Parser CostModels Source # parseJSONList ∷ Value → Parser [CostModels] Source # | |||||
| ToJSON CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods toJSON ∷ CostModels → Value Source # toEncoding ∷ CostModels → Encoding Source # toJSONList ∷ [CostModels] → Value Source # toEncodingList ∷ [CostModels] → Encoding Source # omitField ∷ CostModels → Bool Source # | |||||
| DecCBOR CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels | |||||
| EncCBOR CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods encCBOR ∷ CostModels → Encoding Source # | |||||
| ToPlutusData CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.ToPlutusData | |||||
| NFData CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods rnf ∷ CostModels → () # | |||||
| Monoid CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels | |||||
| Semigroup CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods (<>) ∷ CostModels → CostModels → CostModels # sconcat ∷ NonEmpty CostModels → CostModels # stimes ∷ Integral b ⇒ b → CostModels → CostModels # | |||||
| Generic CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Associated Types
| |||||
| Show CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods showsPrec ∷ Int → CostModels → ShowS # show ∷ CostModels → String # showList ∷ [CostModels] → ShowS # | |||||
| Eq CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels | |||||
| Ord CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels Methods compare ∷ CostModels → CostModels → Ordering # (<) ∷ CostModels → CostModels → Bool # (<=) ∷ CostModels → CostModels → Bool # (>) ∷ CostModels → CostModels → Bool # (>=) ∷ CostModels → CostModels → Bool # max ∷ CostModels → CostModels → CostModels # min ∷ CostModels → CostModels → CostModels # | |||||
| NoThunks CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels | |||||
| type Rep CostModels Source # | |||||
Defined in Cardano.Ledger.Plutus.CostModels type Rep CostModels = D1 ('MetaData "CostModels" "Cardano.Ledger.Plutus.CostModels" "cardano-ledger-core-1.19.0.0-inplace" 'False) (C1 ('MetaCons "CostModels" 'PrefixI 'True) (S1 ('MetaSel ('Just "_costModelsValid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map Language CostModel)) :*: S1 ('MetaSel ('Just "_costModelsUnknown") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map Word8 [Int64])))) | |||||
mkCostModels ∷ Map Language CostModel → CostModels Source #
Construct an all valid CostModels
Arguments
| ∷ CostModels | Old CostModels that will be overwritten |
| → CostModels | New CostModels that will overwrite |
| → CostModels |
Updates the first with the second one, so that only the cost models
that are present in the second one get updated while all the others stay
unchanged. Language specific errors and unknown cost models are removed, whenever a
valid CostModelsCostModel for the language is supplied in the update.
Arguments
| ∷ Bool | Do not restrict number of parameters to the initial count and allow parsing of cost models for unknown plutus versions. |
| → [Language] | Restrict parsable Plutus language versions to the given list. If left empty, no restrictions are applied and all non-native languages are parsed. |
| → Value | |
| → Parser CostModels |
costModelsUnknown ∷ CostModels → Map Word8 [Int64] Source #
flattenCostModels ∷ CostModels → Map Word8 [Int64] Source #
Turn a CostModels into a mapping of potential language versions and cost model
values, with no distinction between valid and unknown cost models. This is used for
serialization, so that judgements about known languages can be made upon
deserialization.