Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kwxm/mainnet script budgets #5973

Merged
merged 3 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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