From 6f0600d4072febb9e7f2227357f277184269eef6 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Wed, 22 May 2024 10:45:09 +0000 Subject: [PATCH] Remove redundant fee calculation. This does not seem to affect the benchmarks. --- hydra-cluster/bench/Main.hs | 12 +-------- hydra-cluster/src/CardanoClient.hs | 32 ++++-------------------- hydra-cluster/src/Hydra/Generator.hs | 11 +++----- hydra-cluster/test/Test/GeneratorSpec.hs | 3 +-- 4 files changed, 11 insertions(+), 47 deletions(-) diff --git a/hydra-cluster/bench/Main.hs b/hydra-cluster/bench/Main.hs index 329d5afb777..e9a10ac60bc 100644 --- a/hydra-cluster/bench/Main.hs +++ b/hydra-cluster/bench/Main.hs @@ -9,11 +9,6 @@ import Bench.EndToEnd (bench) import Bench.Options (Options (..), benchOptionsParser) import Bench.Summary (Summary (..), markdownReport, textReport) import Data.Aeson (eitherDecodeFileStrict', encodeFile) -import Hydra.Cardano.Api ( - ShelleyBasedEra (..), - ShelleyGenesis (..), - fromLedgerPParams, - ) import Hydra.Generator (Dataset (..), generateConstantUTxODataset) import Options.Applicative (execParser) import System.Directory (createDirectoryIfMissing, doesDirectoryExist) @@ -42,12 +37,7 @@ main = play outputDirectory timeoutSeconds scalingFactor clusterSize startingNodeId workDir = do putStrLn $ "Generating single dataset in work directory: " <> workDir numberOfTxs <- generate $ scale (* scalingFactor) getSize - pparams <- - eitherDecodeFileStrict' ("config" "devnet" "genesis-shelley.json") >>= \case - Left err -> fail $ show err - Right shelleyGenesis -> - pure $ fromLedgerPParams ShelleyBasedEraShelley (sgProtocolParams shelleyGenesis) - dataset <- generateConstantUTxODataset pparams (fromIntegral clusterSize) numberOfTxs + dataset <- generateConstantUTxODataset (fromIntegral clusterSize) numberOfTxs let datasetPath = workDir "dataset.json" saveDataset datasetPath dataset run outputDirectory timeoutSeconds startingNodeId [datasetPath] diff --git a/hydra-cluster/src/CardanoClient.hs b/hydra-cluster/src/CardanoClient.hs index 722fb1caca6..0e4814c3b27 100644 --- a/hydra-cluster/src/CardanoClient.hs +++ b/hydra-cluster/src/CardanoClient.hs @@ -34,28 +34,12 @@ buildScriptAddress script networkId = in makeShelleyAddress networkId (PaymentCredentialByScript hashed) NoStakeAddress -- | Build a "raw" transaction from a bunch of inputs, outputs and fees. -buildRaw :: [TxIn] -> [TxOut CtxTx] -> Coin -> Either TxBodyError TxBody -buildRaw ins outs fee = +buildRaw :: [TxIn] -> [TxOut CtxTx] -> Either TxBodyError TxBody +buildRaw ins outs = createAndValidateTransactionBody $ defaultTxBodyContent & setTxIns (map (,BuildTxWith $ KeyWitness KeyWitnessForSpending) ins) & setTxOuts outs - & setTxFee (TxFeeExplicit fee) - -calculateMinFee :: NetworkId -> TxBody -> Sizes -> ProtocolParameters -> Coin -calculateMinFee networkId body Sizes{inputs, outputs, witnesses} pparams = - let tx = makeSignedTransaction [] body - noByronWitnesses = 0 - in estimateTransactionFee - shelleyBasedEra - networkId - (protocolParamTxFeeFixed pparams) - (protocolParamTxFeePerByte pparams) - tx - inputs - outputs - noByronWitnesses - witnesses data Sizes = Sizes { inputs :: Int @@ -126,7 +110,6 @@ waitForUTxO networkId nodeSocket utxo = mkGenesisTx :: NetworkId -> - ProtocolParameters -> -- | Owner of the 'initialFund'. SigningKey PaymentKey -> -- | Amount of initialFunds @@ -134,8 +117,8 @@ mkGenesisTx :: -- | Recipients and amounts to pay in this transaction. [(VerificationKey PaymentKey, Coin)] -> Tx -mkGenesisTx networkId pparams signingKey initialAmount recipients = - case buildRaw [initialInput] (recipientOutputs <> [changeOutput]) fee of +mkGenesisTx networkId signingKey initialAmount recipients = + case buildRaw [initialInput] (recipientOutputs <> [changeOutput]) of Left err -> error $ "Fail to build genesis transations: " <> show err Right tx -> sign signingKey tx where @@ -144,18 +127,13 @@ mkGenesisTx networkId pparams signingKey initialAmount recipients = networkId (unsafeCastHash $ verificationKeyHash $ getVerificationKey signingKey) - fee = calculateMinFee networkId rawTx Sizes{inputs = 1, outputs = length recipients + 1, witnesses = 1} pparams - rawTx = case buildRaw [initialInput] [] 0 of - Left err -> error $ "Fail to build genesis transactions: " <> show err - Right tx -> tx - totalSent = foldMap snd recipients changeAddr = mkVkAddress networkId (getVerificationKey signingKey) changeOutput = TxOut changeAddr - (lovelaceToValue $ initialAmount - totalSent - fee) + (lovelaceToValue $ initialAmount - totalSent) TxOutDatumNone ReferenceScriptNone diff --git a/hydra-cluster/src/Hydra/Generator.hs b/hydra-cluster/src/Hydra/Generator.hs index deb6372c637..5034d5f1879 100644 --- a/hydra-cluster/src/Hydra/Generator.hs +++ b/hydra-cluster/src/Hydra/Generator.hs @@ -32,7 +32,7 @@ data Dataset = Dataset instance Arbitrary Dataset where arbitrary = sized $ \n -> do sk <- genSigningKey - genDatasetConstantUTxO sk defaultProtocolParameters (n `div` 10) n + genDatasetConstantUTxO sk (n `div` 10) n data ClientKeys = ClientKeys { signingKey :: SigningKey PaymentKey @@ -79,26 +79,24 @@ defaultProtocolParameters = fromLedgerPParams ShelleyBasedEraShelley def -- The sequence of transactions generated consist only of simple payments from -- and to arbitrary keys controlled by the individual clients. generateConstantUTxODataset :: - ProtocolParameters -> -- | Number of clients Int -> -- | Number of transactions Int -> IO Dataset -generateConstantUTxODataset pparams nClients nTxs = do +generateConstantUTxODataset nClients nTxs = do (_, faucetSk) <- keysFor Faucet - generate $ genDatasetConstantUTxO faucetSk pparams nClients nTxs + generate $ genDatasetConstantUTxO faucetSk nClients nTxs genDatasetConstantUTxO :: -- | The faucet signing key SigningKey PaymentKey -> - ProtocolParameters -> -- | Number of clients Int -> -- | Number of transactions Int -> Gen Dataset -genDatasetConstantUTxO faucetSk pparams nClients nTxs = do +genDatasetConstantUTxO faucetSk nClients nTxs = do clientKeys <- replicateM nClients arbitrary -- Prepare funding transaction which will give every client's -- 'externalSigningKey' "some" lovelace. The internal 'signingKey' will get @@ -109,7 +107,6 @@ genDatasetConstantUTxO faucetSk pparams nClients nTxs = do let fundingTransaction = mkGenesisTx networkId - pparams faucetSk (Coin availableInitialFunds) clientFunds diff --git a/hydra-cluster/test/Test/GeneratorSpec.hs b/hydra-cluster/test/Test/GeneratorSpec.hs index 83b71fe5f1f..f6418177816 100644 --- a/hydra-cluster/test/Test/GeneratorSpec.hs +++ b/hydra-cluster/test/Test/GeneratorSpec.hs @@ -13,7 +13,6 @@ import Hydra.Cluster.Util (keysFor) import Hydra.Generator ( ClientDataset (..), Dataset (..), - defaultProtocolParameters, genDatasetConstantUTxO, ) import Hydra.Ledger (ChainSlot (ChainSlot), applyTransactions) @@ -46,7 +45,7 @@ prop_keepsUTxOConstant = let ledgerEnv = newLedgerEnv defaultPParams -- XXX: non-exhaustive pattern match pure $ - forAll (genDatasetConstantUTxO faucetSk defaultProtocolParameters 1 n) $ + forAll (genDatasetConstantUTxO faucetSk 1 n) $ \Dataset{fundingTransaction, clientDatasets = [ClientDataset{txSequence}]} -> let initialUTxO = utxoFromTx fundingTransaction finalUTxO = foldl' (apply defaultGlobals ledgerEnv) initialUTxO txSequence