Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
effectfully committed Apr 23, 2024
1 parent 9d8942d commit e6afc0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions plutus-ledger-api/src/PlutusLedgerApi/Common/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mkTermToEvaluate ll pv script args = do
through (liftEither . first DeBruijnError . UPLC.checkScope) appliedT

toMachineParameters :: MajorProtocolVersion -> EvaluationContext -> DefaultMachineParameters
toMachineParameters pv (EvaluationContext lv toSemVar machParsList) =
toMachineParameters pv (EvaluationContext ll toSemVar machParsList) =
case lookup (toSemVar pv) machParsList of
Nothing -> error $ Prelude.concat
["Internal error: ", show lv, " does not support protocol version ", show pv]
Expand All @@ -128,6 +128,9 @@ version using the stored function. Note that the semantics variant depends on th
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
Expand All @@ -141,7 +144,8 @@ data EvaluationContext = EvaluationContext
{ _evalCtxLedgerLang :: PlutusLedgerLanguage
-- ^ Specifies what language versions the 'EvaluationContext' is for.
, _evalCtxToSemVar :: MajorProtocolVersion -> BuiltinSemanticsVariant DefaultFun
-- ^ Specifies how to get a semantics variant given a 'MajorProtocolVersion'.
-- ^ Specifies how to get a semantics variant for this ledger language given a
-- 'MajorProtocolVersion'.
, _evalCtxMachParsCache :: [(BuiltinSemanticsVariant DefaultFun, DefaultMachineParameters)]
-- ^ The cache of 'DefaultMachineParameters' for each semantics variant supported by the
-- current language version.
Expand Down Expand Up @@ -169,8 +173,8 @@ mkDynEvaluationContext
-> (MajorProtocolVersion -> BuiltinSemanticsVariant DefaultFun)
-> Plutus.CostModelParams
-> m EvaluationContext
mkDynEvaluationContext lv semVars toSemVar newCMP =
EvaluationContext lv toSemVar <$> mkMachineParametersFor semVars newCMP
mkDynEvaluationContext ll semVars toSemVar newCMP =
EvaluationContext ll toSemVar <$> mkMachineParametersFor semVars newCMP

-- FIXME: remove this function
assertWellFormedCostModelParams :: MonadError CostModelApplyError m => Plutus.CostModelParams -> m ()
Expand Down
6 changes: 3 additions & 3 deletions plutus-ledger-api/src/PlutusLedgerApi/V2/EvaluationContext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PlutusLedgerApi.Common
import PlutusLedgerApi.Common.Versions (conwayPV)
import PlutusLedgerApi.V2.ParamName as V2

import PlutusCore.Default as Plutus (BuiltinSemanticsVariant (DefaultFunSemanticsVariant0, DefaultFunSemanticsVariant1))
import PlutusCore.Default (BuiltinSemanticsVariant (DefaultFunSemanticsVariant0, DefaultFunSemanticsVariant1))

import Control.Monad
import Control.Monad.Except
Expand Down Expand Up @@ -41,5 +41,5 @@ mkEvaluationContext =
PlutusV2
[DefaultFunSemanticsVariant0, DefaultFunSemanticsVariant1]
(\pv -> if pv < conwayPV
then Plutus.DefaultFunSemanticsVariant0
else Plutus.DefaultFunSemanticsVariant1)
then DefaultFunSemanticsVariant0
else DefaultFunSemanticsVariant1)
4 changes: 2 additions & 2 deletions plutus-ledger-api/src/PlutusLedgerApi/V3/EvaluationContext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module PlutusLedgerApi.V3.EvaluationContext
import PlutusLedgerApi.Common
import PlutusLedgerApi.V3.ParamName as V3

import PlutusCore.Default as Plutus (BuiltinSemanticsVariant (DefaultFunSemanticsVariant2))
import PlutusCore.Default (BuiltinSemanticsVariant (DefaultFunSemanticsVariant2))

import Control.Monad
import Control.Monad.Except
Expand All @@ -38,4 +38,4 @@ mkEvaluationContext =
>=> mkDynEvaluationContext
PlutusV3
[DefaultFunSemanticsVariant2]
(const Plutus.DefaultFunSemanticsVariant2)
(const DefaultFunSemanticsVariant2)

0 comments on commit e6afc0b

Please sign in to comment.