Skip to content

Commit

Permalink
Use seed-devnet and not assume node keys in bench-e2e
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ch1bo committed Oct 10, 2024
1 parent 5a4718c commit a48d056
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
18 changes: 2 additions & 16 deletions .github/workflows/network-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down
36 changes: 20 additions & 16 deletions hydra-cluster/src/Hydra/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ->
Expand All @@ -118,49 +118,53 @@ 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
allPaymentKeys <- generate $ replicateM nClients genSigningKey
clientFunds <- generate $ genClientFunds allPaymentKeys fundsAvailable
-- XXX: DRY with 'seedFromFaucet'
fundingTransaction <- do
let changeAddress = mkVkAddress network faucetVk
let recipientOutputs =
flip map clientFunds $ \(vk, ll) ->
TxOut
(mkVkAddress network vk)
(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
clientDatasets <- forM allPaymentKeys (generateClientDataset network fundingTransaction nTxs)
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

Expand Down

0 comments on commit a48d056

Please sign in to comment.