forked from decred/dcrpool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harness.sh
executable file
·401 lines (355 loc) · 11.7 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/usr/bin/env bash
#
# Copyright (c) 2020 The Decred developers
# Use of this source code is governed by an ISC
# license that can be found in the LICENSE file.
#
# Tmux script that sets up a simnet mining harness.
#
# To use the script simply run `./harness.sh` from the repo root.
#
# The script makes a few assumptions about the system it is running on:
# - tmux is installed
# - dcrd, dcrwallet, dcrctl, miner and dcrpool are available on $PATH
# - /tmp directory exists
set -e
TMUX_SESSION="dcrpool-harness"
HARNESS_ROOT=/tmp/dcrpool-harness
RPC_USER="user"
RPC_PASS="pass"
MASTER_WALLET_SEED="b280922d2cffda44648346412c5ec97f429938105003730414f10b01e1402eac"
VOTING_WALLET_SEED="aabbcaabbcaabbcaabbcaabbcaabbcaabbcaabbcaabbcaabbcaabbcaabbcaabbc"
WALLET_PASS=123
ADMIN_PASS=admin
SOLO_POOL=0
MAX_GEN_TIME=20s
MINER_MAX_PROCS=1
PAYMENT_METHOD="pplns"
LAST_N_PERIOD=5m
GUI_DIR="${HARNESS_ROOT}/gui"
# Enabling profiling uses a lot more ports that might conflict with other Decred
# software. Set to 1 to enable. Leave blank to disable.
ENABLE_PROFILING=
# Using postgres requires the DB specified below to already exist.
USE_POSTGRES=0
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USER=dcrpooluser
POSTGRES_PASS=12345
POSTGRES_DBNAME=dcrpooldb
# CPU_MINING_ADDR is the mining address printed during creation of vwallet.
# Initial block rewards from `generate` are sent here so vwallet can buy tickets.
CPU_MINING_ADDR="SsaJxXSymEGroxAiUY9u1mRq1DDWLxn5WhB"
# POOL_MINING_ADDR is the mining address printed during creation of mwallet.
# Block rewards from pool mining are sent here before being distributed to participants.
POOL_MINING_ADDR="SsXciQNTo3HuV5tX3yy4hXndRWgLMRVC7Ah"
# PFEE_ADDR is from mwallet, pfee account.
# Pool fees are collected here.
PFEE_ADDR="SsYcrXcBfUA1TAYiMhYRTkHupEapH7QWNU6"
# CLIENT_ADDRS are from mwallet, accounts c0, c1, etc.
# Client reward payments are sent to these addresses.
CLIENT_ADDRS=(
"SscVdtfaNS1iCLceaT8Sqwd8hGoia8XDifR"
"SsjUjmw8oGCg63C2MQPygFGZPh2Mbq3iaHM"
"SsbpP2WFUWtnzm4GbiLUTVYWgpGiFDb6M8G"
"SsVDptDDFQrfq7YZoDU3F1i6qNGgRo59FXG"
"SsViw2X9sY74GfXjYm5ieWLZv3vNmmtZGXB"
"SshjubSN3mXx6NTRiGnYZ2p9bU3ZKvMkd3f"
"Ssj1cwFpr7JM1KqW9cePAXM6nXVYz7BHveC"
"SsUgTPPZzQPQLq9MDYQKDXiAJjK4F5aQMjV"
"Ssh37A184b5pequfjwZGSZrPyrAFJETg7c4"
"Ssa9aqaHJYsPLyLRAz47j5uSJDmsSDkaSPU"
"Ssjti72KzbRACaMQcjrXHEUHn374dm4hbn6"
"SsUmjGtniYZxWQVkRUbN2Q65ou8poUMAFm8"
"SsjqAzmWmPPKG7kk9LDs9ZNfi2y9HjkVXU6"
"SsVwnUEBVSne61pqnxEU9WXh3HKeUemjHgU"
"SsZpWMDW6UN8AZkKfW99RWG4imY93Bnu8X2"
"SsqzmU32q7DWU8Pvqrhj7BLRZ4iy6wa6wTB"
"SsWJKGHaEmTjN9AUrTPoLWbumBJGqZnGvz6"
"SsbAAMn7b3Ei8rN4qq1CWZvgfytCHoSBq7c"
"SsnL7yGMaASzaDVb3VVsVutWGzAMT8hHFvR"
"SsjSDtCo8E6ztfib23kZSACFjW8Dfkv3obq"
)
# Number of mining clients to create. Maximum is determined by number of client
# addresses above - currently 20.
NUMBER_OF_CLIENTS=1
if [ -d "${HARNESS_ROOT}" ]; then
echo "Deleting ${HARNESS_ROOT}"
rm -R "${HARNESS_ROOT}"
fi
echo "Writing node config files"
mkdir -p "${HARNESS_ROOT}/master"
mkdir -p "${HARNESS_ROOT}/vnode"
mkdir -p "${HARNESS_ROOT}/mwallet"
mkdir -p "${HARNESS_ROOT}/vwallet"
mkdir -p "${HARNESS_ROOT}/pool"
mkdir -p "${HARNESS_ROOT}/gui"
cp -r internal/gui/assets ${GUI_DIR}/assets
for ((i = 0; i < $NUMBER_OF_CLIENTS; i++)); do
PROFILE_PORT=$(($i + 6061))
mkdir -p "${HARNESS_ROOT}/c$i"
cat > "${HARNESS_ROOT}/c$i/client.conf" <<EOF
debuglevel=trace
activenet=simnet
user=m$i
address=${CLIENT_ADDRS[$i]}
pool=127.0.0.1:5550
maxprocs=$MINER_MAX_PROCS
profile=${ENABLE_PROFILING-$PROFILE_PORT}
EOF
done
cat > "${HARNESS_ROOT}/master/dcrmctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=./rpc.cert
rpcserver=127.0.0.1:19556
EOF
cat > "${HARNESS_ROOT}/vnode/dcrvctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=./rpc.cert
rpcserver=127.0.0.1:19560
EOF
cat > "${HARNESS_ROOT}/pool/pool.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
dcrdrpchost=127.0.0.1:19556
dcrdrpccert=../master/rpc.cert
walletgrpchost=127.0.0.1:19558
walletrpccert=../mwallet/rpc.cert
debuglevel=trace
maxgentime=${MAX_GEN_TIME}
solopool=${SOLO_POOL}
activenet=simnet
walletpass=${WALLET_PASS}
poolfeeaddrs=${PFEE_ADDR}
paymentmethod=${PAYMENT_METHOD}
lastnperiod=${LAST_N_PERIOD}
adminpass=${ADMIN_PASS}
guidir=../gui
designation=${TMUX_SESSION}
profile=${ENABLE_PROFILING-6060}
postgres=${USE_POSTGRES}
postgreshost=${POSTGRES_HOST}
postgresport=${POSTGRES_PORT}
postgresuser=${POSTGRES_USER}
postgrespass=${POSTGRES_PASS}
postgresdbname=${POSTGRES_DBNAME}
EOF
cat > "${HARNESS_ROOT}/mwallet/dcrmwctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=./rpc.cert
rpcserver=127.0.0.1:19557
EOF
cat > "${HARNESS_ROOT}/vwallet/dcrvwctl.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=./rpc.cert
rpcserver=127.0.0.1:19562
EOF
cat > "${HARNESS_ROOT}/mwallet/mwallet.conf" <<EOF
username=${RPC_USER}
password=${RPC_PASS}
cafile=../master/rpc.cert
clientcafile=../pool/wallet.cert
logdir=./logs
appdata=../mwallet
simnet=1
pass=${WALLET_PASS}
accountgaplimit=25
EOF
cat > "${HARNESS_ROOT}/vwallet/vwallet.conf" <<EOF
username=${RPC_USER}
password=${RPC_PASS}
cafile=../vnode/rpc.cert
logdir=./logs
appdata=../vwallet
simnet=1
enablevoting=1
enableticketbuyer=1
ticketbuyer.limit=10
pass=${WALLET_PASS}
rpcconnect=127.0.0.1:19560
grpclisten=127.0.0.1:19561
rpclisten=127.0.0.1:19562
EOF
cd ${HARNESS_ROOT} && tmux new-session -d -s $TMUX_SESSION
################################################################################
# Setup the master node.
################################################################################
cat > "${HARNESS_ROOT}/master/ctl" <<EOF
#!/bin/sh
dcrctl -C dcrmctl.conf \$*
EOF
chmod +x "${HARNESS_ROOT}/master/ctl"
tmux rename-window -t $TMUX_SESSION 'master'
tmux send-keys "cd ${HARNESS_ROOT}/master" C-m
echo "Starting simnet master node"
tmux send-keys "dcrd --appdata=${HARNESS_ROOT}/master \
--nobanning \
--rpcuser=${RPC_USER} --rpcpass=${RPC_PASS} \
--miningaddr=${POOL_MINING_ADDR} \
--txindex --debuglevel=debug \
--simnet" C-m
################################################################################
# Setup the master node's dcrctl (mctl).
################################################################################
cat > "${HARNESS_ROOT}/master/mine" <<EOF
#!/bin/sh
NUM=1
case \$1 in
''|*[!0-9]*) ;;
*) NUM=\$1 ;;
esac
for i in \$(seq \$NUM) ; do
dcrctl -C dcrmctl.conf generate 1
sleep 0.5
done
EOF
chmod +x "${HARNESS_ROOT}/master/mine"
tmux new-window -t $TMUX_SESSION -n 'mctl'
tmux send-keys "cd ${HARNESS_ROOT}/master" C-m
sleep 1
# mine some blocks to start the chain.
tmux send-keys "./mine 2; tmux wait -S mine-two" C-m
tmux wait mine-two
echo "Mined 2 blocks"
tmux send-keys "./ctl livetickets"
################################################################################
# Setup the pool wallet.
################################################################################
cat > "${HARNESS_ROOT}/mwallet/ctl" <<EOF
#!/bin/sh
dcrctl -C dcrmwctl.conf --wallet \$*
EOF
chmod +x "${HARNESS_ROOT}/mwallet/ctl"
tmux new-window -t $TMUX_SESSION -n 'mwallet'
# generate the needed dcrpool key pairs before starting the wallet.
tmux send-keys "cd ${HARNESS_ROOT}/pool" C-m
tmux send-keys "dcrpool --configfile=pool.conf --gencertsonly \
--appdata=${HARNESS_ROOT}/pool" C-m
tmux send-keys "cd ${HARNESS_ROOT}/mwallet" C-m
echo "Creating simnet master wallet"
tmux send-keys "dcrwallet -C mwallet.conf --create <<EOF
y
n
y
${MASTER_WALLET_SEED}
EOF" C-m
sleep 1
tmux send-keys "dcrwallet -C mwallet.conf --debuglevel=info" C-m
# ################################################################################
# # Setup the pool wallet's dcrctl (wctl).
# ################################################################################
sleep 6
# The consensus daemon must be synced for account generation to
# work as expected.
echo "Setting up pool wallet accounts"
tmux new-window -t $TMUX_SESSION -n 'mwctl'
tmux send-keys "cd ${HARNESS_ROOT}/mwallet" C-m
tmux send-keys "./ctl createnewaccount pfee" C-m
tmux send-keys "./ctl getnewaddress pfee" C-m
# Create accounts & addresses for mining clients (only needed for debugging).
for ((i = 0; i < $NUMBER_OF_CLIENTS; i++)); do
tmux send-keys "./ctl createnewaccount c$i" C-m
tmux send-keys "./ctl getnewaddress c$i" C-m
done
tmux send-keys "./ctl getnewaddress default" C-m
tmux send-keys "./ctl getbalance"
################################################################################
# Setup the voting node.
################################################################################
cat > "${HARNESS_ROOT}/vnode/ctl" <<EOF
#!/bin/sh
dcrctl -C dcrvctl.conf \$*
EOF
chmod +x "${HARNESS_ROOT}/vnode/ctl"
tmux new-window -t $TMUX_SESSION -n 'vnode'
tmux send-keys "cd ${HARNESS_ROOT}/vnode" C-m
echo "Starting simnet voting node"
tmux send-keys "dcrd --appdata=${HARNESS_ROOT}/vnode \
--nobanning \
--rpcuser=${RPC_USER} --rpcpass=${RPC_PASS} \
--connect=127.0.0.1:18555 \
--listen=127.0.0.1:19559 --rpclisten=127.0.0.1:19560 \
--miningaddr=${CPU_MINING_ADDR} \
--txindex --debuglevel=info \
--simnet" C-m
################################################################################
# Setup the voting node's dcrctl (vctl).
################################################################################
sleep 3
cat > "${HARNESS_ROOT}/vnode/mine" <<EOF
#!/bin/sh
NUM=1
case \$1 in
''|*[!0-9]*) ;;
*) NUM=\$1 ;;
esac
for i in \$(seq \$NUM) ; do
dcrctl -C dcrvctl.conf generate 1
sleep 0.5
done
EOF
chmod +x "${HARNESS_ROOT}/vnode/mine"
tmux new-window -t $TMUX_SESSION -n 'vctl'
tmux send-keys "cd ${HARNESS_ROOT}/vnode" C-m
# mine to stake enabled height (SEH).
tmux send-keys "./mine 30; tmux wait -S mine" C-m
tmux wait mine
echo "Mined 30 blocks, at stake enabled height (SEH)"
################################################################################
# Setup the voting wallet.
################################################################################
cat > "${HARNESS_ROOT}/vwallet/ctl" <<EOF
#!/bin/sh
dcrctl -C dcrvwctl.conf --wallet \$*
EOF
chmod +x "${HARNESS_ROOT}/vwallet/ctl"
cat > "${HARNESS_ROOT}/vwallet/tickets" <<EOF
#!/bin/sh
NUM=1
case \$1 in
''|*[!0-9]*) ;;
*) NUM=\$1 ;;
esac
./ctl purchaseticket default 999999 1 \`./ctl getnewaddress\` \$NUM
EOF
chmod +x "${HARNESS_ROOT}/vwallet/tickets"
tmux new-window -t $TMUX_SESSION -n 'vwallet'
tmux send-keys "cd ${HARNESS_ROOT}/vwallet" C-m
echo "Creating simnet voting wallet"
tmux send-keys "dcrwallet -C vwallet.conf --create <<EOF
y
n
y
${VOTING_WALLET_SEED}
EOF" C-m
sleep 1
tmux send-keys "dcrwallet -C vwallet.conf --debuglevel=debug" C-m
################################################################################
# Setup the voting wallet's dcrctl (vwctl).
################################################################################
tmux new-window -t $TMUX_SESSION -n 'vwctl'
tmux send-keys "cd ${HARNESS_ROOT}/vwallet" C-m
################################################################################
# Setup dcrpool.
################################################################################
echo "Starting dcrpool"
sleep 5
tmux new-window -t $TMUX_SESSION -n 'pool'
tmux send-keys "cd ${HARNESS_ROOT}/pool" C-m
tmux send-keys "dcrpool --configfile=pool.conf --appdata=${HARNESS_ROOT}/pool \
--purgedb" C-m
################################################################################
# Setup the mining clients.
################################################################################
for ((i = 0; i < $NUMBER_OF_CLIENTS; i++)); do
echo "Starting mining client $i"
sleep 1
tmux new-window -t $TMUX_SESSION -n c$i
tmux send-keys "cd ${HARNESS_ROOT}/c$i" C-m
tmux send-keys "miner --configfile=client.conf --appdata=${HARNESS_ROOT}/c$i" C-m
done
tmux attach-session -t $TMUX_SESSION