forked from casper-network/casper-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-dev-tmux.sh
executable file
·147 lines (117 loc) · 3.36 KB
/
run-dev-tmux.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
tmux_new_window() {
local SESSION=${1}
local ID=${2}
local CMD=${3}
local NAME="${SESSION}-${ID}"
tmux new-window -t "${SESSION}:${ID}" -n "${NAME}"
tmux send-keys -t "${NAME}" "${CMD}" C-m
}
build_system_contracts() {
local CMD=(
"make -s"
"build-contracts-rs"
"CARGO_FLAGS=--quiet"
)
echo "Building system contracts..."
${CMD[*]}
}
build_node() {
local CMD=(
"cargo build"
"--quiet"
"--manifest-path=node/Cargo.toml"
)
echo "Building node..."
${CMD[*]}
}
generate_timestamp() {
local DELAY=${1}
local SCRIPT=(
"from datetime import datetime, timedelta;"
"print((datetime.utcnow() + timedelta(seconds=${DELAY})).isoformat('T') + 'Z')"
)
python3 -c "${SCRIPT[*]}"
}
generate_chainspec() {
local BASEDIR=${1}
local TIMESTAMP=${2}
local SOURCE="${BASEDIR}/resources/local/chainspec.toml.in"
local TARGET="${BASEDIR}/resources/local/chainspec.toml"
export BASEDIR
export TIMESTAMP
echo "Generating chainspec..."
envsubst < ${SOURCE} > ${TARGET}
}
run_node() {
local EXECUTABLE=${1}
local SESSION=${2}
local ID=${3}
local CONFIG_DIR=${4}
local DATA_DIR=${5}
local CONFIG_TOML_PATH="${CONFIG_DIR}/config.toml"
local SECRET_KEY_PATH="${CONFIG_DIR}/secret_keys/node-${ID}.pem"
local STORAGE_DIR="${DATA_DIR}/node-${ID}-storage"
local CMD=(
"${EXECUTABLE}"
"validator"
"${CONFIG_TOML_PATH}"
"-C consensus.secret_key_path=${SECRET_KEY_PATH}"
"-C storage.path=${STORAGE_DIR}"
"-C rpc_server.address='0.0.0.0:50101'"
)
if [[ ${ID} != 1 ]]; then
CMD+=("-C network.bind_address='0.0.0.0:0'")
CMD+=("-C rpc_server.address='0.0.0.0:0'")
CMD+=("-C rest_server.address='0.0.0.0:0'")
CMD+=("-C event_stream_server.address='0.0.0.0:0'")
fi
CMD+=("1> >(tee ${DATA_DIR}/node-${ID}.log) 2> >(tee ${DATA_DIR}/node-${ID}.log.stderr)")
mkdir -p "${STORAGE_DIR}"
tmux_new_window "${SESSION}" "${ID}" "${CMD[*]}"
echo "Booting node ${ID}..."
}
check_for_bootstrap () {
local BOOTSTRAP_PORT=34553
while ! (: </dev/tcp/0.0.0.0/${BOOTSTRAP_PORT}) &>/dev/null; do
sleep 1
done
}
main() {
local DELAY=${1:-40}
local SESSION="${SESSION:-local}"
local TMPDIR="${TMPDIR:-$(mktemp -d)}"
local BASEDIR="$(readlink -f $(dirname ${0}))"
local EXECUTABLE="${BASEDIR}/target/debug/casper-node"
local CONFIG_DIR="${BASEDIR}/resources/local"
local TIMESTAMP="$(generate_timestamp ${DELAY})"
local RUST_LOG="${RUST_LOG:-debug}"
export TMPDIR
export RUST_LOG
build_system_contracts
build_node
generate_chainspec ${BASEDIR} ${TIMESTAMP}
tmux new-session -d -s ${SESSION}
local ID=1
run_node ${EXECUTABLE} ${SESSION} ${ID} ${CONFIG_DIR} ${TMPDIR}
for ID in {2..5}; do
check_for_bootstrap
run_node ${EXECUTABLE} ${SESSION} ${ID} ${CONFIG_DIR} ${TMPDIR}
done
echo
echo "DELAY : ${DELAY}"
echo "TMPDIR : ${TMPDIR}"
echo "TIMESTAMP : ${TIMESTAMP}"
echo "RUST_LOG : ${RUST_LOG}"
echo
echo "To view: "
echo " tmux attach -t ${SESSION}"
echo
echo "To kill: "
echo " tmux kill-session -t ${SESSION}"
echo
}
main ${@}