From 4a7377a150d9df2128647d7b7c256be99c13ce27 Mon Sep 17 00:00:00 2001 From: Noon van der Silk Date: Wed, 11 Sep 2024 19:19:53 +0100 Subject: [PATCH 1/2] Hack some env var usage in --- .github/workflows/network-test.yaml | 2 +- demo/export-tx-id-and-pparams.sh | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/network-test.yaml b/.github/workflows/network-test.yaml index 14d6c3b09e5..1fc79321365 100644 --- a/.github/workflows/network-test.yaml +++ b/.github/workflows/network-test.yaml @@ -67,7 +67,7 @@ jobs: sleep 5 # :tear: socket permissions. sudo chown runner:docker devnet/node.socket - ./export-tx-id-and-pparams.sh + DEVNET_DIR=devnet HYDRA_NODE_CMD="nix run .#hydra-node --" ./export-tx-id-and-pparams.sh # 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} diff --git a/demo/export-tx-id-and-pparams.sh b/demo/export-tx-id-and-pparams.sh index 37707ecabbd..7a4df472fad 100755 --- a/demo/export-tx-id-and-pparams.sh +++ b/demo/export-tx-id-and-pparams.sh @@ -6,7 +6,7 @@ SCRIPT_DIR=${SCRIPT_DIR:-$(realpath $(dirname $(realpath $0)))} NETWORK_ID=42 CCLI_CMD= -DEVNET_DIR=/devnet +DEVNET_DIR="${DEVNET_DIR:-/devnet}" if [[ -n ${1} ]]; then echo >&2 "Using provided cardano-cli command: ${1}" $(${1} version > /dev/null) @@ -14,7 +14,7 @@ if [[ -n ${1} ]]; then DEVNET_DIR=${SCRIPT_DIR}/devnet fi -HYDRA_NODE_CMD= +HYDRA_NODE_CMD="${HYDRA_NODE_CMD}" if [[ -n ${2} ]]; then echo >&2 "Using provided hydra-node command: ${2}" ${2} --version > /dev/null @@ -41,6 +41,15 @@ function publishReferenceScripts() { --cardano-signing-key devnet/credentials/faucet.sk } +DOCKER_COMPOSE_CMD= +if [[ ! -x ${CCLI_CMD} ]]; then + if docker compose --version > /dev/null 2>&1; then + DOCKER_COMPOSE_CMD="docker compose" + else + DOCKER_COMPOSE_CMD="docker-compose" + fi +fi + # Invoke cardano-cli in running cardano-node container or via provided cardano-cli function ccli() { ccli_ ${@} --testnet-magic ${NETWORK_ID} From 67ef048ea9a4dacdb13f7a69f627e32e968f3619 Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Thu, 12 Sep 2024 09:40:58 +0200 Subject: [PATCH 2/2] Moves publish/protocol param prep back into seed-devnet The overriding of commands from the network-tests usage site came to a level where simply calling the hydra-node publish-scripts and cli query protocol-parameters seemed easier than maintaining this second shell script. --- .github/workflows/network-test.yaml | 15 +++++- demo/export-tx-id-and-pparams.sh | 80 ----------------------------- demo/seed-devnet.sh | 38 +++++++++++++- flake.nix | 2 +- 4 files changed, 51 insertions(+), 84 deletions(-) delete mode 100755 demo/export-tx-id-and-pparams.sh diff --git a/.github/workflows/network-test.yaml b/.github/workflows/network-test.yaml index 1fc79321365..aa53e8e73a9 100644 --- a/.github/workflows/network-test.yaml +++ b/.github/workflows/network-test.yaml @@ -67,7 +67,20 @@ jobs: sleep 5 # :tear: socket permissions. sudo chown runner:docker devnet/node.socket - DEVNET_DIR=devnet HYDRA_NODE_CMD="nix run .#hydra-node --" ./export-tx-id-and-pparams.sh + + 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 >> .env + + nix run .#cardano-cli query protocol-parameters \ + --socket-path devnet/node.socket \ + --out-file /dev/stdout \ + | jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" \ + > devnet/protocol-parameters.json + # 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} diff --git a/demo/export-tx-id-and-pparams.sh b/demo/export-tx-id-and-pparams.sh deleted file mode 100755 index 7a4df472fad..00000000000 --- a/demo/export-tx-id-and-pparams.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -SCRIPT_DIR=${SCRIPT_DIR:-$(realpath $(dirname $(realpath $0)))} -NETWORK_ID=42 - -CCLI_CMD= -DEVNET_DIR="${DEVNET_DIR:-/devnet}" -if [[ -n ${1} ]]; then - echo >&2 "Using provided cardano-cli command: ${1}" - $(${1} version > /dev/null) - CCLI_CMD=${1} - DEVNET_DIR=${SCRIPT_DIR}/devnet -fi - -HYDRA_NODE_CMD="${HYDRA_NODE_CMD}" -if [[ -n ${2} ]]; then - echo >&2 "Using provided hydra-node command: ${2}" - ${2} --version > /dev/null - HYDRA_NODE_CMD=${2} -fi - -# Invoke hydra-node in a container or via provided executable -function hnode() { - if [[ -n ${HYDRA_NODE_CMD} ]]; then - ${HYDRA_NODE_CMD} ${@} - else - docker run --rm \ - --pull always \ - -v ${SCRIPT_DIR}/devnet:/devnet \ - ghcr.io/cardano-scaling/hydra-node:0.18.1 -- ${@} - fi -} - -function publishReferenceScripts() { - echo >&2 "Publishing reference scripts..." - hnode publish-scripts \ - --testnet-magic ${NETWORK_ID} \ - --node-socket ${DEVNET_DIR}/node.socket \ - --cardano-signing-key devnet/credentials/faucet.sk -} - -DOCKER_COMPOSE_CMD= -if [[ ! -x ${CCLI_CMD} ]]; then - if docker compose --version > /dev/null 2>&1; then - DOCKER_COMPOSE_CMD="docker compose" - else - DOCKER_COMPOSE_CMD="docker-compose" - fi -fi - -# Invoke cardano-cli in running cardano-node container or via provided cardano-cli -function ccli() { - ccli_ ${@} --testnet-magic ${NETWORK_ID} -} -function ccli_() { - if [[ -x ${CCLI_CMD} ]]; then - ${CCLI_CMD} ${@} - else - ${DOCKER_COMPOSE_CMD} exec cardano-node cardano-cli ${@} - fi -} - -function queryPParams() { - echo >&2 "Query Protocol parameters" - if [[ -x ${CCLI_CMD} ]]; then - ccli query protocol-parameters --socket-path ${DEVNET_DIR}/node.socket --out-file /dev/stdout \ - | jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" > devnet/protocol-parameters.json - else - docker exec demo-cardano-node-1 cardano-cli query protocol-parameters --testnet-magic ${NETWORK_ID} --socket-path ${DEVNET_DIR}/node.socket --out-file /dev/stdout \ - | jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" > devnet/protocol-parameters.json - fi - echo >&2 "Saved in protocol-parameters.json" -} - -queryPParams -echo "HYDRA_SCRIPTS_TX_ID=$(publishReferenceScripts)" > .env -echo >&2 "Environment variable stored in '.env'" -echo >&2 -e "\n\t$(cat .env)\n" diff --git a/demo/seed-devnet.sh b/demo/seed-devnet.sh index a7a9c32c024..811813de238 100755 --- a/demo/seed-devnet.sh +++ b/demo/seed-devnet.sh @@ -43,6 +43,18 @@ function ccli_() { fi } +# Invoke hydra-node in a container or via provided executable +function hnode() { + if [[ -n ${HYDRA_NODE_CMD} ]]; then + ${HYDRA_NODE_CMD} ${@} + else + docker run --rm -it \ + --pull always \ + -v ${SCRIPT_DIR}/devnet:/devnet \ + ghcr.io/cardano-scaling/hydra-node:0.18.1 -- ${@} + fi +} + # Retrieve some lovelace from faucet function seedFaucet() { ACTOR=${1} @@ -77,6 +89,26 @@ function seedFaucet() { echo >&2 "Done" } +function publishReferenceScripts() { + echo >&2 "Publishing reference scripts..." + hnode publish-scripts \ + --testnet-magic ${NETWORK_ID} \ + --node-socket ${DEVNET_DIR}/node.socket \ + --cardano-signing-key devnet/credentials/faucet.sk +} + +function queryPParams() { + echo >&2 "Query Protocol parameters" + if [[ -x ${CCLI_CMD} ]]; then + ccli query protocol-parameters --socket-path ${DEVNET_DIR}/node.socket --out-file /dev/stdout \ + | jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" > devnet/protocol-parameters.json + else + docker exec demo-cardano-node-1 cardano-cli query protocol-parameters --testnet-magic ${NETWORK_ID} --socket-path ${DEVNET_DIR}/node.socket --out-file /dev/stdout \ + | jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" > devnet/protocol-parameters.json + fi + echo >&2 "Saved in protocol-parameters.json" +} + echo >&2 "Fueling up hydra nodes of alice, bob and carol..." seedFaucet "alice" 30000000 # 30 Ada to the node seedFaucet "bob" 30000000 # 30 Ada to the node @@ -85,5 +117,7 @@ echo >&2 "Distributing funds to alice, bob and carol..." seedFaucet "alice-funds" 100000000 # 100 Ada to commit seedFaucet "bob-funds" 50000000 # 50 Ada to commit seedFaucet "carol-funds" 25000000 # 25 Ada to commit - -./export-tx-id-and-pparams.sh +queryPParams +echo "HYDRA_SCRIPTS_TX_ID=$(publishReferenceScripts)" > .env +echo >&2 "Environment variable stored in '.env'" +echo >&2 -e "\n\t$(cat .env)\n" diff --git a/flake.nix b/flake.nix index 535558f6611..6f42b7dfbab 100644 --- a/flake.nix +++ b/flake.nix @@ -126,7 +126,7 @@ x.components."${y}") [ "benchmarks" "exes" "sublibs" "tests" ]); in { - legacyPackages = hsPkgs; + legacyPackages = pkgs // hsPkgs; packages = hydraPackages //