Skip to content

Commit a8a9f7e

Browse files
committed
Start cardano-nodes by hand add toxiproxy ports
1 parent 8a8dae2 commit a8a9f7e

File tree

9 files changed

+246
-51
lines changed

9 files changed

+246
-51
lines changed

scripts/demo/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

scripts/demo/env/configuration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"ConwayGenesisFile": "conway-genesis.json",
55
"EnableLogMetrics": false,
66
"EnableLogging": true,
7-
"EnableP2P": false,
7+
"EnableP2P": true,
88
"ExperimentalHardForksEnabled": true,
99
"ExperimentalProtocolsEnabled": true,
1010
"LastKnownBlockVersion-Alt": 0,
@@ -95,4 +95,4 @@
9595
"scName": "stdout"
9696
}
9797
]
98-
}
98+
}
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
{
2-
"Producers": [
3-
"node_2",
4-
"node_3"
5-
]
6-
}
2+
"bootstrapPeers": [],
3+
"localRoots": [
4+
{
5+
"accessPoints": [
6+
{
7+
"address": "127.0.0.1",
8+
"port": 4002
9+
},
10+
{
11+
"address": "127.0.0.1",
12+
"port": 4003
13+
}
14+
],
15+
"advertise": false,
16+
"trustable": true,
17+
"valency": 2
18+
}
19+
],
20+
"publicRoots": []
21+
}
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
{
2-
"Producers": [
3-
"node_1",
4-
"node_3"
5-
]
6-
}
2+
"bootstrapPeers": [],
3+
"localRoots": [
4+
{
5+
"accessPoints": [
6+
{
7+
"address": "127.0.0.1",
8+
"port": 4001
9+
},
10+
{
11+
"address": "127.0.0.1",
12+
"port": 4003
13+
}
14+
],
15+
"advertise": false,
16+
"trustable": true,
17+
"valency": 2
18+
}
19+
],
20+
"publicRoots": []
21+
}
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
{
2-
"Producers": [
3-
"node_1",
4-
"node_2"
5-
]
6-
}
2+
"bootstrapPeers": [],
3+
"localRoots": [
4+
{
5+
"accessPoints": [
6+
{
7+
"address": "127.0.0.1",
8+
"port": 4001
9+
},
10+
{
11+
"address": "127.0.0.1",
12+
"port": 4002
13+
}
14+
],
15+
"advertise": false,
16+
"trustable": true,
17+
"valency": 2
18+
}
19+
],
20+
"publicRoots": []
21+
}

scripts/demo/env/shelley-genesis.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"tau": 0.1
5353
},
5454
"securityParam": 5,
55-
"slotLength": 0.1,
55+
"slotLength": 0.2,
5656
"slotsPerKESPeriod": 129600,
5757
"staking": {
5858
"pools": {
@@ -113,4 +113,4 @@
113113
},
114114
"systemStart": "2025-09-23T17:29:43Z",
115115
"updateQuorum": 2
116-
}
116+
}

scripts/demo/flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/demo/flake.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
description = "Peras Demo Flake";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
};
7+
outputs =
8+
{
9+
self,
10+
nixpkgs,
11+
flake-utils,
12+
}:
13+
flake-utils.lib.eachDefaultSystem (
14+
system:
15+
let
16+
pkgs = import nixpkgs { inherit system; };
17+
in
18+
{
19+
devShells.default = pkgs.mkShell {
20+
buildInputs = with pkgs; [
21+
git
22+
jq
23+
toxiproxy
24+
];
25+
};
26+
}
27+
);
28+
}

scripts/demo/launch.sh

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,15 @@
22

33
set -e
44

5-
CARDANO_CLI=$(realpath bin/cardano-cli)
65
CARDANO_NODE=$(realpath bin/cardano-node)
7-
CARDANO_TESTNET=$(realpath bin/cardano-testnet)
86
STATIC_ENV=$(realpath env)
97
TESTNET_ENV=$(realpath testnet)
108
STATIC_FILES=$(realpath src/ouroboros-consensus/static)
119

12-
# Recreate the testnet environment
13-
rm -rf "$TESTNET_ENV"
14-
cp -r "$STATIC_ENV" "$TESTNET_ENV"
15-
16-
# Update the "startup timestamp" field in a couple of places
17-
ISO_8601_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
18-
jq --arg ts "$ISO_8601_TS" \
19-
'. + { "systemStart": $ts }' \
20-
"$STATIC_ENV/shelley-genesis.json" > \
21-
"$TESTNET_ENV/shelley-genesis.json"
22-
23-
EPOCH_TS=$(date -u +"%s")
24-
jq --argjson ts "$EPOCH_TS" \
25-
'. + { "startTime": $ts }' \
26-
"$STATIC_ENV/byron-genesis.json" > \
27-
"$TESTNET_ENV/byron-genesis.json"
28-
2910
# Setup a watcher for the server to announce itself and open the web UI
30-
wait_for_server() {
11+
wait_for_http_server() {
3112
local node_to_watch="$1"
32-
local logfile="$TESTNET_ENV/logs/$node_to_watch/stdout.log"
13+
local logfile="$TESTNET_ENV/logs/node${node_to_watch}/out.log"
3314
local pattern="Serving files at: (\S+)"
3415
local match;
3516

@@ -41,29 +22,108 @@ wait_for_server() {
4122
while read -r line; do
4223
if [[ "$line" =~ $pattern ]]; then
4324
match="${BASH_REMATCH[1]}"
44-
echo "==============================="
45-
echo "Detected server URL: $match"
46-
echo "Opening web UI in the default browser ..."
47-
echo "==============================="
48-
sleep 3
25+
echo "Found server for node${node_to_watch} running at $match, launching web UI ..."
26+
sleep 1
4927
xdg-open "$match"
5028
break
5129
fi
5230
done < <(tail -n +1 -F "$logfile")
5331
}
5432

55-
wait_for_server "node1" &
33+
# Start a pool node in a given port
34+
start_pool_node() {
35+
local node="$1"
36+
local port="$2"
5637

57-
# Export variables needed by cardano-testnet
58-
export CARDANO_CLI
59-
export CARDANO_NODE
38+
mkdir -p "$TESTNET_ENV/logs/node${node}"
39+
echo "Starting pool node${node} on port ${port} ..."
40+
$CARDANO_NODE run \
41+
--config "$TESTNET_ENV/configuration.yaml" \
42+
--topology "$TESTNET_ENV/node-data/node${node}/topology.json" \
43+
--database-path "$TESTNET_ENV/node-data/node${node}/db" \
44+
--shelley-kes-key "$TESTNET_ENV/pools-keys/pool${node}/kes.skey" \
45+
--shelley-vrf-key "$TESTNET_ENV/pools-keys/pool${node}/vrf.skey" \
46+
--shelley-operational-certificate "$TESTNET_ENV/pools-keys/pool${node}/opcert.cert" \
47+
--byron-delegation-certificate "$TESTNET_ENV/pools-keys/pool${node}/byron-delegation.cert" \
48+
--byron-signing-key "$TESTNET_ENV/pools-keys/pool${node}/byron-delegate.key" \
49+
--socket-path "$TESTNET_ENV/node-data/node${node}/sock" \
50+
--host-addr 127.0.0.1 \
51+
--port "$port" \
52+
&> "$TESTNET_ENV/logs/node${node}/out.log"
53+
}
54+
55+
# Start the toxiproxy server
56+
start_toxiproxy_server() {
57+
echo "Starting toxiproxy server ..."
58+
toxiproxy-server &> "$TESTNET_ENV/logs/toxiproxy.log"
59+
}
60+
61+
# Create a proxy port for a given node with some latency
62+
create_toxiproxy() {
63+
local node="$1"
64+
local in_port="$2"
65+
local out_port="$3"
66+
echo "Creating toxiproxy ${in_port}->${out_port} ..."
67+
toxiproxy-cli create \
68+
--listen "127.0.0.1:${out_port}" \
69+
--upstream "127.0.0.1:${in_port}" \
70+
"node${node}_proxy"
71+
toxiproxy-cli toxic add \
72+
--type latency \
73+
--attribute latency=250 \
74+
"node${node}_proxy"
75+
76+
}
77+
78+
# "Gracefully" stop all pool nodes on script termination
79+
cleanup() {
80+
echo ""
81+
echo "Stopping pool nodes ..."
82+
pkill -f "$CARDANO_NODE" || true
83+
echo "Stopping toxiproxy server ..."
84+
pkill -f toxiproxy-server || true
85+
}
86+
87+
# ---------------------------------
6088

6189
# Export variables needed to enable Peras+CertConjuring in cardano-node
6290
export ENABLE_PERAS=1
6391
export PERAS_CERT_CONJURING=1
6492
export PERAS_CERT_CONJURING_STATIC_FILES="$STATIC_FILES"
6593

66-
# Launch the testnet
67-
$CARDANO_TESTNET cardano --node-env "$TESTNET_ENV"
94+
# Recreate the testnet environment
95+
rm -rf "$TESTNET_ENV"
96+
cp -r "$STATIC_ENV" "$TESTNET_ENV"
97+
mkdir -p "$TESTNET_ENV/logs"
98+
99+
# Update the "startup timestamp" field in a couple of places
100+
ISO_8601_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
101+
jq --arg ts "$ISO_8601_TS" \
102+
'. + { "systemStart": $ts }' \
103+
"$STATIC_ENV/shelley-genesis.json" > \
104+
"$TESTNET_ENV/shelley-genesis.json"
105+
106+
EPOCH_TS=$(date -u +"%s")
107+
jq --argjson ts "$EPOCH_TS" \
108+
'. + { "startTime": $ts }' \
109+
"$STATIC_ENV/byron-genesis.json" > \
110+
"$TESTNET_ENV/byron-genesis.json"
111+
112+
# Launch some auxiliary processes
113+
wait_for_http_server 1 &
114+
start_toxiproxy_server &
68115

116+
# Launch 3 pool nodes behind toxiproxy instances
117+
for i in 1 2 3; do
118+
in_port=$((3000 + i))
119+
out_port=$((4000 + i))
120+
create_toxiproxy "$i" "$in_port" "$out_port"
121+
start_pool_node "$i" "$in_port" &
122+
done
69123

124+
# Setup a trap wait for Ctrl+C to stop everything
125+
echo "Press Ctrl+C to stop the testnet ..."
126+
trap cleanup SIGINT
127+
while true; do
128+
sleep 1
129+
done

0 commit comments

Comments
 (0)