cardano-ledger-core-1.12.0.0: Core components of Cardano ledgers from the Shelley release on.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Ledger.Plutus.CostModels

Synopsis

Cost Model

data CostModel Source #

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

Instances details
ToJSON CostModel Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Generic CostModel Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Associated Types

type Rep CostModelTypeType Source #

Show CostModel Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

NFData CostModel Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Methods

rnfCostModel → () Source #

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 mkCostModel.

Instance details

Defined in Cardano.Ledger.Plutus.CostModels

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 mkCostModel.

Instance details

Defined in Cardano.Ledger.Plutus.CostModels

NoThunks CostModel Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

type Rep CostModel Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

type Rep CostModel = D1 ('MetaData "CostModel" "Cardano.Ledger.Plutus.CostModels" "cardano-ledger-core-1.12.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))))

mkCostModelLanguage → [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.

mkCostModelsLenientMonadFail 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.

encodeCostModelCostModelEncoding Source #

Encoding for the CostModel. Important to note that it differs from Encoding used by getLanguageView

costModelParamsCountLanguageInt 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.

decodeCostModelLanguageDecoder 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

Instances details
FromJSON CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

ToJSON CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Monoid CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Semigroup CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Generic CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Associated Types

type Rep CostModelsTypeType Source #

Show CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

DecCBOR CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

EncCBOR CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Methods

encCBORCostModelsEncoding Source #

encodedSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy CostModelsSize Source #

encodedListSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy [CostModels] → Size Source #

ToPlutusData CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.ToPlutusData

NFData CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Methods

rnfCostModels → () Source #

Eq CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

Ord CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

NoThunks CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

type Rep CostModels Source # 
Instance details

Defined in Cardano.Ledger.Plutus.CostModels

type Rep CostModels = D1 ('MetaData "CostModels" "Cardano.Ledger.Plutus.CostModels" "cardano-ledger-core-1.12.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]))))

updateCostModels Source #

Arguments

CostModels

Old CostModels that will be overwritten

CostModels

New CostModels that will overwrite

CostModels 

Updates the first CostModels 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 CostModel for the language is supplied in the update.

flattenCostModelsCostModelsMap 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.