This repository was archived by the owner on Aug 7, 2023. It is now read-only.
forked from decred/dcrpool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharness.sh
executable file
·314 lines (280 loc) · 8.61 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/sh
# Tmux script that sets up a mining harness.
set -e
SESSION="harness"
NODES_ROOT=~/harness
RPC_USER="user"
RPC_PASS="pass"
WALLET_SEED="b280922d2cffda44648346412c5ec97f429938105003730414f10b01e1402eac"
WALLET_PASS=123
BACKUP_PASS=b@ckUp
NETWORK="simnet"
# NETWORK="testnet3"
# NETWORK="mainnet"
SOLO_POOL=0
MAX_GEN_TIME=20
PAYMENT_METHOD="pplns"
LAST_N_PERIOD=300 # PPLNS range, 5 minutes.
if [ "${NETWORK}" = "simnet" ]; then
POOL_MINING_ADDR="SspUvSyDGSzvPz2NfdZ5LW15uq6rmuGZyhL"
PFEE_ADDR="SsVPfV8yoMu7AvF5fGjxTGmQ57pGkaY6n8z"
CLIENT_ONE_ADDR="SsZckVrqHRBtvhJA5UqLZ3MDXpZHi5mK6uU"
CLIENT_TWO_ADDR="Ssn23a3rJaCUxjqXiVSNwU6FxV45sLkiFpz"
fi
if [ "${NETWORK}" = "mainnet" ]; then
POOL_MINING_ADDR="DsXete8zpkHZXGd4vcxhz4rPqmEqydC9u5E"
PFEE_ADDR="DsXete8zpkHZXGd4vcxhz4rPqmEqydC9u5E"
CLIENT_ADDR="DsXete8zpkHZXGd4vcxhz4rPqmEqydC9u5E"
fi
if [ "${NETWORK}" = "testnet3" ]; then
POOL_MINING_ADDR="TsWP4MhHZn77F6tQprHhFoJHMWifaDdh2Mc"
PFEE_ADDR="TsWP4MhHZn77F6tQprHhFoJHMWifaDdh2Mc"
CLIENT_ADDR="TsWP4MhHZn77F6tQprHhFoJHMWifaDdh2Mc"
fi
if [ -d "${NODES_ROOT}" ]; then
rm -R "${NODES_ROOT}"
fi
DCRD_RPC_CERT="${HOME}/.dcrd/rpc.cert"
DCRD_RPC_KEY="${HOME}/.dcrd/rpc.key"
DCRD_CONF="${HOME}/.dcrd/dcrd.conf"
WALLET_RPC_CERT="${HOME}/.dcrwallet/rpc.cert"
WALLET_RPC_KEY="${HOME}/.dcrwallet/rpc.key"
GUI_DIR="${NODES_ROOT}/gui"
echo "Writing node config files"
mkdir -p "${NODES_ROOT}/master"
mkdir -p "${NODES_ROOT}/wallet"
mkdir -p "${NODES_ROOT}/pool"
mkdir -p "${NODES_ROOT}/gui"
mkdir -p "${NODES_ROOT}/c1"
mkdir -p "${NODES_ROOT}/c2"
cp -r gui/public ${GUI_DIR}/public
cp -r gui/templates ${GUI_DIR}/templates
cat > "${NODES_ROOT}/c1/client.conf" <<EOF
debuglevel=trace
activenet=${NETWORK}
user=m1
address=${CLIENT_ONE_ADDR}
pool=127.0.0.1:5550
EOF
cat > "${NODES_ROOT}/c2/client.conf" <<EOF
debuglevel=trace
activenet=${NETWORK}
user=m2
address=${CLIENT_TWO_ADDR}
pool=127.0.0.1:5550
EOF
if [ "${NETWORK}" = "mainnet" ]; then
cat > "${NODES_ROOT}/dcrctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=${DCRD_RPC_CERT}
rpcserver=127.0.0.1:9109
EOF
cat > "${NODES_ROOT}/pool/pool.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
dcrdrpchost=127.0.0.1:9109
dcrdrpccert=${DCRD_RPC_CERT}
walletgrpchost=127.0.0.1:9111
walletrpccert=${WALLET_RPC_CERT}
debuglevel=trace
maxgentime=${MAX_GEN_TIME}
solopool=${SOLO_POOL}
activenet=${NETWORK}
walletpass=${WALLET_PASS}
poolfeeaddrs=${PFEE_ADDR}
paymentmethod=${PAYMENT_METHOD}
lastnperiod=${LAST_N_PERIOD}
backuppass=${BACKUP_PASS}
guidir=${GUI_DIR}
EOF
fi
if [ "${NETWORK}" = "simnet" ]; then
cat > "${NODES_ROOT}/dcrctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=${DCRD_RPC_CERT}
rpcserver=127.0.0.1:19556
EOF
cat > "${NODES_ROOT}/pool/pool.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
dcrdrpchost=127.0.0.1:19556
dcrdrpccert=${DCRD_RPC_CERT}
walletgrpchost=127.0.0.1:19558
walletrpccert=${WALLET_RPC_CERT}
debuglevel=trace
maxgentime=${MAX_GEN_TIME}
solopool=${SOLO_POOL}
activenet=${NETWORK}
walletpass=${WALLET_PASS}
poolfeeaddrs=${PFEE_ADDR}
paymentmethod=${PAYMENT_METHOD}
lastnperiod=${LAST_N_PERIOD}
backuppass=${BACKUP_PASS}
guidir=${GUI_DIR}
EOF
cat > "${NODES_ROOT}/dcrwctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=${WALLET_RPC_CERT}
rpcserver=127.0.0.1:19557
EOF
cat > "${NODES_ROOT}/wallet/wallet.conf" <<EOF
username=${RPC_USER}
password=${RPC_PASS}
rpccert=${WALLET_RPC_CERT}
rpckey=${WALLET_RPC_KEY}
logdir=./log
appdata=./data
simnet=1
pass=${WALLET_PASS}
debuglevel=debug
EOF
fi
if [ "${NETWORK}" = "testnet3" ]; then
cat > "${NODES_ROOT}/dcrctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=${DCRD_RPC_CERT}
rpcserver=127.0.0.1:19109
EOF
cat > "${NODES_ROOT}/pool/pool.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
dcrdrpchost=127.0.0.1:19109
dcrdrpccert=${DCRD_RPC_CERT}
walletgrpchost=127.0.0.1:19111
walletrpccert=${WALLET_RPC_CERT}
debuglevel=trace
maxgentime=${MAX_GEN_TIME}
solopool=${SOLO_POOL}
activenet=${NETWORK}
walletpass=${WALLET_PASS}
poolfeeaddrs=${PFEE_ADDR}
paymentmethod=${PAYMENT_METHOD}
lastnperiod=${LAST_N_PERIOD}
backuppass=${BACKUP_PASS}
guidir=${GUI_DIR}
EOF
fi
cd ${NODES_ROOT} && tmux new-session -d -s $SESSION
################################################################################
# Setup the master node.
################################################################################
cat > "${NODES_ROOT}/master/ctl" <<EOF
#!/bin/zsh
dcrctl -C ../dcrctl.conf \$*
EOF
chmod +x "${NODES_ROOT}/master/ctl"
tmux rename-window -t $SESSION:0 'master'
tmux send-keys "cd ${NODES_ROOT}/master" C-m
echo "Starting ${NETWORK} dcrd"
if [ "${NETWORK}" = "mainnet" ]; then
tmux send-keys "dcrd -C ${DCRD_CONF} \
--rpccert=${DCRD_RPC_CERT} --rpckey=${DCRD_RPC_KEY} \
--rpcuser=${RPC_USER} --rpcpass=${RPC_PASS} \
--miningaddr=${POOL_MINING_ADDR}" C-m
fi
if [ "${NETWORK}" = "testnet3" ]; then
tmux send-keys "dcrd -C ${DCRD_CONF} \
--rpccert=${DCRD_RPC_CERT} --rpckey=${DCRD_RPC_KEY} \
--rpcuser=${RPC_USER} --rpcpass=${RPC_PASS} \
--miningaddr=${POOL_MINING_ADDR} \
--testnet" C-m
fi
if [ "${NETWORK}" = "simnet" ]; then
tmux send-keys "dcrd -C ${DCRD_CONF} \
--rpccert=${DCRD_RPC_CERT} --rpckey=${DCRD_RPC_KEY} \
--rpcuser=${RPC_USER} --rpcpass=${RPC_PASS} \
--miningaddr=${POOL_MINING_ADDR} \
--simnet" C-m
fi
################################################################################
# Setup the master node's dcrctl (mctl).
################################################################################
cat > "${NODES_ROOT}/master/mine" <<EOF
#!/bin/sh
NUM=1
case \$1 in
''|*[!0-9]*) ;;
*) NUM=\$1 ;;
esac
for i in \$(seq \$NUM) ; do
dcrctl -C ../dcrctl.conf generate 1
sleep 0.5
done
EOF
chmod +x "${NODES_ROOT}/master/mine"
tmux new-window -t $SESSION:1 -n 'mctl'
tmux send-keys "cd ${NODES_ROOT}/master" C-m
if [ "${NETWORK}" = "simnet" ]; then
echo "Waiting for some ${NETWORK} blocks to be mined"
sleep 2
# mine some blocks to start the chain if the active network is simnet.
tmux send-keys "./mine 2" C-m
fi
if [ "${NETWORK}" = "simnet" ]; then
################################################################################
# Setup the pool wallet.
################################################################################
cat > "${NODES_ROOT}/wallet/ctl" <<EOF
#!/bin/sh
dcrctl -C ../dcrwctl.conf --wallet \$*
EOF
chmod +x "${NODES_ROOT}/wallet/ctl"
tmux new-window -t $SESSION:2 -n 'wallet'
tmux send-keys "cd ${NODES_ROOT}/wallet" C-m
tmux send-keys "dcrwallet -C wallet.conf --create" C-m
echo "Creating ${NETWORK} wallet"
sleep 2
tmux send-keys "${WALLET_PASS}" C-m "${WALLET_PASS}" C-m "n" C-m "y" C-m
echo "Setting wallet passphrase"
sleep 1
tmux send-keys "${WALLET_SEED}" C-m C-m
tmux send-keys "dcrwallet -C wallet.conf" C-m
################################################################################
# Setup the pool wallet's dcrctl (wctl).
################################################################################
echo "Waiting for nodes to be synced"
sleep 6
# The consensus daemon must be synced for account generation to
# work as expected.
tmux new-window -t $SESSION:3 -n 'wctl'
tmux send-keys "cd ${NODES_ROOT}/wallet" C-m
tmux send-keys "./ctl createnewaccount pfee" C-m
tmux send-keys "./ctl getnewaddress pfee" C-m
tmux send-keys "./ctl createnewaccount c1" C-m
tmux send-keys "./ctl getnewaddress c1" C-m
tmux send-keys "./ctl createnewaccount c2" C-m
tmux send-keys "./ctl getnewaddress c2" C-m
tmux send-keys "./ctl getnewaddress default" C-m
tmux send-keys "./ctl getbalance"
fi
################################################################################
# Setup dcrpool.
################################################################################
echo "Starting dcrpool"
sleep 4
tmux new-window -t $SESSION:4 -n 'pool'
tmux send-keys "cd ${NODES_ROOT}/pool" C-m
tmux send-keys "dcrpool --configfile pool.conf --homedir=${NODES_ROOT}/pool" C-m
if [ "${NETWORK}" = "simnet" ]; then
################################################################################
# Setup first mining client.
################################################################################
echo "Starting mining client 1"
sleep 1
tmux new-window -t $SESSION:5 -n 'c1'
tmux send-keys "cd ${NODES_ROOT}/c1" C-m
tmux send-keys "miner --configfile=client.conf --homedir=${NODES_ROOT}/c1" C-m
################################################################################
# Setup another mining client.
################################################################################
echo "Starting mining client 2"
sleep 1
tmux new-window -t $SESSION:6 -n 'c2'
tmux send-keys "cd ${NODES_ROOT}/c2" C-m
tmux send-keys "miner --configfile=client.conf --homedir=${NODES_ROOT}/c2" C-m
fi
tmux attach-session -t $SESSION