Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data EvaluationContext
- mkEvaluationContext ∷ (MonadError CostModelApplyError m, MonadWriter [CostModelApplyWarn] m) ⇒ [Int64] → m EvaluationContext
- type CostModelParams = Map Text Int64
- assertWellFormedCostModelParams ∷ MonadError CostModelApplyError m ⇒ CostModelParams → m ()
- toMachineParameters ∷ MajorProtocolVersion → EvaluationContext → DefaultMachineParameters
- data CostModelApplyError
Documentation
data EvaluationContext Source #
An opaque type that contains all the static parameters that the evaluator needs to evaluate a script. This is so that they can be computed once and cached, rather than being recomputed on every evaluation.
Different protocol versions may require different bundles of machine parameters, which allows us for
example to tweak the shape of the costing function of a builtin, so that the builtin costs less.
Currently this means that we have to create multiple DefaultMachineParameters
per language
version, which we put into a cache (represented by an association list) in order to avoid costly
recomputation of machine parameters.
In order to get the appropriate DefaultMachineParameters
at validation time we look it up in the
cache using a semantics variant as a key. We compute the semantics variant from the protocol
version using the stored function. Note that the semantics variant depends on the language version
too, but the latter is known statically (because each language version has its own evaluation
context), hence there's no reason to require it to be provided at runtime.
To say it differently, there's a matrix of semantics variants indexed by (LL, PV) pairs and we
cache its particular row corresponding to the statically given LL in an EvaluationContext
.
The reason why we associate a DefaultMachineParameters
with a semantics variant rather than a
protocol version are
- generally there are far more protocol versions than semantics variants supported by a specific language version, so we save on pointless duplication of bundles of machine parameters
- builtins don't know anything about protocol versions, only semantics variants. It is therefore more semantically precise to associate bundles of machine parameters with semantics variants than with protocol versions
Instances
∷ (MonadError CostModelApplyError m, MonadWriter [CostModelApplyWarn] m) | |
⇒ [Int64] | the (updated) cost model parameters of the protocol |
→ m EvaluationContext |
Build the EvaluationContext
.
The input is a list of cost model parameters (which are integer values) passed from the ledger.
IMPORTANT: the cost model parameters MUST appear in the correct order,
matching the names in ParamName
. If the parameters are
supplied in the wrong order then script cost calculations will be incorrect.
IMPORTANT: The evaluation context of every Plutus version must be recreated upon a protocol update with the updated cost model parameters.
type CostModelParams = Map Text Int64 Source #
A raw representation of the ledger's cost model parameters.
The associated keys/names to the parameter values are arbitrarily set by the plutus team; the ledger does not hold any such names.
See Note [Cost model parameters]
assertWellFormedCostModelParams ∷ MonadError CostModelApplyError m ⇒ CostModelParams → m () Source #
data CostModelApplyError Source #
A fatal error when trying to create a cost given some plain costmodel parameters.
CMUnknownParamError !Text | a costmodel parameter with the give name does not exist in the costmodel to be applied upon |
CMInternalReadError | internal error when we are transforming the applyParams' input to json (should not happen) |
CMInternalWriteError !String | internal error when we are transforming the applied params from json with given jsonstring error (should not happen) |