From 0f5dc888cdc2eebd889212b599cc025d5a8107d1 Mon Sep 17 00:00:00 2001 From: Kenneth MacKenzie Date: Tue, 14 May 2024 13:17:51 +0100 Subject: [PATCH] Kwxm/mainnet script budgets (#5973) * Mainnet script budget analysis * Comment * Add a comment --- .../exe/analyse-script-events/Main.hs | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/plutus-ledger-api/exe/analyse-script-events/Main.hs b/plutus-ledger-api/exe/analyse-script-events/Main.hs index 4c8a0f8431b..9b4be82bc36 100644 --- a/plutus-ledger-api/exe/analyse-script-events/Main.hs +++ b/plutus-ledger-api/exe/analyse-script-events/Main.hs @@ -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 @@ -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 = @@ -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)