Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- costModelParamsCount ∷ Language → Int
- decodeCostModel ∷ Language → Decoder s CostModel
- data CostModels
- mkCostModels ∷ Map Language CostModel → CostModels
- emptyCostModels ∷ CostModels
- updateCostModels ∷ CostModels → CostModels → 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
ToJSON CostModel Source # | |
Generic CostModel Source # | |
Show CostModel Source # | |
NFData CostModel Source # | |
Defined in Cardano.Ledger.Plutus.CostModels | |
Eq CostModel Source # | Note that this Eq instance ignores the evaluation context, which is
entirely dependent on the cost model parameters and is guarded by the
smart constructor |
Ord CostModel Source # | Note that this Ord instance ignores the evaluation context, which is
entirely dependent on the cost model parameters and is guarded by the
smart constructor |
Defined in Cardano.Ledger.Plutus.CostModels | |
NoThunks CostModel Source # | |
type Rep CostModel Source # | |
Defined in Cardano.Ledger.Plutus.CostModels type Rep CostModel = D1 ('MetaData "CostModel" "Cardano.Ledger.Plutus.CostModels" "cardano-ledger-core-1.17.0.0-inplace" 'False) (C1 ('MetaCons "CostModel" 'PrefixI 'True) (S1 ('MetaSel ('Just "cmLanguage") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Language) :*: (S1 ('MetaSel ('Just "cmValues") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Int64]) :*: S1 ('MetaSel ('Just "cmEvalCtx") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 EvaluationContext)))) |
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 #
costModelParamsCount ∷ Language → Int Source #
Initial number of parameters in a CostModel for a specific language when the language was introduced. Starting with Conway we support variable number of parameters, therefore do not expect this number to reflect the reality on the number of supported parameters.
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
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
mkCostModels ∷ Map Language CostModel → CostModels Source #
Construct an all valid CostModels
∷ 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 CostModels
CostModel
for the language is supplied in the update.
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.