2
2
3
3
set -e
4
4
5
- CARDANO_CLI=$( realpath bin/cardano-cli)
6
5
CARDANO_NODE=$( realpath bin/cardano-node)
7
- CARDANO_TESTNET=$( realpath bin/cardano-testnet)
8
6
STATIC_ENV=$( realpath env)
9
7
TESTNET_ENV=$( realpath testnet)
10
8
STATIC_FILES=$( realpath src/ouroboros-consensus/static)
11
9
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
-
29
10
# Setup a watcher for the server to announce itself and open the web UI
30
- wait_for_server () {
11
+ wait_for_http_server () {
31
12
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"
33
14
local pattern=" Serving files at: (\S+)"
34
15
local match;
35
16
@@ -41,29 +22,108 @@ wait_for_server() {
41
22
while read -r line; do
42
23
if [[ " $line " =~ $pattern ]]; then
43
24
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
49
27
xdg-open " $match "
50
28
break
51
29
fi
52
30
done < <( tail -n +1 -F " $logfile " )
53
31
}
54
32
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 "
56
37
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
+ # ---------------------------------
60
88
61
89
# Export variables needed to enable Peras+CertConjuring in cardano-node
62
90
export ENABLE_PERAS=1
63
91
export PERAS_CERT_CONJURING=1
64
92
export PERAS_CERT_CONJURING_STATIC_FILES=" $STATIC_FILES "
65
93
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 &
68
115
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
69
123
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