File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import Data.String.ToString (toString)
3333import Data.Text (Text )
3434import Data.Text qualified as Text
3535import PlutusConfig.Base (
36+ customRationalSpec ,
3637 enumToAtom ,
3738 filepathSpec ,
3839 maybeSpec ,
@@ -95,6 +96,7 @@ instance ToValue PABConfig where
9596 pcPort
9697 pcEnableTxEndpoint
9798 pcCollectStats
99+ pcBudgetMultiplier
98100 ) =
99101 Sections
100102 ()
@@ -116,6 +118,7 @@ instance ToValue PABConfig where
116118 , Section () " port" $ toValue pcPort
117119 , Section () " enableTxEndpoint" $ toValue pcEnableTxEndpoint
118120 , Section () " collectStats" $ toValue pcCollectStats
121+ , Section () " budgetMultiplier" $ toValue pcBudgetMultiplier
119122 ]
120123{- ORMOLU_ENABLE -}
121124
@@ -206,6 +209,13 @@ pabConfigSpec = sectionsSpec "PABConfig" $ do
206209 trueOrFalseSpec
207210 " Save some stats during contract run (only transactions execution budgets supported atm)"
208211
212+ pcBudgetMultiplier <-
213+ sectionWithDefault'
214+ (pcBudgetMultiplier def)
215+ " budgetMultiplier"
216+ customRationalSpec
217+ " Multiplier on the budgets automatically calculated"
218+
209219 pure PABConfig {.. }
210220
211221docPABConfig :: String
Original file line number Diff line number Diff line change @@ -46,11 +46,18 @@ estimateBudget pabConf txFile = do
4646 let txBudget = do
4747 body <- txBody
4848 budget <- budgetRes
49- (spendingBudgets, policyBudgets) <- mkBudgetMaps budget body
49+ let scaledBudget = fmap (fmap $ scaleBudget pabConf. pcBudgetMultiplier) budget
50+ (spendingBudgets, policyBudgets) <- mkBudgetMaps scaledBudget body
5051 Right $ TxBudget spendingBudgets policyBudgets
5152
5253 return txBudget
5354
55+ -- | Scale the budget by the multipliers in config
56+ scaleBudget :: Rational -> CAPI. ExecutionUnits -> CAPI. ExecutionUnits
57+ scaleBudget scaler (CAPI. ExecutionUnits steps mem) = CAPI. ExecutionUnits (scale steps) (scale mem)
58+ where
59+ scale x = round $ toRational x * scaler
60+
5461-- | Deserialize transaction body from ".signed" file
5562deserialiseSigned :: FilePath -> IO (Either BudgetEstimationError (CAPI. Tx CAPI. AlonzoEra ))
5663deserialiseSigned txFile = do
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ data PABConfig = PABConfig
8383 , pcPort :: ! Port
8484 , pcEnableTxEndpoint :: ! Bool
8585 , pcCollectStats :: ! Bool
86+ , pcBudgetMultiplier :: ! Rational
8687 }
8788 deriving stock (Show , Eq )
8889
@@ -221,6 +222,7 @@ instance Default PABConfig where
221222 , pcPort = 9080
222223 , pcEnableTxEndpoint = False
223224 , pcCollectStats = False
225+ , pcBudgetMultiplier = 1
224226 }
225227
226228data RawTx = RawTx
You can’t perform that action at this time.
0 commit comments