Skip to content

Commit

Permalink
tx-generator | workbench: add PlutusV2 capability and SECP benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeier authored and deepfire committed Dec 9, 2022
1 parent 05da82a commit 90c3f17
Show file tree
Hide file tree
Showing 29 changed files with 1,412 additions and 392 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ ps: ## Plain-text list of profiles
##
## Profile-based cluster shells (autogenerated targets)
##
PROFILES_BASE := default plutus oldtracing idle tracer-only
PROFILES_BASE := default plutus plutus-secp-ecdsa plutus-secp-schnorr oldtracing idle tracer-only
PROFILES_STARTSTOP := startstop startstop-p2p startstop-plutus startstop-notracer startstop-oldtracing
PROFILES_CI_TEST := ci-test ci-test-p2p ci-test-plutus ci-test-notracer ci-test-dense10
PROFILES_CI_BENCH := ci-bench ci-bench-p2p ci-bench-plutus ci-bench-notracer
PROFILES_CI_BENCH := ci-bench ci-bench-p2p ci-bench-plutus ci-bench-plutus-secp-ecdsa ci-bench-plutus-secp-schnorr ci-bench-notracer
PROFILES_10 := 10 10-p2p 10-plutus 10-notracer
PROFILES_FORGE_STRESS := forge-stress forge-stress-p2p forge-stress-plutus forge-stress-plutus-singleton forge-stress-notracer
PROFILES_FORGE_STRESS_PRE := forge-stress-pre forge-stress-pre-plutus forge-stress-pre-notracer
Expand Down
1 change: 1 addition & 0 deletions bench/tx-generator/data/ecdsa-secp256k1-loop.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"constructor":0,"fields":[{"int":1000000},{"bytes":"0392d7b94bc6a11c335a043ee1ff326b6eacee6230d3685861cd62bce350a172e0"},{"bytes":"16e0bf1f85594a11e75030981c0b670370b3ad83a43f49ae58a2fd6f6513cde9"},{"bytes":"5fb12954b28be6456feb080cfb8467b6f5677f62eb9ad231de7a575f4b6857512754fb5ef7e0e60e270832e7bb0e2f0dc271012fa9c46c02504aa0e798be6295"}]}
1 change: 1 addition & 0 deletions bench/tx-generator/data/loop.redeemer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"int":1000000}
386 changes: 386 additions & 0 deletions bench/tx-generator/data/protocol-parameters-v8.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions bench/tx-generator/data/protocol-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lessThanEqualsByteString-cpu-arguments-intercept": 103599,
"encodeUtf8-cpu-arguments-slope": 1000,
"equalsString-cpu-arguments-constant": 1000,
"blake2b-cpu-arguments-slope": 29175,
"blake2b_256-cpu-arguments-slope": 29175,
"consByteString-memory-arguments-intercept": 0,
"headList-cpu-arguments": 150000,
"listData-cpu-arguments": 150000,
Expand Down Expand Up @@ -121,7 +121,7 @@
"indexByteString-cpu-arguments": 150000,
"equalsInteger-cpu-arguments-slope": 1326,
"lessThanByteString-memory-arguments": 1,
"blake2b-cpu-arguments-intercept": 2477736,
"blake2b_256-cpu-arguments-intercept": 2477736,
"encodeUtf8-cpu-arguments-intercept": 150000,
"multiplyInteger-cpu-arguments-slope": 11218,
"tailList-cpu-arguments": 150000,
Expand All @@ -148,7 +148,7 @@
"sliceByteString-memory-arguments-slope": 1,
"sha3_256-memory-arguments": 4,
"mkCons-memory-arguments": 32,
"verifySignature-cpu-arguments-intercept": 3345831,
"verifyEd25519Signature-cpu-arguments-intercept": 3345831,
"cekBuiltinCost-exBudgetMemory": 100,
"remainderInteger-memory-arguments-intercept": 0,
"lessThanEqualsByteString-memory-arguments": 1,
Expand All @@ -167,14 +167,14 @@
"nullList-memory-arguments": 32,
"lessThanByteString-cpu-arguments-intercept": 103599,
"appendByteString-memory-arguments-slope": 1,
"blake2b-memory-arguments": 4,
"blake2b_256-memory-arguments": 4,
"unBData-memory-arguments": 32,
"cekConstCost-exBudgetCPU": 29773,
"consByteString-cpu-arguments-slope": 1000,
"trace-memory-arguments": 32,
"quotientInteger-memory-arguments-intercept": 0,
"mapData-memory-arguments": 32,
"verifySignature-cpu-arguments-slope": 1,
"verifyEd25519Signature-cpu-arguments-slope": 1,
"quotientInteger-cpu-arguments-model-arguments-intercept": 425507,
"modInteger-cpu-arguments-constant": 148000,
"appendString-cpu-arguments-slope": 1000,
Expand All @@ -184,7 +184,7 @@
"equalsByteString-cpu-arguments-intercept": 112536,
"sliceByteString-memory-arguments-intercept": 0,
"lessThanInteger-cpu-arguments-slope": 497,
"verifySignature-memory-arguments": 1,
"verifyEd25519Signature-memory-arguments": 1,
"cekLamCost-exBudgetMemory": 100,
"sliceByteString-cpu-arguments-intercept": 150000,
"modInteger-cpu-arguments-model-arguments-intercept": 425507,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"constructor":0,"fields":[{"int":1000000},{"bytes":"599de3e582e2a3779208a210dfeae8f330b9af00a47a7fb22e9bb8ef596f301b"},{"bytes":"30303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030"},{"bytes":"5a56da88e6fd8419181dec4d3dd6997bab953d2fc71ab65e23cfc9e7e3d1a310613454a60f6703819a39fdac2a410a094442afd1fc083354443e8d8bb4461a9b"}]}
52 changes: 32 additions & 20 deletions bench/tx-generator/src/Cardano/Benchmarking/Compiler.hs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}

{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}

module Cardano.Benchmarking.Compiler
where

import Prelude

import Control.Applicative (liftA2)
import Control.Monad
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except
import Control.Monad.Trans.RWS.CPS
import Data.ByteString as BS (ByteString)
import Data.DList (DList)
import qualified Data.DList as DL
import Data.Functor ((<&>))
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as Text

import Cardano.Api
import Cardano.Benchmarking.Script.Types
import Cardano.TxGenerator.Setup.NixService
import Cardano.TxGenerator.Setup.SigningKey
import Cardano.TxGenerator.Types (TxGenTxParams (..))
import Cardano.TxGenerator.Types

data CompileError where
SomeCompilerError :: String -> CompileError
Expand Down Expand Up @@ -132,17 +136,24 @@ splittingPhase srcWallet = do

plutusPayMode :: DstWallet -> Compiler PayMode
plutusPayMode dst = do
autoMode <- isPlutusAutoMode
scriptSpec <- if autoMode
then ScriptSpec <$> askNixOption _nix_plutusLoopScript <*> pure AutoScript
else do
executionUnits <- ExecutionUnits <$> askNixOption _nix_executionMemory <*> askNixOption _nix_executionSteps
debugMode <- askNixOption _nix_debugMode
budget <- (if debugMode then CheckScriptBudget else StaticScriptBudget)
<$> (ScriptDataNumber <$> askNixOption _nix_plutusData)
<*> (ScriptDataNumber <$> askNixOption _nix_plutusRedeemer)
<*> pure executionUnits
ScriptSpec <$> askNixOption _nix_plutusScript <*> pure budget
~(Just plutus@PlutusOn{..}) <- askNixOption _nix_plutus
scriptSpec <- if plutusType == LimitSaturationLoop
then case plutusRedeemer of
Nothing -> throwCompileError $ SomeCompilerError "Plutus loop autoscript requires a redeemer."
Just redeemer -> do
autoScript <- AutoScript redeemer <$> askNixOption _nix_inputs_per_tx
pure $ ScriptSpec plutusScript autoScript
else case hasStaticBudget plutus of
Nothing -> throwCompileError $ SomeCompilerError "Plutus custom script requires a static budget."
Just executionUnits -> do
debugMode <- askNixOption _nix_debugMode
let
budget = StaticScriptBudget
(fromMaybe "" plutusDatum)
(fromMaybe "" plutusRedeemer)
executionUnits
debugMode
pure $ ScriptSpec plutusScript budget
return $ PayToScript scriptSpec dst

-- Generate src and dst wallet names for a splitSequence.
Expand Down Expand Up @@ -205,7 +216,7 @@ data Fees = Fees {
evilFeeMagic :: Compiler Fees
evilFeeMagic = do
(Quantity tx_fee) <- lovelaceToQuantity <$> askNixOption _nix_tx_fee
plutusMode <- askNixOption _nix_plutusMode
plutusMode <- isPlutusType CustomScript
inputs_per_tx <- askNixOption _nix_inputs_per_tx
outputs_per_tx <- askNixOption _nix_outputs_per_tx
(Quantity min_utxo_value) <- lovelaceToQuantity <$> askNixOption _nix_min_utxo_value
Expand Down Expand Up @@ -239,14 +250,15 @@ askNixOption = asks
delay :: Compiler ()
delay = cmd1 Delay _nix_init_cooldown

isPlutusMode :: Compiler Bool
isPlutusMode = askNixOption _nix_plutusMode

isPlutusAutoMode :: Compiler Bool
isPlutusAutoMode = askNixOption _nix_plutusAutoMode
isPlutusType :: TxGenPlutusType -> Compiler Bool
isPlutusType t
= askNixOption _nix_plutus <&> \case
Just PlutusOn{plutusType = t'} -> t == t'
_ -> False

isAnyPlutusMode :: Compiler Bool
isAnyPlutusMode = liftA2 (||) isPlutusMode isPlutusAutoMode
isAnyPlutusMode
= isJust <$> askNixOption _nix_plutus

newIdentifier :: String -> Compiler String
newIdentifier prefix = do
Expand Down
15 changes: 3 additions & 12 deletions bench/tx-generator/src/Cardano/Benchmarking/OuroborosImports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Cardano.Benchmarking.OuroborosImports
, SigningKeyFile
, StandardShelley
, NetworkId
, getGenesis
-- , getGenesis
, makeLocalConnectInfo
, protocolToTopLevelConfig
, protocolToNetworkId
Expand All @@ -38,8 +38,8 @@ import Cardano.Api.Shelley (CardanoMode)
import Cardano.CLI.Types (SigningKeyFile)

import Cardano.Api (BlockType (..), ConsensusModeParams (..), EpochSlots (..),
LocalNodeConnectInfo (..), NetworkId (..), PaymentKey, ProtocolInfoArgs (..),
SigningKey, TxInMode, TxValidationErrorInMode, protocolInfo, submitTxToNodeLocal)
LocalNodeConnectInfo (..), NetworkId (..), PaymentKey, SigningKey, TxInMode,
TxValidationErrorInMode, protocolInfo, submitTxToNodeLocal)
import Cardano.Ledger.Shelley.Genesis (ShelleyGenesis)

type CardanoBlock = Consensus.CardanoBlock StandardCrypto
Expand All @@ -48,15 +48,6 @@ toProtocolInfo :: SomeConsensusProtocol -> ProtocolInfo IO CardanoBlock
toProtocolInfo (SomeConsensusProtocol CardanoBlockType info) = protocolInfo info
toProtocolInfo _ = error "toProtocolInfo unknown protocol"

getGenesis :: SomeConsensusProtocol -> ShelleyGenesis StandardShelley
getGenesis (SomeConsensusProtocol CardanoBlockType info) = shelleyBasedGenesis
where
(ProtocolInfoArgsCardano
_
Consensus.ProtocolParamsShelleyBased{Consensus.shelleyBasedGenesis}
_ _ _ _ _ _ _ _ _ _) = info
getGenesis (SomeConsensusProtocol _ _ ) = error "getGenesis (SomeConsensusProtocol _ _ ) unknown protocol"

protocolToTopLevelConfig :: SomeConsensusProtocol -> TopLevelConfig CardanoBlock
protocolToTopLevelConfig ptcl = pInfoConfig
where
Expand Down
84 changes: 0 additions & 84 deletions bench/tx-generator/src/Cardano/Benchmarking/PlutusExample.hs

This file was deleted.

32 changes: 30 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Action.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{-# LANGUAGE GADTs #-}

module Cardano.Benchmarking.Script.Action
where
( action
, liftToAction
)
where

import qualified Data.Text as Text (unpack)

import Control.Monad.IO.Class
import Control.Monad.Trans.Except.Extra

import Cardano.Benchmarking.OuroborosImports as Core (protocolToNetworkId)
import Cardano.Benchmarking.Script.Core
import Cardano.Benchmarking.Script.Env
import Cardano.Benchmarking.Script.NodeConfig (startProtocol)
import Cardano.Benchmarking.Script.Types
import Cardano.Benchmarking.Tracer
import Cardano.TxGenerator.Setup.NodeConfig
import Cardano.TxGenerator.Types (TxGenError)


action :: Action -> ActionM ()
action a = case a of
Expand All @@ -27,3 +37,21 @@ action a = case a of
WaitForEra era -> waitForEra era
LogMsg txt -> traceDebug $ Text.unpack txt
Reserved options -> reserved options

liftToAction :: IO (Either TxGenError a) -> ActionM a
liftToAction = firstExceptT TxGenError . newExceptT . liftIO

startProtocol :: FilePath -> Maybe FilePath -> ActionM ()
startProtocol configFile tracerSocket = do
nodeConfig <- liftToAction $ mkNodeConfig configFile
protocol <- liftToAction $ mkConsensusProtocol nodeConfig
setEnvProtocol protocol
setEnvGenesis $ getGenesis protocol
let networkId = protocolToNetworkId protocol
setEnvNetworkId networkId
tracers <- case tracerSocket of
Nothing -> liftIO initDefaultTracers
Just socket -> do
iomgr <- askIOManager
liftIO $ initTracers iomgr networkId socket
setBenchTracers tracers
5 changes: 5 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ testJSONRoundTrip l = case fromJSON $ toJSON l of
Success r -> if l == r then Nothing else Just "compare: not equal"
Error err -> Just err

prettyPrintOrdered :: ToJSON a => a -> BSL.ByteString
prettyPrintOrdered = encodePretty' conf
where
conf = defConfig {confCompare = compare}

prettyPrint :: [Action] -> BSL.ByteString
prettyPrint = encodePretty' conf
where
Expand Down
Loading

0 comments on commit 90c3f17

Please sign in to comment.