Skip to content

Commit 6e3da00

Browse files
author
Kenneth MacKenzie
authored
Kwxm/mainnet script budgets (#5973)
* Mainnet script budget analysis * Comment * Add a comment
1 parent 59d4b04 commit 6e3da00

File tree

1 file changed

+36
-6
lines changed
  • plutus-ledger-api/exe/analyse-script-events

1 file changed

+36
-6
lines changed

plutus-ledger-api/exe/analyse-script-events/Main.hs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
-- editorconfig-checker-disable-file
2-
{-# LANGUAGE GADTs #-}
3-
{-# LANGUAGE LambdaCase #-}
4-
{-# LANGUAGE RecordWildCards #-}
5-
{-# LANGUAGE TemplateHaskell #-}
6-
{-# LANGUAGE TupleSections #-}
7-
{-# LANGUAGE TypeApplications #-}
2+
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE LambdaCase #-}
4+
{-# LANGUAGE NumericUnderscores #-}
5+
{-# LANGUAGE RecordWildCards #-}
6+
{-# LANGUAGE TemplateHaskell #-}
7+
{-# LANGUAGE TupleSections #-}
8+
{-# LANGUAGE TypeApplications #-}
89

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

356+
357+
max_tx_ex_steps :: Double
358+
max_tx_ex_steps = 10_000_000_000
359+
360+
max_tx_ex_mem :: Double
361+
max_tx_ex_mem = 14_000_000
362+
363+
-- Print out the CPU and memory budgets of each script event. These are the costs
364+
-- paid for by the submitters, not the actual costs consumed during execution.
365+
-- TODO: add a version that tells us the actual execution costs.
366+
getBudgets :: EventAnalyser
367+
getBudgets _ctx _params ev =
368+
let printFractions d =
369+
let ExBudget (V2.ExCPU cpu) (V2.ExMemory mem) = dataBudget d
370+
in printf "%15d %10.8f %15d %10.8f\n"
371+
(fromSatInt cpu :: Int)
372+
((fromSatInt cpu) / max_tx_ex_steps)
373+
(fromSatInt mem :: Int)
374+
((fromSatInt mem) / max_tx_ex_mem)
375+
376+
in case ev of
377+
PlutusV1Event evdata _expected -> printFractions evdata
378+
PlutusV2Event evdata _expected -> printFractions evdata
379+
355380
main :: IO ()
356381
main =
357382
let analyses =
@@ -375,6 +400,11 @@ main =
375400
, "count the total number of occurrences of each builtin in validator scripts"
376401
, countBuiltins
377402
)
403+
, ( "budgets"
404+
, "print (claimed) budgets of scripts"
405+
, putStrLn " cpu cpuFraction mem memFraction"
406+
`thenDoAnalysis` getBudgets
407+
)
378408
]
379409

380410
doAnalysis analyser = mapM_ (analyseOneFile analyser)

0 commit comments

Comments
 (0)