From f9784b9d358013ae1c8c6683ec9be158c971f1a2 Mon Sep 17 00:00:00 2001 From: kwxm Date: Mon, 13 May 2024 17:57:37 +0100 Subject: [PATCH 1/3] Mainnet script budget analysis --- .../exe/analyse-script-events/Main.hs | 39 ++++++++++++++++--- 1 file changed, 33 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..c6bdb6a9c6b 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,27 @@ 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 + +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 +397,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) From 4b35f9cbb9ffe702493f8546b10cb0812ba56775 Mon Sep 17 00:00:00 2001 From: kwxm Date: Mon, 13 May 2024 18:02:48 +0100 Subject: [PATCH 2/3] Comment --- plutus-ledger-api/exe/analyse-script-events/Main.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plutus-ledger-api/exe/analyse-script-events/Main.hs b/plutus-ledger-api/exe/analyse-script-events/Main.hs index c6bdb6a9c6b..1c8b86976b8 100644 --- a/plutus-ledger-api/exe/analyse-script-events/Main.hs +++ b/plutus-ledger-api/exe/analyse-script-events/Main.hs @@ -360,6 +360,8 @@ 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. getBudgets :: EventAnalyser getBudgets _ctx _params ev = let printFractions d = From 3650109de5509dbb4d9362c800a31b7630161111 Mon Sep 17 00:00:00 2001 From: kwxm Date: Tue, 14 May 2024 12:49:15 +0100 Subject: [PATCH 3/3] Add a comment --- plutus-ledger-api/exe/analyse-script-events/Main.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/plutus-ledger-api/exe/analyse-script-events/Main.hs b/plutus-ledger-api/exe/analyse-script-events/Main.hs index 1c8b86976b8..9b4be82bc36 100644 --- a/plutus-ledger-api/exe/analyse-script-events/Main.hs +++ b/plutus-ledger-api/exe/analyse-script-events/Main.hs @@ -362,6 +362,7 @@ 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 =