From 4b5054337e774c2f95a82cb4ed4ee57d3de023f0 Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Thu, 10 Oct 2024 11:28:46 +0200 Subject: [PATCH] Use seed-devnet and not assume node keys in bench-e2e This decouples the bench-e2e binary which just produces load and provides statistics more from how the hydra-nodes are run. Now the only assumption is that the 'hydra-cluster/config/credentials/faucet.sk' owns funds on the given network. --- .github/workflows/network-test.yaml | 18 ++------------ hydra-cluster/bench/Main.hs | 4 ++-- hydra-cluster/src/Hydra/Generator.hs | 36 +++++++++++++++------------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/.github/workflows/network-test.yaml b/.github/workflows/network-test.yaml index 4b3c57a52ce..7b616cf242a 100644 --- a/.github/workflows/network-test.yaml +++ b/.github/workflows/network-test.yaml @@ -69,28 +69,14 @@ jobs: cd demo ./prepare-devnet.sh docker compose up -d cardano-node - sleep 5 + sleep 2 # :tear: socket permissions. sudo chmod a+w devnet/node.socket - - HYDRA_SCRIPTS_TX_ID=$(nix run .#hydra-node -- publish-scripts \ - --testnet-magic 42 \ - --node-socket devnet/node.socket \ - --cardano-signing-key devnet/credentials/faucet.sk) - - echo "HYDRA_SCRIPTS_TX_ID=$HYDRA_SCRIPTS_TX_ID" > .env - - nix run .#cardano-cli -- query protocol-parameters \ - --testnet-magic 42 \ - --socket-path devnet/node.socket \ - --out-file /dev/stdout \ - | jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" \ - > devnet/protocol-parameters.json + ./seed-devnet.sh "nix run .#cardano-cli --" "nix run .#hydra-node --" # Specify two docker compose yamls; the second one overrides the # images to use the netem ones specifically docker compose -f docker-compose.yaml -f docker-compose-netem.yaml up -d hydra-node-{1,2,3} - sleep 3 docker ps - name: Build required nix and docker derivations diff --git a/hydra-cluster/bench/Main.hs b/hydra-cluster/bench/Main.hs index b8e4fcb3ba1..a5a4f1b3171 100644 --- a/hydra-cluster/bench/Main.hs +++ b/hydra-cluster/bench/Main.hs @@ -41,9 +41,9 @@ main = do results <- runSingle dataset workDir action summarizeResults outputDirectory [results] DemoOptions{outputDirectory, scalingFactor, timeoutSeconds, networkId, nodeSocket, hydraClients} -> do + (_, faucetSk) <- keysFor Faucet numberOfTxs <- generate $ scale (* scalingFactor) getSize - hydraNodeKeys <- mapM (fmap snd . keysFor) [Alice, Bob, Carol] - dataset <- generateDemoUTxODataset networkId nodeSocket hydraNodeKeys numberOfTxs + dataset <- generateDemoUTxODataset networkId nodeSocket faucetSk (length hydraClients) numberOfTxs workDir <- maybe (createTempDir "bench-demo") checkEmpty outputDirectory results <- runSingle dataset workDir $ diff --git a/hydra-cluster/src/Hydra/Generator.hs b/hydra-cluster/src/Hydra/Generator.hs index ddd1fad8382..0324fb454d3 100644 --- a/hydra-cluster/src/Hydra/Generator.hs +++ b/hydra-cluster/src/Hydra/Generator.hs @@ -9,8 +9,7 @@ import Control.Monad (foldM) import Data.Aeson (object, withObject, (.:), (.=)) import Data.Default (def) import Hydra.Cluster.Faucet (FaucetException (..)) -import Hydra.Cluster.Fixture (Actor (..), availableInitialFunds) -import Hydra.Cluster.Util (keysFor) +import Hydra.Cluster.Fixture (availableInitialFunds) import Hydra.Ledger.Cardano (mkTransferTx) import Test.Hydra.Tx.Gen (genSigningKey) import Test.QuickCheck (choose, generate, sized) @@ -91,9 +90,10 @@ instance FromJSON ClientDataset where defaultProtocolParameters :: PParams LedgerEra defaultProtocolParameters = def --- | Generate 'Dataset' which does not grow the per-client UTXO set over time. --- The sequence of transactions generated consist only of simple payments from --- and to arbitrary keys controlled by the individual clients. +-- | Generate a 'Dataset' which does not grow the per-client UTXO set over time. +-- This version provided faucet key owns funds on the initial funds of the +-- devnet (See 'availableInitialFunds' and 'genesis-shelley.json'). Then for a +-- given number of clients a number of transactions are generated. generateConstantUTxODataset :: -- | Faucet signing key SigningKey PaymentKey -> @@ -118,21 +118,22 @@ generateConstantUTxODataset faucetSk nClients nTxs = do clientDatasets <- forM allPaymentKeys (generateClientDataset networkId fundingTransaction nTxs) pure Dataset{fundingTransaction, hydraNodeKeys, clientDatasets, title = Nothing, description = Nothing} --- | Generates a 'Dataset' from an already running network by quering available --- funds of the well-known 'faucet.sk' and using given hydra-node keys. For each --- hydra-node a 'ClientDataset' with given number of transaction is generated. +-- | Generate a 'Dataset' from an already running network by quering available +-- funds of the well-known 'faucet.sk' and assuming the hydra-nodes we connect +-- to have fuel available. Then for a given number of clients a number of +-- transactions are generated. generateDemoUTxODataset :: NetworkId -> SocketPath -> - -- | Hydra node (fuel) keys. - [SigningKey PaymentKey] -> + -- | Faucet signing key + SigningKey PaymentKey -> + -- | Number of clients. + Int -> -- | Number of transactions Int -> IO Dataset -generateDemoUTxODataset network nodeSocket hydraNodeKeys nTxs = do - let nClients = length hydraNodeKeys +generateDemoUTxODataset network nodeSocket faucetSk nClients nTxs = do -- Query available funds - (faucetVk, faucetSk) <- keysFor Faucet faucetUTxO <- queryUTxOFor network nodeSocket QueryTip faucetVk let (Coin fundsAvailable) = foldMap (selectLovelace . txOutValue) faucetUTxO -- Generate client datasets @@ -140,7 +141,6 @@ generateDemoUTxODataset network nodeSocket hydraNodeKeys nTxs = do clientFunds <- generate $ genClientFunds allPaymentKeys fundsAvailable -- XXX: DRY with 'seedFromFaucet' fundingTransaction <- do - let changeAddress = mkVkAddress network faucetVk let recipientOutputs = flip map clientFunds $ \(vk, ll) -> TxOut @@ -148,7 +148,7 @@ generateDemoUTxODataset network nodeSocket hydraNodeKeys nTxs = do (lovelaceToValue ll) TxOutDatumNone ReferenceScriptNone - buildTransaction network nodeSocket changeAddress faucetUTxO [] recipientOutputs >>= \case + buildTransaction network nodeSocket faucetAddress faucetUTxO [] recipientOutputs >>= \case Left e -> throwIO $ FaucetFailedToBuildTx{reason = e} Right tx -> pure $ signTx faucetSk tx generate $ do @@ -156,11 +156,15 @@ generateDemoUTxODataset network nodeSocket hydraNodeKeys nTxs = do pure Dataset { fundingTransaction - , hydraNodeKeys + , hydraNodeKeys = [] -- Not needed as we won't start nodes , clientDatasets , title = Nothing , description = Nothing } + where + faucetVk = getVerificationKey faucetSk + + faucetAddress = mkVkAddress network faucetVk -- * Helpers