Skip to content

Commit

Permalink
Kwxm/mainnet script budgets (#5973)
Browse files Browse the repository at this point in the history
* Mainnet script budget analysis

* Comment

* Add a comment
  • Loading branch information
kwxm committed May 14, 2024
1 parent 59d4b04 commit 6e3da00
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions plutus-ledger-api/exe/analyse-script-events/Main.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
-- editorconfig-checker-disable-file
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}

-- | Various analyses of events in mainnet script dumps.
-- This only deals with PlutusV1 and PlutusV2 script events because
Expand Down Expand Up @@ -352,6 +353,30 @@ analyseOneFile analyse eventFile = do
Just (ctx, params) -> analyse ctx params event
Nothing -> putStrLn "*** ctxV2 missing ***"


max_tx_ex_steps :: Double
max_tx_ex_steps = 10_000_000_000

max_tx_ex_mem :: Double
max_tx_ex_mem = 14_000_000

-- Print out the CPU and memory budgets of each script event. These are the costs
-- paid for by the submitters, not the actual costs consumed during execution.
-- TODO: add a version that tells us the actual execution costs.
getBudgets :: EventAnalyser
getBudgets _ctx _params ev =
let printFractions d =
let ExBudget (V2.ExCPU cpu) (V2.ExMemory mem) = dataBudget d
in printf "%15d %10.8f %15d %10.8f\n"
(fromSatInt cpu :: Int)
((fromSatInt cpu) / max_tx_ex_steps)
(fromSatInt mem :: Int)
((fromSatInt mem) / max_tx_ex_mem)

in case ev of
PlutusV1Event evdata _expected -> printFractions evdata
PlutusV2Event evdata _expected -> printFractions evdata

main :: IO ()
main =
let analyses =
Expand All @@ -375,6 +400,11 @@ main =
, "count the total number of occurrences of each builtin in validator scripts"
, countBuiltins
)
, ( "budgets"
, "print (claimed) budgets of scripts"
, putStrLn " cpu cpuFraction mem memFraction"
`thenDoAnalysis` getBudgets
)
]

doAnalysis analyser = mapM_ (analyseOneFile analyser)
Expand Down

0 comments on commit 6e3da00

Please sign in to comment.