Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tx-generator: towards stand-alone mode #3425

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions bench/script/test-stand-alone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{ "SetProtocolParameters": { "UseLocalProtocolFile": "/tmp/t2.json" } },
{ "Set": { "SNumberOfInputsPerTx": 2 } },
{ "Set": { "SNumberOfOutputsPerTx": 2 } },
{ "Set": { "STxAdditionalSize": 39 } },
{ "Set": { "SFee": 212345 } },
{ "Set": { "SMinValuePerUTxO": 1000000 } },
{ "Set": { "STTL": 1000000 } },
{ "Set": { "SEra": "Allegra" } },
{ "Set": { "SNetworkId": "Mainnet" } },
{ "ReadSigningKey": [ "pass-partout", "run/current/genesis/utxo-keys/utxo1.skey" ] },
{ "CreateChange": [
{ "DumpToFile": "/tmp/script-txs.txt" },
{ "PayToAddr": [] },
149200212345,
1
] },
{ "CreateChange": [
{ "DumpToFile": "/tmp/script-txs.txt" },
{ "PayToCollateral": [] },
149200000000,
1
] },
{ "CreateChange": [
{ "DumpToFile": "/tmp/split-txs.txt" },
{ "PayToAddr": [] },
2200000000000,
10
] },
{ "CreateChange": [
{ "DumpToFile": "/tmp/split-txs.txt" },
{ "PayToAddr": [] },
70000000000,
300
] },
{ "CreateChange": [
{ "DumpToFile": "/tmp/script-txs.txt" },
{ "PayToScript": [ "bench/script/sum1ToN.plutus", 3 ] },
2300000000,
9000
] },
{ "RunBenchmark": [
{ "DumpToFile": "/tmp/submit-txs.txt" },
{ "SpendScript": [
"bench/script/sum1ToN.plutus",
{ "PreExecuteScript": [] },
3,
6
] },
"walletBasedBenchmark",
4000,
10
] }
]
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ runBenchmarkScriptWith ::
runBenchmarkScriptWith iocp logConfigFile socketFile script = do
(loggingLayer, ptcl) <- startProtocol logConfigFile
let tracers :: BenchTracers
tracers = createTracers loggingLayer
tracers = createLoggingLayerTracers loggingLayer
dslSet :: MonoDSLs
dslSet = mangleLocalProtocolDefinition ptcl iocp socketFile tracers
res <- firstExceptT BenchmarkRunnerError $ script (tracers, dslSet)
Expand Down
8 changes: 7 additions & 1 deletion bench/tx-generator/src/Cardano/Benchmarking/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import Control.Monad.IO.Class
import Ouroboros.Network.NodeToClient (IOManager)
import Cardano.Node.Configuration.Logging (shutdownLoggingLayer)

import Cardano.Benchmarking.Tracer (createDebugTracers)
import Cardano.Benchmarking.Script.Action
import Cardano.Benchmarking.Script.Aeson (parseScriptFileAeson)
import Cardano.Benchmarking.Script.AesonLegacy (parseScriptFileLegacy)
import Cardano.Benchmarking.Script.Core (initGlobalWallet)
import Cardano.Benchmarking.Script.Env
import Cardano.Benchmarking.Script.Store
import Cardano.Benchmarking.Script.Types

type Script = [Action]

runScript :: Script -> IOManager -> IO (Either Error ())
runScript script iom = runActionM (forM_ script action) iom >>= \case
runScript script iom = runActionM execScript iom >>= \case
(Right a , s , ()) -> do
cleanup s shutDownLogging
threadDelay 10_000_000
Expand All @@ -38,6 +40,10 @@ runScript script iom = runActionM (forM_ script action) iom >>= \case
return $ Left err
where
cleanup s a = void $ runActionMEnv s a iom
execScript = do
initGlobalWallet
set BenchTracers createDebugTracers
forM_ script action

shutDownLogging :: ActionM ()
shutDownLogging = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Cardano.Benchmarking.Script.Types
action :: Action -> ActionM ()
action a = case a of
Set (key :=> (Identity val)) -> set (User key) val
SetProtocolParameters p -> setProtocolParameters p
StartProtocol filePath -> startProtocol filePath
ReadSigningKey name filePath -> readSigningKey name filePath
SecureGenesisFund fundName fundKey genesisKey -> secureGenesisFund fundName fundKey genesisKey
Expand Down
28 changes: 27 additions & 1 deletion bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import Data.Aeson.Types
import Data.Aeson.Encode.Pretty
import qualified Data.Attoparsec.ByteString as Atto

import Cardano.Api (AnyCardanoEra(..), CardanoEra(..), ScriptData, ScriptDataJsonSchema(..), scriptDataFromJson, scriptDataToJson)
import qualified Ouroboros.Network.Magic as Ouroboros (NetworkMagic(..))
import Cardano.Api (AnyCardanoEra(..), CardanoEra(..), ScriptData, ScriptDataJsonSchema(..), NetworkId(..)
, scriptDataFromJson, scriptDataToJson)
import Cardano.Api.Shelley (ProtocolParameters)
import Cardano.CLI.Types (SigningKeyFile(..))

import Cardano.Benchmarking.Script.Setters
Expand Down Expand Up @@ -55,6 +58,12 @@ instance FromJSON AnyCardanoEra where
jsonOptionsUnTaggedSum :: Options
jsonOptionsUnTaggedSum = defaultOptions { sumEncoding = ObjectWithSingleField }

instance ToJSON ProtocolParametersSource where
toJSON = genericToJSON jsonOptionsUnTaggedSum
toEncoding = genericToEncoding jsonOptionsUnTaggedSum
instance FromJSON ProtocolParametersSource where
parseJSON = genericParseJSON jsonOptionsUnTaggedSum

-- Orphan instance used in the tx-generator
instance ToJSON ScriptData where
toJSON = scriptDataToJson ScriptDataJsonNoSchema
Expand Down Expand Up @@ -140,6 +149,9 @@ parseJSONFile parser filePath = do
parseScriptFileAeson :: FilePath -> IO [Action]
parseScriptFileAeson = parseJSONFile fromJSON

readProtocolParametersFile :: FilePath -> IO ProtocolParameters
readProtocolParametersFile = parseJSONFile fromJSON

instance ToJSON KeyName where toJSON (KeyName a) = toJSON a
instance ToJSON FundName where toJSON (FundName a) = toJSON a
instance ToJSON FundListName where toJSON (FundListName a) = toJSON a
Expand All @@ -153,3 +165,17 @@ instance FromJSON FundListName where parseJSON a = FundListName <$> parseJSON
instance FromJSON TxListName where parseJSON a = TxListName <$> parseJSON a
instance FromJSON ThreadName where parseJSON a = ThreadName <$> parseJSON a
instance FromJSON SigningKeyFile where parseJSON a = SigningKeyFile <$> parseJSON a

instance ToJSON NetworkId where
toJSON Mainnet = "Mainnet"
toJSON (Testnet (Ouroboros.NetworkMagic t)) = object ["Testnet" .= t]

instance FromJSON NetworkId where
parseJSON j = case j of
(String "Mainnet") -> return Mainnet
(Object v) -> v .:? "Testnet" >>= \case
Nothing -> failed
Just w -> return $ Testnet $ Ouroboros.NetworkMagic w
_invalid -> failed
where
failed = fail $ "Parsing of NetworkId failed: " <> show j
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ actionToJSON a = case a of
CancelBenchmark (ThreadName t) -> singleton "cancelBenchmark" t
WaitForEra era -> singleton "waitForEra" era
Reserved l -> singleton "reserved" l
other -> error $ "Action not supported in legacy JSON mode : " ++ show other
where
singleton k v = object [ k .= v ]

Expand Down
Loading