This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-dev.sh
executable file
·100 lines (83 loc) · 2.99 KB
/
run-dev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
#
# run-dev: A quick and dirty script to run a testing setup of local nodes.
set -eu
BASEDIR=$(readlink -f $(dirname $0))
CHAINSPEC=$(mktemp -t chainspec_XXXXXXXX --suffix .toml)
TRUSTED_HASH="${TRUSTED_HASH:-}"
# Generate a genesis timestamp 30 seconds into the future, unless explicity given a different one.
TIMESTAMP=$(python3 -c 'from datetime import datetime, timedelta; print((datetime.utcnow() + timedelta(seconds=20)).isoformat("T") + "Z")')
TIMESTAMP=${GENESIS_TIMESTAMP:-$TIMESTAMP}
echo "GENESIS_TIMESTAMP=${TIMESTAMP}"
# Build the contracts
make build-contracts-rs
# Build the node first, so that `sleep` in the loop has an effect.
cargo build -p casper-node
# Update the chainspec to use the current time as the genesis timestamp.
cp ${BASEDIR}/resources/local/chainspec.toml ${CHAINSPEC}
sed -i "s/^\([[:alnum:]_]*timestamp\) = .*/\1 = \"${TIMESTAMP}\"/" ${CHAINSPEC}
sed -i 's|\.\./\.\.|'"$BASEDIR"'|' ${CHAINSPEC}
sed -i 's|accounts\.csv|'"$BASEDIR"'/resources/local/accounts.csv|' ${CHAINSPEC}
# If no nodes defined, start all.
NODES="${@:-1 2 3 4 5}"
run_node() {
ID=$1
STORAGE_DIR=/tmp/node-${ID}-storage
LOGFILE=/tmp/node-${ID}.log
rm -rf ${STORAGE_DIR}
rm -f ${LOGFILE}
rm -f ${LOGFILE}.stderr
mkdir -p ${STORAGE_DIR}
if [ $1 -ne 1 ]
then
BIND_ADDRESS_ARG=--config-ext=network.bind_address='0.0.0.0:0'
DEPS="--property=After=node-1.service --property=Requires=node-1.service"
else
BIND_ADDRESS_ARG=
DEPS=
fi
if ! [ -z "$TRUSTED_HASH" ]
then
TRUSTED_HASH_ARG=--config-ext=node.trusted_hash="${TRUSTED_HASH}"
else
TRUSTED_HASH_ARG=
fi
echo "$TRUSTED_HASH_ARG"
# We run with a 10 minute timeout, to allow for compilation and loading.
systemd-run \
--user \
--unit node-$ID \
--description "Casper Dev Node ${ID}" \
--collect \
--no-block \
--property=Type=notify \
--property=TimeoutSec=600 \
--property=WorkingDirectory=${BASEDIR} \
$DEPS \
--setenv=RUST_LOG=trace \
--property=StandardOutput=file:${LOGFILE} \
--property=StandardError=file:${LOGFILE}.stderr \
-- \
cargo run -p casper-node \
validator \
resources/local/config.toml \
--config-ext=network.systemd_support=true \
--config-ext=consensus.secret_key_path=secret_keys/node-${ID}.pem \
--config-ext=storage.path=${STORAGE_DIR} \
--config-ext=network.gossip_interval=1000 \
--config-ext=node.chainspec_config_path=${CHAINSPEC} \
${BIND_ADDRESS_ARG} \
${TRUSTED_HASH_ARG}
echo "Started node $ID, logfile: ${LOGFILE}"
# Sleep so that nodes are actually started in sequence.
# Hopefully, fixes some of the race condition issues during startup.
sleep 1;
}
for i in $NODES; do
run_node $i
done;
echo "Test network starting."
echo
echo "To stop all nodes, run"
echo " systemctl --user stop node-\\*"
echo " systemctl --user reset-failed"