forked from decred/dcrstakepool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harness.sh
executable file
·206 lines (177 loc) · 6.34 KB
/
harness.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
# To use this test harness simply run `./harness.sh` from the repo root.
#
# After writing the config files and starting all of the processes, the web
# interface should become available almost immediately. It will take a short
# while for dcrstakepool to become fully functional because the wallets need
# to sync and complete a re-scan before they can be used.
#
# This harness makes a few assumptions
#
# - tmux is installed
# - dcrd, dcrwallet, stakepoold and dcrstakepool are available on $PATH
# - Decred testnet chain is already downloaded and sync'd
# - MySQL is configured at 127.0.0.1:3306
# - Database `stakepool` and user `stakepool` with password `password` exist
# - The following files exist:
# - ${HOME}/.dcrd/rpc.cert
# - ${HOME}/.dcrd/rpc.key
# - ${HOME}/.dcrwallet/rpc.cert
# - ${HOME}/.dcrwallet/rpc.key
# - ${HOME}/.stakepoold/rpc.cert
set -e
SESSION="harness"
NODES_ROOT=~/harness
RPC_USER="user"
RPC_PASS="pass"
NUMBER_OF_BACKENDS=2
DCRD_RPC_CERT="${HOME}/.dcrd/rpc.cert"
DCRD_RPC_KEY="${HOME}/.dcrd/rpc.key"
DCRD_RPC_LISTEN="127.0.0.1:12321"
WALLET_PASS="12345"
WALLET_RPC_CERT="${HOME}/.dcrwallet/rpc.cert"
WALLET_RPC_KEY="${HOME}/.dcrwallet/rpc.key"
STAKEPOOLD_RPC_CERT="${HOME}/.stakepoold/rpc.cert"
MYSQL_HOST="127.0.0.1"
MYSQL_PORT="3306"
MYSQL_DB="stakepool"
MYSQL_USER="stakepool"
MYSQL_PASS="password"
DCRSTAKEPOOL_ADMIN_IPS="127.0.0.1,::1"
DCRSTAKEPOOL_ADMIN_IDS="1,6,46"
DCRSTAKEPOOL_SMTP_FROM="[email protected]"
DCRSTAKEPOOL_SMTP_HOST="localhost:2500"
VOTING_WALLET_SEED="c539a410d13ce16dced00ed54d2644aa79302e9853bb2cd6c7d9520bf0546da27"
VOTING_WALLET_DEFAULT_ACCT_PUB_KEY="tpubVpa7jQBLn1RH1dtbNTQoWaxnzmqedpQX8ZxUoUfjMbNw3CYapSZMikw9ktFvhmb5Xwjpz2Uiin9Zncaw14cHq6oZH69Uws4yCZkZdKip9vZ"
COLD_WALLET_PUB_KEY="tpubVpksTuUYrAgbfwZvU3h9gPLPemf6WCisSrEtYS7gKWqRdPKeqd9t8wPxX99ubvm82N18JeFhhK357q5PuJsVj1qnC7MFVjS37dMjzH7SD34"
if [ -d "${NODES_ROOT}" ]; then
rm -R "${NODES_ROOT}"
fi
tmux new-session -d -s $SESSION
#################################################
# Setup the dcrd node.
#################################################
tmux rename-window -t $SESSION 'dcrd'
echo "Writing config for testnet dcrd node"
mkdir -p "${NODES_ROOT}/dcrd"
cp "${DCRD_RPC_CERT}" "${NODES_ROOT}/dcrd/rpc.cert"
cp "${DCRD_RPC_KEY}" "${NODES_ROOT}/dcrd/rpc.key"
cat > "${NODES_ROOT}/dcrd/dcrd.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=${NODES_ROOT}/dcrd/rpc.cert
rpckey=${NODES_ROOT}/dcrd/rpc.key
rpclisten=${DCRD_RPC_LISTEN}
testnet=true
logdir=${NODES_ROOT}/master/log
EOF
echo "Starting dcrd node"
tmux send-keys "dcrd -C ${NODES_ROOT}/dcrd/dcrd.conf" C-m
sleep 3 # Give dcrd time to start
#################################################
# Setup multiple back-ends.
#################################################
for ((i = 1; i <= $NUMBER_OF_BACKENDS; i++)); do
WALLET_RPC_LISTEN="127.0.0.1:2011${i}"
STAKEPOOLD_RPC_LISTEN="127.0.0.1:3010$i"
ALL_STAKEPOOLDS="${ALL_STAKEPOOLDS:+$ALL_STAKEPOOLDS,}${STAKEPOOLD_RPC_LISTEN}"
ALL_STAKEPOOLD_RPC_CERTS="${ALL_STAKEPOOLD_RPC_CERTS:+$ALL_STAKEPOOLD_RPC_CERTS,}${STAKEPOOLD_RPC_CERT}"
#################################################
# dcrwallet
#################################################
echo ""
echo "Writing config for dcrwallet-${i}"
mkdir -p "${NODES_ROOT}/dcrwallet-${i}"
cp "${WALLET_RPC_CERT}" "${NODES_ROOT}/dcrwallet-${i}/rpc.cert"
cp "${WALLET_RPC_KEY}" "${NODES_ROOT}/dcrwallet-${i}/rpc.key"
cat > "${NODES_ROOT}/dcrwallet-${i}/dcrwallet.conf" <<EOF
username=${RPC_USER}
password=${RPC_PASS}
rpccert=${NODES_ROOT}/dcrwallet-${i}/rpc.cert
rpckey=${NODES_ROOT}/dcrwallet-${i}/rpc.key
logdir=${NODES_ROOT}/dcrwallet-${i}/log
appdata=${NODES_ROOT}/dcrwallet-${i}
testnet=true
pass=${WALLET_PASS}
rpcconnect=${DCRD_RPC_LISTEN}
grpclisten=127.0.0.1:2010${i}
rpclisten=${WALLET_RPC_LISTEN}
stakepoolcoldextkey=${COLD_WALLET_PUB_KEY}:10000
EOF
echo "Starting dcrwallet-${i}"
tmux new-window -t $SESSION -n "dcrwallet-${i}"
tmux send-keys "dcrwallet -C ${NODES_ROOT}/dcrwallet-${i}/dcrwallet.conf --create <<EOF
y
n
y
${VOTING_WALLET_SEED}
EOF" C-m
sleep 2
tmux send-keys "dcrwallet -C ${NODES_ROOT}/dcrwallet-${i}/dcrwallet.conf " C-m
sleep 12 # Give dcrwallet time to start
#################################################
# stakepoold
#################################################
echo ""
echo "Writing config for stakepoold-${i}"
mkdir -p "${NODES_ROOT}/stakepoold-${i}"
cat > "${NODES_ROOT}/stakepoold-${i}/stakepoold.conf" <<EOF
dcrdhost=${DCRD_RPC_LISTEN}
dcrdcert=${DCRD_RPC_CERT}
dcrduser=${RPC_USER}
dcrdpassword=${RPC_PASS}
dbhost=${MYSQL_HOST}
dbport=${MYSQL_PORT}
logdir=${NODES_ROOT}/stakepoold-${i}/log
dbname=${MYSQL_DB}
dbuser=${MYSQL_USER}
dbpassword=${MYSQL_PASS}
coldwalletextpub=${COLD_WALLET_PUB_KEY}
wallethost=${WALLET_RPC_LISTEN}
walletcert=${WALLET_RPC_CERT}
walletuser=${RPC_USER}
walletpassword=${RPC_PASS}
testnet=true
appdata=${NODES_ROOT}/stakepoold-${i}
rpclisten=${STAKEPOOLD_RPC_LISTEN}
debuglevel=debug
EOF
echo "Starting stakepoold-${i}"
tmux new-window -t $SESSION -n "stakepoold-${i}"
tmux send-keys "stakepoold -C ${NODES_ROOT}/stakepoold-${i}/stakepoold.conf " C-m
done
#################################################
# Setup dcrstakepool
#################################################
echo ""
echo "Writing config for dcrstakepool"
mkdir -p "${NODES_ROOT}/dcrstakepool"
cat > "${NODES_ROOT}/dcrstakepool/dcrstakepool.conf" <<EOF
logdir=${NODES_ROOT}/dcrstakepool/log
votingwalletextpub=${VOTING_WALLET_DEFAULT_ACCT_PUB_KEY}
apisecret=not_very_secret_at_all
cookiesecret=not_very_secret_at_all
dbhost=${MYSQL_HOST}
dbport=${MYSQL_PORT}
dbname=${MYSQL_DB}
dbuser=${MYSQL_USER}
dbpassword=${MYSQL_PASS}
coldwalletextpub=${COLD_WALLET_PUB_KEY}
testnet=true
smtphost=${DCRSTAKEPOOL_SMTP_HOST}
smtpfrom=${DCRSTAKEPOOL_SMTP_FROM}
adminips=${DCRSTAKEPOOL_ADMIN_IPS}
adminuserids=${DCRSTAKEPOOL_ADMIN_IDS}
stakepooldhosts=${ALL_STAKEPOOLDS}
stakepooldcerts=${ALL_STAKEPOOLD_RPC_CERTS}
debuglevel=debug
EOF
tmux new-window -t $SESSION -n "dcrstakepool"
echo "Starting dcrstakepool"
sleep 10 # Give stakepoold time to start
tmux send-keys "dcrstakepool -C ${NODES_ROOT}/dcrstakepool/dcrstakepool.conf" C-m
sleep 2
#################################################
# All done - attach to tmux session.
#################################################
tmux attach-session -t $SESSION