diff --git a/.gitignore b/.gitignore index b741472..3bbe750 100644 --- a/.gitignore +++ b/.gitignore @@ -311,3 +311,8 @@ TSWLatexianTemp* # glossaries *.glstex + +# demo files +scripts/demo/src/ +scripts/demo/bin/ +scripts/demo/testnet/ diff --git a/scripts/demo/.envrc b/scripts/demo/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/scripts/demo/.envrc @@ -0,0 +1 @@ +use flake diff --git a/scripts/demo/create_env.sh b/scripts/demo/create_env.sh new file mode 100755 index 0000000..eb72445 --- /dev/null +++ b/scripts/demo/create_env.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +CARDANO_CLI=$(realpath bin/cardano-cli) +CARDANO_NODE=$(realpath bin/cardano-node) +CARDANO_TESTNET=$(realpath bin/cardano-testnet) +STATIC_ENV=$(realpath env) +NUM_POOL_NODES=3 + +export CARDANO_CLI +export CARDANO_NODE + +rm -rf "$STATIC_ENV" +$CARDANO_TESTNET \ + create-env \ + --output "$STATIC_ENV" \ + --num-pool-nodes="$NUM_POOL_NODES" diff --git a/scripts/demo/env/alonzo-genesis.json b/scripts/demo/env/alonzo-genesis.json new file mode 100644 index 0000000..0a6d69f --- /dev/null +++ b/scripts/demo/env/alonzo-genesis.json @@ -0,0 +1,375 @@ +{ + "collateralPercentage": 150, + "costModels": { + "PlutusV1": [ + 205665, + 812, + 1, + 1, + 1000, + 571, + 0, + 1, + 1000, + 24177, + 4, + 1, + 1000, + 32, + 117366, + 10475, + 4, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 100, + 100, + 23000, + 100, + 19537, + 32, + 175354, + 32, + 46417, + 4, + 221973, + 511, + 0, + 1, + 89141, + 32, + 497525, + 14068, + 4, + 2, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1000, + 28662, + 4, + 2, + 245000, + 216773, + 62, + 1, + 1060367, + 12586, + 1, + 208512, + 421, + 1, + 187000, + 1000, + 52998, + 1, + 80436, + 32, + 43249, + 32, + 1000, + 32, + 80556, + 1, + 57667, + 4, + 1000, + 10, + 197145, + 156, + 1, + 197145, + 156, + 1, + 204924, + 473, + 1, + 208896, + 511, + 1, + 52467, + 32, + 64832, + 32, + 65493, + 32, + 22558, + 32, + 16563, + 32, + 76511, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 69522, + 11687, + 0, + 1, + 60091, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 196500, + 453240, + 220, + 0, + 1, + 1, + 806990, + 30482, + 4, + 1927926, + 82523, + 4, + 265318, + 0, + 4, + 0, + 85931, + 32, + 205665, + 812, + 1, + 1, + 41182, + 32, + 212342, + 32, + 31220, + 32, + 32696, + 32, + 43357, + 32, + 32247, + 32, + 38314, + 32, + 57996947, + 18975, + 10 + ], + "PlutusV2": [ + 205665, + 812, + 1, + 1, + 1000, + 571, + 0, + 1, + 1000, + 24177, + 4, + 1, + 1000, + 32, + 117366, + 10475, + 4, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 23000, + 100, + 100, + 100, + 23000, + 100, + 19537, + 32, + 175354, + 32, + 46417, + 4, + 221973, + 511, + 0, + 1, + 89141, + 32, + 497525, + 14068, + 4, + 2, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1000, + 28662, + 4, + 2, + 245000, + 216773, + 62, + 1, + 1060367, + 12586, + 1, + 208512, + 421, + 1, + 187000, + 1000, + 52998, + 1, + 80436, + 32, + 43249, + 32, + 1000, + 32, + 80556, + 1, + 57667, + 4, + 1000, + 10, + 197145, + 156, + 1, + 197145, + 156, + 1, + 204924, + 473, + 1, + 208896, + 511, + 1, + 52467, + 32, + 64832, + 32, + 65493, + 32, + 22558, + 32, + 16563, + 32, + 76511, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 69522, + 11687, + 0, + 1, + 60091, + 32, + 196500, + 453240, + 220, + 0, + 1, + 1, + 196500, + 453240, + 220, + 0, + 1, + 1, + 1159724, + 392670, + 0, + 2, + 806990, + 30482, + 4, + 1927926, + 82523, + 4, + 265318, + 0, + 4, + 0, + 85931, + 32, + 205665, + 812, + 1, + 1, + 41182, + 32, + 212342, + 32, + 31220, + 32, + 32696, + 32, + 43357, + 32, + 32247, + 32, + 38314, + 32, + 35892428, + 10, + 9462713, + 1021, + 10, + 38887044, + 32947, + 10, + 1292075, + 24469, + 74, + 0, + 1, + 936157, + 49601, + 237, + 0, + 1 + ] + }, + "executionPrices": { + "priceMemory": 5.77e-2, + "priceSteps": 7.21e-5 + }, + "lovelacePerUTxOWord": 34482, + "maxBlockExUnits": { + "memory": 62000000, + "steps": 20000000000 + }, + "maxCollateralInputs": 3, + "maxTxExUnits": { + "memory": 140000000, + "steps": 10000000000 + }, + "maxValueSize": 5000 +} \ No newline at end of file diff --git a/scripts/demo/env/byron-gen-command/genesis-keys.000.key b/scripts/demo/env/byron-gen-command/genesis-keys.000.key new file mode 100644 index 0000000..8f34ea8 --- /dev/null +++ b/scripts/demo/env/byron-gen-command/genesis-keys.000.key @@ -0,0 +1,2 @@ +X€x’×2(ˆÀ2¾£âéÁfM˜·õ B×S*õãiÏ3\c1¶’|ÝO±héøÕ-œÝ "$TESTNET_ENV/logs/node${node}/out.log" +} + +# Start the toxiproxy server +start_toxiproxy_server() { + echo "Starting toxiproxy server ..." + toxiproxy-server &> "$TESTNET_ENV/logs/toxiproxy.log" +} + +# Create a proxy port for a given node with some latency +create_toxiproxy() { + local node="$1" + local in_port="$2" + local out_port="$3" + local latency="$4" + echo "Creating toxiproxy ${in_port}->${out_port} ..." + toxiproxy-cli create \ + --listen "127.0.0.1:${out_port}" \ + --upstream "127.0.0.1:${in_port}" \ + "node${node}_proxy" + toxiproxy-cli toxic add \ + --type latency \ + --attribute latency="$latency" \ + "node${node}_proxy" + +} + +# "Gracefully" stop all pool nodes on script termination +cleanup() { + echo "" + echo "Stopping pool nodes ..." + pkill -f "$CARDANO_NODE" || true + echo "Stopping toxiproxy server ..." + pkill -f toxiproxy-server || true +} + +# --------------------------------- + +# Export variables needed to enable Peras+CertConjuring in cardano-node +export ENABLE_PERAS=1 +export PERAS_CERT_CONJURING=1 +export PERAS_CERT_CONJURING_STATIC_FILES="$STATIC_FILES" + +# Recreate the testnet environment +rm -rf "$TESTNET_ENV" +cp -r "$STATIC_ENV" "$TESTNET_ENV" +mkdir -p "$TESTNET_ENV/logs" + +# Update the "startup timestamp" field in a couple of places +ISO_8601_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +jq --arg ts "$ISO_8601_TS" \ + '. + { "systemStart": $ts }' \ + "$STATIC_ENV/shelley-genesis.json" > \ + "$TESTNET_ENV/shelley-genesis.json" + +EPOCH_TS=$(date -u +"%s") +jq --argjson ts "$EPOCH_TS" \ + '. + { "startTime": $ts }' \ + "$STATIC_ENV/byron-genesis.json" > \ + "$TESTNET_ENV/byron-genesis.json" + +# Launch some auxiliary processes +wait_for_http_server 1 & +start_toxiproxy_server & + +# Launch 3 pool nodes behind toxiproxy instances with some latency to induce +# network partitions to create forks +NODE_LATENCY_MS=250 +for i in $(seq 1 3); do + in_port=$((3000 + i)) + out_port=$((4000 + i)) + create_toxiproxy "$i" "$in_port" "$out_port" "$NODE_LATENCY_MS" + start_pool_node "$i" "$in_port" & +done + +# Setup a trap waiting for Ctrl+C to stop everything +echo "Press Ctrl+C to stop the testnet ..." +trap cleanup SIGINT +while true; do + sleep 1 +done diff --git a/scripts/demo/setup.sh b/scripts/demo/setup.sh new file mode 100755 index 0000000..46815f5 --- /dev/null +++ b/scripts/demo/setup.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +set -e +set -x + +mkdir -p bin src + +# Clone needed repositories +if [[ ! -d src/cardano-base ]]; then + git clone https://github.com/IntersectMBO/cardano-base src/cardano-base +fi + +if [[ ! -d src/ouroboros-network ]]; then + git clone https://github.com/IntersectMBO/ouroboros-network src/ouroboros-network +fi + +if [[ ! -d src/ouroboros-consensus ]]; then + git clone https://github.com/IntersectMBO/ouroboros-consensus src/ouroboros-consensus +fi + +if [[ ! -d src/cardano-node ]]; then + git clone https://github.com/IntersectMBO/cardano-node src/cardano-node +fi + +# Checkout specific commits/branches +git -C src/cardano-base checkout 5c18017546dc1032e76a985c45fe7c3df2a76616 +git -C src/ouroboros-network checkout peras/10.5 +git -C src/ouroboros-consensus checkout peras/10.5-with-cert-conjuring + +# Build the needed binaries inside cardano-node +pushd src/cardano-node + +# cardano-cli @master +if [[ ! -f ../../bin/cardano-cli ]] || [[ -n "$REBUILD_CARDANO_CLI" ]]; then + git checkout master + nix develop -c cabal clean + nix develop -c cabal build cardano-cli + cp "$(nix develop -c cabal list-bin cardano-cli)" ../../bin/cardano-cli +fi + +# cardano-testnet @cardano-testnet-fix-numpools-test +if [[ ! -f ../../bin/cardano-testnet ]] || [[ -n "$REBUILD_CARDANO_TESTNET" ]]; then + git checkout cardano-testnet-fix-numpools-test + nix develop -c cabal clean + nix develop -c cabal build cardano-testnet + cp "$(nix develop -c cabal list-bin cardano-testnet)" ../../bin/cardano-testnet +fi + +# cardano-node @peras/10.5 +if [[ ! -f ../../bin/cardano-node ]] || [[ -n "$REBUILD_CARDANO_NODE" ]]; then + git checkout peras/10.5 + cat > cabal.project.local <