Skip to content

Commit 3d78ef2

Browse files
authored
dev: Add simnet config and tmux script for reorg testing
Add simnet config, tmux script for launching parallel nodes and wallets, and a script to trigger a reorg.
1 parent 50512d6 commit 3d78ef2

File tree

7 files changed

+380
-2
lines changed

7 files changed

+380
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ debug
88
*.cert
99
*.key
1010
dcrdata
11-
dcrdata*.conf
11+
dcrdata.conf
1212
/vendor/
1313
*.orig
1414
*.db
@@ -32,6 +32,7 @@ ffldb_stake*/
3232
testnet/
3333
.DS_Store
3434
testdata/
35+
dev/datadir/
3536
\.project
3637
test-data-repo
3738
dcrdata-testdata-gitlfs
@@ -53,5 +54,4 @@ testutil/dbconfig/test.data
5354
pubsub/democlient/democlient
5455
dcrrates/rateserver/rateserver
5556
dcrrates/rateserver/logs/
56-
*.sql
5757
*.gob

dev/dcrdata-simnet.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Application Options]
2+
3+
simnet=1
4+
5+
; alpha node
6+
dcrdserv=127.0.0.1:19101
7+
; beta node
8+
;dcrdserv=127.0.0.1:19201
9+
10+
dcrduser=USER
11+
dcrdpass=PASS
12+
13+
nodaemontls=1
14+
15+
apilisten=0.0.0.0:9777
16+
17+
; Set the logging verbosity level
18+
debuglevel=DATD=debug,SQLT=debug,MEMP=debug,RPCC=info,JAPI=debug,PSQL=debug,IAPI=debug,NTFN=trace,SKDB=debug,BLKD=debug,EXPR=debug
19+
20+
; PostgreSQL database config
21+
pgdbname=dcrdata_simnet
22+
pguser=dcrdata_simnet_stooge
23+
pgpass=pass
24+
25+
; Connect via TCP
26+
;pghost=127.0.0.1:5432
27+
; Connect via UNIX domain socket
28+
pghost=/run/postgresql
29+

dev/do-reorg.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SESSION="dcrd-parallel-nodes"
6+
7+
# mine some on both nodes
8+
tmux send-key -t dcrd-parallel-nodes:0.0 "./mine-both" C-m
9+
10+
sleep 6
11+
12+
# disconnect b from a
13+
tmux send-key -t dcrd-parallel-nodes:2.1 "./ctl addnode 127.0.0.1:19100 remove" C-m
14+
15+
sleep 2
16+
17+
# mine a block on node a
18+
tmux send-key -t dcrd-parallel-nodes:1.1 "./mine" C-m
19+
20+
# mine 3 blocks on node b
21+
tmux send-key -t dcrd-parallel-nodes:2.1 "./mine" C-m
22+
tmux send-key -t dcrd-parallel-nodes:2.1 "./mine" C-m
23+
tmux send-key -t dcrd-parallel-nodes:2.1 "./mine" C-m
24+
25+
sleep 4
26+
27+
# reconnect b to a
28+
tmux send-key -t dcrd-parallel-nodes:2.1 "./ctl addnode 127.0.0.1:19100 add" C-m
29+
30+
sleep 2
31+
32+
grep REORG ~/dcrdsimnet/alpha/log/simnet/dcrd.log

dev/parallel-nodes.tmux

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
#!/bin/sh
2+
#
3+
# Script to setup parallel dcrd nodes with separate wallets.
4+
# Useful for testing reorgs by disconnecting nodes, mining individually, then
5+
# reconnecting them.
6+
#
7+
# alpha <------> beta
8+
# listen 19100 19200
9+
# rpclisten 19101 <. .> 19201
10+
# w-alpha | | w-beta
11+
# rpclisten 19102 19202
12+
#
13+
# For simplicity, node "beta" is configured to connect to node "alpha" via
14+
# --connect on the command line, so that you can easily disconnect the nodes
15+
# by stopping beta, removing the --connect, then restarting it.
16+
17+
set -e
18+
19+
SESSION="dcrd-parallel-nodes"
20+
NODES_ROOT=~/dcrdsimnet
21+
RPCUSER="USER"
22+
RPCPASS="PASS"
23+
WALLET01_SEED="1111111111111111111111111111111111111111111111111111111111111111"
24+
WALLET02_SEED="2222222222222222222222222222222222222222222222222222222222222222"
25+
WALLET01_MININGADDR="Ssmn12w4CTF2j6B1jaLxEyKXVeMFkPJmDBs"
26+
WALLET02_MININGADDR="Ssc9exyQoHX3octYgu7SVWYTJQBP7PqJd31"
27+
# WALLET01_MININGADDR="Ssoaqgx4ecmHX54LqrUXgqi6miUFxP9iUvc"
28+
# WALLET02_MININGADDR="SsgkhRgr9JdonELE7MjK8qUkwSPsrTnWcE6"
29+
30+
if [ -d "${NODES_ROOT}" ] ; then
31+
rm -R "${NODES_ROOT}"
32+
fi
33+
34+
mkdir -p "${NODES_ROOT}/"{alpha,beta,w-alpha,w-beta}
35+
36+
# Config Files
37+
38+
cat > "${NODES_ROOT}/dcrd.conf" <<EOF
39+
rpcuser=${RPCUSER}
40+
rpcpass=${RPCPASS}
41+
simnet=1
42+
logdir=./log
43+
datadir=./data
44+
notls=1
45+
txindex=1
46+
debuglevel=TXMP=TRACE,MINR=TRACE,CHAN=TRACE
47+
EOF
48+
49+
cat > "${NODES_ROOT}/dcrctl.conf" <<EOF
50+
rpcuser=${RPCUSER}
51+
rpcpass=${RPCPASS}
52+
notls=1
53+
simnet=1
54+
EOF
55+
56+
cat > "${NODES_ROOT}/wallet.conf" <<EOF
57+
username=${RPCUSER}
58+
password=${RPCPASS}
59+
noclienttls=1
60+
simnet=1
61+
logdir=./log
62+
appdata=./data
63+
pass=123
64+
enablevoting=1
65+
enableticketbuyer=1
66+
nogrpc=1
67+
EOF
68+
69+
70+
cp ${NODES_ROOT}/dcrd.conf ${NODES_ROOT}/alpha
71+
cat >> ${NODES_ROOT}/alpha/dcrd.conf <<EOF
72+
listen=127.0.0.1:19100
73+
rpclisten=127.0.0.1:19101
74+
miningaddr=${WALLET01_MININGADDR}
75+
EOF
76+
77+
cp ${NODES_ROOT}/dcrctl.conf ${NODES_ROOT}/alpha
78+
cat >> ${NODES_ROOT}/alpha/dcrctl.conf <<EOF
79+
rpcserver=127.0.0.1:19101
80+
EOF
81+
82+
cp ${NODES_ROOT}/dcrctl.conf ${NODES_ROOT}/w-alpha
83+
cat >> ${NODES_ROOT}/w-alpha/dcrctl.conf <<EOF
84+
walletrpcserver=127.0.0.1:19102
85+
EOF
86+
87+
88+
cp ${NODES_ROOT}/dcrd.conf ${NODES_ROOT}/beta
89+
cat >> ${NODES_ROOT}/beta/dcrd.conf <<EOF
90+
listen=127.0.0.1:19200
91+
rpclisten=127.0.0.1:19201
92+
miningaddr=${WALLET02_MININGADDR}
93+
EOF
94+
95+
cp ${NODES_ROOT}/dcrctl.conf ${NODES_ROOT}/beta
96+
cat >> ${NODES_ROOT}/beta/dcrctl.conf <<EOF
97+
rpcserver=127.0.0.1:19201
98+
EOF
99+
100+
cp ${NODES_ROOT}/dcrctl.conf ${NODES_ROOT}/w-beta
101+
cat >> ${NODES_ROOT}/w-beta/dcrctl.conf <<EOF
102+
walletrpcserver=127.0.0.1:19202
103+
EOF
104+
105+
# Node Scripts
106+
107+
cat > "${NODES_ROOT}/alpha/ctl" <<EOF
108+
#!/bin/sh
109+
dcrctl -C ./dcrctl.conf \$*
110+
EOF
111+
chmod +x "${NODES_ROOT}/alpha/ctl"
112+
113+
cat > "${NODES_ROOT}/alpha/mine" <<EOF
114+
#!/bin/sh
115+
NUM=1
116+
case \$1 in
117+
''|*[!0-9]*) ;;
118+
*) NUM=\$1 ;;
119+
esac
120+
121+
for i in \$(seq \$NUM) ; do
122+
dcrctl -C ./dcrctl.conf generate 1
123+
sleep 0.3
124+
done
125+
EOF
126+
chmod +x "${NODES_ROOT}/alpha/mine"
127+
128+
# script to mine one block on each node
129+
cat > "${NODES_ROOT}/mine-both" <<EOF
130+
#!/bin/sh
131+
NUM=1
132+
case \$1 in
133+
''|*[!0-9]*) ;;
134+
*) NUM=\$1 ;;
135+
esac
136+
137+
for i in \$(seq \$NUM) ; do
138+
cd ${NODES_ROOT}/alpha && ./mine
139+
cd ${NODES_ROOT}/beta && ./mine
140+
done
141+
EOF
142+
chmod +x "${NODES_ROOT}/mine-both"
143+
144+
cp ${NODES_ROOT}/alpha/ctl ${NODES_ROOT}/beta/
145+
cp ${NODES_ROOT}/alpha/mine ${NODES_ROOT}/beta/
146+
147+
148+
# Wallet Scripts
149+
150+
cat > "${NODES_ROOT}/w-alpha/ctl" <<EOF
151+
#!/bin/sh
152+
dcrctl -C ./dcrctl.conf --wallet -c ./data/rpc.cert \$*
153+
EOF
154+
chmod +x "${NODES_ROOT}/w-alpha/ctl"
155+
156+
cat > "${NODES_ROOT}/w-alpha/tickets" <<EOF
157+
#!/bin/sh
158+
NUM=1
159+
case \$1 in
160+
''|*[!0-9]*) ;;
161+
*) NUM=\$1 ;;
162+
esac
163+
164+
./ctl purchaseticket default 999999 1 \`./ctl getnewaddress\` \$NUM
165+
EOF
166+
chmod +x "${NODES_ROOT}/w-alpha/tickets"
167+
168+
cat > "${NODES_ROOT}/w-alpha/xfer" <<EOF
169+
#!/bin/sh
170+
./ctl sendtoaddress \`./ctl getnewaddress\` 0.1
171+
EOF
172+
chmod +x "${NODES_ROOT}/w-alpha/xfer"
173+
174+
cp ${NODES_ROOT}/w-alpha/ctl ${NODES_ROOT}/w-beta
175+
cp ${NODES_ROOT}/w-alpha/tickets ${NODES_ROOT}/w-beta
176+
cp ${NODES_ROOT}/w-alpha/xfer ${NODES_ROOT}/w-beta
177+
178+
179+
cd ${NODES_ROOT} && tmux -2 new-session -d -s $SESSION
180+
181+
tmux rename-window -t $SESSION:0 'prompt'
182+
183+
184+
# Alpha Node
185+
186+
tmux new-window -t $SESSION:1 -n 'alpha'
187+
tmux split-window -v
188+
tmux select-pane -t 0
189+
tmux send-keys "cd alpha" C-m
190+
tmux send-keys "dcrd -C ./dcrd.conf" C-m
191+
tmux select-pane -t 1
192+
tmux send-keys "cd alpha" C-m
193+
#sleep 3
194+
#tmux send-keys "./ctl generate 16" C-m
195+
196+
197+
# Beta Node
198+
199+
tmux new-window -t $SESSION:2 -n 'beta'
200+
tmux split-window -v
201+
tmux select-pane -t 0
202+
tmux send-keys "cd beta" C-m
203+
tmux send-keys "dcrd -C ./dcrd.conf --connect 127.0.0.1:19100" C-m
204+
tmux select-pane -t 1
205+
tmux send-keys "cd beta" C-m
206+
#sleep 3
207+
#tmux send-keys "./ctl generate 16" C-m
208+
209+
sleep 3
210+
tmux send-keys -t $SESSION:0 "./mine-both 16" C-m
211+
212+
# Wallets
213+
214+
tmux new-window -t $SESSION:3 -n 'wallets'
215+
tmux split-window -h
216+
tmux split-window -v
217+
tmux select-pane -t 0
218+
tmux split-window -v
219+
220+
221+
tmux select-pane -t 0
222+
tmux send-keys "cd w-alpha" C-m
223+
tmux send-keys "dcrwallet -C ../wallet.conf --create" C-m
224+
sleep 2
225+
tmux send-keys "123" C-m "123" C-m "n" C-m "y" C-m
226+
sleep 1
227+
tmux send-keys "${WALLET01_SEED}" C-m C-m
228+
tmux send-keys "dcrwallet -C ../wallet.conf --rpcconnect 127.0.0.1:19101 \
229+
--rpclisten 127.0.0.1:19102" C-m
230+
tmux select-pane -t 2
231+
tmux send-keys "cd w-alpha" C-m
232+
233+
tmux select-pane -t 1
234+
tmux send-keys "cd w-beta" C-m
235+
tmux send-keys "dcrwallet -C ../wallet.conf --create" C-m
236+
sleep 2
237+
tmux send-keys "123" C-m "123" C-m "n" C-m "y" C-m
238+
sleep 1
239+
tmux send-keys "${WALLET02_SEED}" C-m C-m
240+
tmux send-keys "dcrwallet -C ../wallet.conf --rpcconnect 127.0.0.1:19201 \
241+
--rpclisten 127.0.0.1:19202" C-m
242+
tmux select-pane -t 3
243+
tmux send-keys "cd w-beta" C-m
244+
245+
echo Attach to simnet nodes/wallets with \"tmux a -t $SESSION\".
246+
# tmux attach-session -t $SESSION

dev/simnet.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- This resets the dcrdata_simnet database.
2+
3+
DROP DATABASE IF EXISTS dcrdata_simnet;
4+
DROP USER IF exists dcrdata_simnet_stooge;
5+
6+
CREATE USER dcrdata_simnet_stooge PASSWORD 'pass';
7+
CREATE DATABASE dcrdata_simnet OWNER dcrdata_simnet_stooge;

dev/start-simnet.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
# Run this script from the "dev" folder to:
4+
# 1. Start parallel simnet nodes and wallets
5+
# 2. Initialize a postgresql database for this simnet session.
6+
# 3. Start dcrdata in simnet mode connected to the alpha node.
7+
#
8+
# When done testing, stop dcrdata with CTRL+C or SIGING, then use stop-simnet.sh
9+
# to stop all simnet nodes and wallets.
10+
11+
set -e
12+
13+
echo "Starting simnet nodes and wallets..."
14+
rm -rf ~/dcrdsimnet
15+
./parallel-nodes.tmux
16+
# tmux a -t dcrd-parallel-nodes
17+
18+
echo "Use stop-simnet.sh to stop nodes and wallets."
19+
20+
sleep 5
21+
22+
echo "Preparing PostgreSQL for simnet dcrdata..."
23+
PSQL="sudo -u postgres -H psql"
24+
$PSQL < ./simnet.sql
25+
26+
rm -rf ~/.dcrdata/data/simnet
27+
rm -rf datadir
28+
pushd .. > /dev/null
29+
./dcrdata -C ./dev/dcrdata-simnet.conf --datadir ./dev/datadir -g
30+
popd > /dev/null
31+
32+
echo " ***
33+
Don't forget to run ./stop-simnet.sh!
34+
***"

0 commit comments

Comments
 (0)