Skip to content

Commit

Permalink
tx-generator: towards stand-alone selftest
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcFontaine committed Mar 29, 2022
1 parent 2c0687f commit a47b3ad
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
29 changes: 19 additions & 10 deletions bench/script/test-stand-alone.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{ "SetProtocolParameters": { "UseLocalProtocolFile": "/tmp/t2.json" } },
{ "SetProtocolParameters": { "UseLocalProtocolFile": "/tmp/t2.json" } },
{ "Set": { "SNumberOfInputsPerTx": 2 } },
{ "Set": { "SNumberOfOutputsPerTx": 2 } },
{ "Set": { "STxAdditionalSize": 39 } },
Expand All @@ -8,6 +8,7 @@
{ "Set": { "STTL": 1000000 } },
{ "Set": { "SEra": "Allegra" } },
{ "Set": { "SNetworkId": { "Testnet": 42 } } },
{ "InitWallet": "test-wallet" },
{ "DefineSigningKey":
[ "pass-partout"
, {
Expand All @@ -16,50 +17,58 @@
"cborHex": "58200b6c317eb6c9762898fa41ca9d683003f86899ab0f2f6dbaf244e415b62826a2"
} ] },
{ "AddFund":
[ "900fc5da77a0747da53f7675cbb7d149d46779346dea2f879ab811ccc72a2162#0"
[ "test-wallet"
, "900fc5da77a0747da53f7675cbb7d149d46779346dea2f879ab811ccc72a2162#0"
, 90000000000000
, "pass-partout"
] },
{ "CreateChange": [
"test-wallet",
"test-wallet",
{ "DumpToFile": "/tmp/script-txs.txt" },
{ "PayToAddr": "pass-partout" },
149200212345,
1
] },
{ "CreateChange": [
"test-wallet",
"test-wallet",
{ "DumpToFile": "/tmp/script-txs.txt" },
{ "PayToCollateral": "pass-partout" },
149200000000,
1
] },
{ "CreateChange": [
"test-wallet",
"test-wallet",
{ "DumpToFile": "/tmp/split-txs.txt" },
{ "PayToAddr": "pass-partout" },
2200000000000,
10
] },
{ "CreateChange": [
"test-wallet",
"test-wallet",
{ "DumpToFile": "/tmp/split-txs.txt" },
{ "PayToAddr": "pass-partout" },
70000000000,
300
] },
{ "CreateChange": [
"test-wallet",
"test-wallet",
{ "DumpToFile": "/tmp/script-txs.txt" },
{ "PayToScript": [ "bench/script/sum1ToN.plutus", 3 ] },
{ "PayToAddr": "pass-partout" },
2300000000,
9000
] },
] },
{ "RunBenchmark": [
"test-wallet",
{ "DumpToFile": "/tmp/submit-txs.txt" },
{ "SpendScript": [
"bench/script/sum1ToN.plutus",
{ "PreExecuteScript": [] },
3,
6
] },
{ "SpendOutput": []},
"walletBasedBenchmark",
4000,
10
] }

]
2 changes: 0 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,3 @@ newWallet n = do
name <- WalletName <$> newIdentifier n
emit $ InitWallet name
return name


15 changes: 8 additions & 7 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ runBenchmarkInEra sourceWallet submitMode (ThreadName threadName) txCount tps er
tracers <- get BenchTracers
networkId <- getUser TNetworkId
fundKey <- getName $ KeyName "pass-partout" -- should be walletkey
targets <- getUser TTargets
(NumberOfInputsPerTx numInputs) <- getUser TNumberOfInputsPerTx
(NumberOfOutputsPerTx numOutputs) <- getUser TNumberOfOutputsPerTx
fee <- getUser TFee
Expand All @@ -268,7 +267,6 @@ runBenchmarkInEra sourceWallet submitMode (ThreadName threadName) txCount tps er
walletRefSrc <- getName sourceWallet
let walletRefDst = walletRefSrc
metadata <- makeMetadata
connectClient <- getConnectClient
let
(Quantity minValue) = lovelaceToQuantity $ fromIntegral numOutputs * minValuePerUTxO + fee

Expand Down Expand Up @@ -302,11 +300,14 @@ runBenchmarkInEra sourceWallet submitMode (ThreadName threadName) txCount tps er
walletScript :: FundSet.Target -> WalletScript era
walletScript = benchmarkWalletScript walletRefSrc txGenerator txCount (const fundSource) inToOut toUTxO fundToStore

coreCall :: AsType era -> ExceptT TxGenError IO AsyncBenchmarkControl
coreCall eraProxy = GeneratorTx.walletBenchmark (btTxSubmit_ tracers) (btN2N_ tracers) connectClient
threadName targets tps LogErrors eraProxy txCount walletScript
case submitMode of
NodeToNode -> do
targets <- getUser TTargets
connectClient <- getConnectClient
let
coreCall :: AsType era -> ExceptT TxGenError IO AsyncBenchmarkControl
coreCall eraProxy = GeneratorTx.walletBenchmark (btTxSubmit_ tracers) (btN2N_ tracers) connectClient
threadName targets tps LogErrors eraProxy txCount walletScript
ret <- liftIO $ runExceptT $ coreCall era
case ret of
Left err -> liftTxGenError err
Expand All @@ -326,7 +327,6 @@ runPlutusBenchmark ::
-> ActionM ()
runPlutusBenchmark sourceWallet submitMode scriptFile scriptBudget scriptData scriptRedeemer (ThreadName threadName) txCount tps = do
tracers <- get BenchTracers
targets <- getUser TTargets
(NumberOfInputsPerTx numInputs) <- getUser TNumberOfInputsPerTx
(NumberOfOutputsPerTx numOutputs) <- getUser TNumberOfOutputsPerTx
networkId <- getUser TNetworkId
Expand All @@ -350,7 +350,6 @@ runPlutusBenchmark sourceWallet submitMode scriptFile scriptBudget scriptData sc
baseFee <- getUser TFee
_minValuePerUTxO <- getUser TMinValuePerUTxO -- TODO:Fix
metadata <- makeMetadata
connectClient <- getConnectClient

let costsPreRun = preExecuteScript protocolParameters script scriptData scriptRedeemer
executionUnits <- case (scriptBudget, costsPreRun) of
Expand Down Expand Up @@ -429,6 +428,8 @@ runPlutusBenchmark sourceWallet submitMode scriptFile scriptBudget scriptData sc

case submitMode of
NodeToNode -> do
targets <- getUser TTargets
connectClient <- getConnectClient
ret <- liftIO $ runExceptT $ GeneratorTx.walletBenchmark (btTxSubmit_ tracers) (btN2N_ tracers) connectClient
threadName targets tps LogErrors AsAlonzoEra txCount walletScript
case ret of
Expand Down
46 changes: 46 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Selftest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Cardano.Benchmarking.Script.Selftest
where
import Data.Dependent.Sum ( (==>) )
import Data.String

import Cardano.Api

import Cardano.Benchmarking.Types
import Cardano.Benchmarking.Script.Setters
import Cardano.Benchmarking.Script.Store
import Cardano.Benchmarking.Script.Types

testScript :: FilePath [Action]
testScript protocolFile =
[ SetProtocolParameters (UseLocalProtocolFile protocolFile)
, Set (TNumberOfInputsPerTx ==> 2)
, Set (TNumberOfOutputsPerTx ==> 2)
, Set (TTxAdditionalSize ==> 39)
, Set (TFee ==> (Lovelace 212345))
, Set (TMinValuePerUTxO ==> (Lovelace 1000000))
, Set (TTTL ==> (SlotNo 1000000))
, Set (TEra ==> (AnyCardanoEra AllegraEra))
, Set (TNetworkId ==> (Testnet (NetworkMagic {unNetworkMagic = 42})))
, InitWallet wallet
, DefineSigningKey key
(TextEnvelope { teType = TextEnvelopeType "GenesisUTxOSigningKey_ed25519"
, teDescription = fromString "Genesis Initial UTxO Signing Key"
, teRawCBOR = "X \vl1~\182\201v(\152\250A\202\157h0\ETX\248h\153\171\SI/m\186\242D\228\NAK\182(&\162"})
, AddFund wallet
(TxIn "900fc5da77a0747da53f7675cbb7d149d46779346dea2f879ab811ccc72a2162" (TxIx 0))
(Lovelace 90000000000000) key
, createChange 2200000000000 10
, createChange 70000000000 300
, createChange 2300000000 9000
, RunBenchmark wallet
output
SpendOutput
(ThreadName "walletBasedBenchmark") 4000 (TPSRate 10.0)
]
where
wallet = WalletName "test-wallet"
key = KeyName "pass-partout"
output = DumpToFile "/tmp/txs.txt"
addr = PayToAddr key
createChange val count
= CreateChange wallet wallet output addr (Lovelace val) count
1 change: 1 addition & 0 deletions bench/tx-generator/tx-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ library
Cardano.Benchmarking.Script.Core
Cardano.Benchmarking.Script.Env
Cardano.Benchmarking.Script.Example
Cardano.Benchmarking.Script.Selftest
Cardano.Benchmarking.Script.Setters
Cardano.Benchmarking.Script.Store
Cardano.Benchmarking.Script.Types
Expand Down

0 comments on commit a47b3ad

Please sign in to comment.