github.com/decred/dcrlnd@v0.7.6/contrib/dcrlnd-tmux-3node.sh (about) 1 #!/bin/sh 2 # 3 # Copyright (c) 2021 The Decred developers 4 # Use of this source code is governed by an ISC 5 # license that can be found in the LICENSE file. 6 # 7 # Minimal dcrln setup for a three-node simnet network. 8 # 9 # This sets up a decred miner + voting wallet to keep the network going, then 10 # prepares three dcrlnd nodes by importing hard-coded seeds, opening and 11 # confirming bidirectional channels between them. 12 # 13 # The final layout of the dcrln network after this runs is (modulo fees): 14 # 15 # dcrlnd0 < 0.05 --- 0.05 > dcrlnd1 < 0.03 --- 0.07 > dcrlnd2 16 17 set -e 18 set -x 19 20 NODES_ROOT=~/dcrlndsimnetnodes 21 DCRLND_BIN="dcrlnd" 22 SESSION="dcrlnd-3node" 23 RPCUSER="USER" 24 RPCPASS="PASS" 25 WALLET_SEED="1111111111111111111111111111111111111111111111111111111111111111" 26 WALLET_MINING_ADDR="Ssoaqgx4ecmHX54LqrUXgqi6miUFxP9iUvc" # NOTE: This must be changed if the seed is changed. 27 WALLET_XFER_ADDR="Ssoaqgx4ecmHX54LqrUXgqi6miUFxP9iUvc" # same as above 28 WALLET_CREATE_CONFIG="y 29 n 30 y 31 ${WALLET_SEED} 32 " 33 NODE0_SEED="abandon replace vendor festival curious load vague empty noise level sock brain noodle nominee concert resemble rice pilot gentle beyond carry material birth town" 34 NODE1_SEED="able field segment load sister riot carbon acoustic undo history zebra multiply blouse raise radar radio gloom slight vote warrior water stable hub village" 35 NODE2_SEED="able found student horse wife gas catch jelly blast grab wage strategy toward can empty junior pond medal cave wise argue typical gossip decline" 36 NODE0_PUBID="032b8c752fdcd8da420e6fd5d2317cfc42f51a0928d34511fce7b6ba42e1e353b8" 37 NODE1_PUBID="03bb9246b8eaacde90c3b9e7a0539b0b70cde514ec0d2571c68063ac15edac5534" 38 NODE2_PUBID="029398ddb14e4b3cb92fc64d61fcaaa2f3b590951b0b05ba1ecc04a7504d333213" 39 40 alias tmxsend="tmux send-keys" 41 42 if [ -d "${NODES_ROOT}" ] ; then 43 rm -R "${NODES_ROOT}" 44 fi 45 46 mkdir -p "${NODES_ROOT}/"{dcrd,wallet,dcrlnd0,dcrlnd1,dcrlnd2} 47 48 cat > "${NODES_ROOT}/dcrd.conf" <<EOF 49 rpcuser = ${RPCUSER} 50 rpcpass = ${RPCPASS} 51 simnet = 1 52 logdir = ./log 53 datadir = ./data 54 txindex = 1 55 listen = :19555 56 rpclisten = :19556 57 miningaddr = ${WALLET_MINING_ADDR} 58 ; debuglevel=TXMP=TRACE,MINR=TRACE,CHAN=TRACE 59 EOF 60 61 cat > "${NODES_ROOT}/dcrctl.conf" <<EOF 62 rpcuser = ${RPCUSER} 63 rpcpass = ${RPCPASS} 64 simnet = 1 65 EOF 66 67 cat > "${NODES_ROOT}/wallet.conf" <<EOF 68 username = ${RPCUSER} 69 password = ${RPCPASS} 70 simnet = 1 71 logdir = ./log 72 appdata = ./data 73 pass = 123 74 enablevoting = 1 75 enableticketbuyer = 1 76 rpcconnect = 127.0.0.1:19556 77 ticketbuyer.limit = 5 78 debuglevel = debug 79 EOF 80 81 cat > "${NODES_ROOT}/dcrdata.conf" <<EOF 82 dcrdserv = localhost:19556 83 dcrduser = ${RPCUSER} 84 dcrdpass = ${RPCPASS} 85 appdata = ${NODES_ROOT}/dcrdata 86 simnet = 1 87 EOF 88 89 cat > "${NODES_ROOT}/dcrlnd0.conf" <<EOF 90 [Application Options] 91 92 datadir = ${NODES_ROOT}/dcrlnd0 93 logdir = ${NODES_ROOT}/dcrlnd0/logs 94 tlscertpath = ${NODES_ROOT}/dcrlnd0/tls.cert 95 tlskeypath = ${NODES_ROOT}/dcrlnd0/tls.key 96 rpclisten = 127.0.0.1:20000 97 restlisten = 127.0.0.1:20001 98 listen = 127.0.0.1:20002 99 maxlogfiles = 100 100 101 102 debuglevel = debug 103 104 node = "dcrd" 105 simnet = 1 106 107 [dcrd] 108 dcrd.rpchost = localhost:19556 109 dcrd.rpcuser = ${RPCUSER} 110 dcrd.rpcpass = ${RPCPASS} 111 EOF 112 113 cat > "${NODES_ROOT}/dcrlnd1.conf" <<EOF 114 [Application Options] 115 116 datadir = ${NODES_ROOT}/dcrlnd1 117 logdir = ${NODES_ROOT}/dcrlnd1/logs 118 tlscertpath = ${NODES_ROOT}/dcrlnd1/tls.cert 119 tlskeypath = ${NODES_ROOT}/dcrlnd1/tls.key 120 rpclisten = 127.0.0.1:20100 121 restlisten = 127.0.0.1:20101 122 listen = 127.0.0.1:20102 123 maxlogfiles = 100 124 125 debuglevel = debug 126 127 node = "dcrd" 128 simnet = 1 129 130 [dcrd] 131 dcrd.rpchost = localhost:19556 132 dcrd.rpcuser = ${RPCUSER} 133 dcrd.rpcpass = ${RPCPASS} 134 EOF 135 136 cat > "${NODES_ROOT}/dcrlnd2.conf" <<EOF 137 [Application Options] 138 139 datadir = ${NODES_ROOT}/dcrlnd2 140 logdir = ${NODES_ROOT}/dcrlnd2/logs 141 tlscertpath = ${NODES_ROOT}/dcrlnd2/tls.cert 142 tlskeypath = ${NODES_ROOT}/dcrlnd2/tls.key 143 rpclisten = 127.0.0.1:20200 144 restlisten = 127.0.0.1:20201 145 listen = 127.0.0.1:20202 146 maxlogfiles = 100 147 148 debuglevel = debug 149 150 node = "dcrd" 151 simnet = 1 152 153 [dcrd] 154 dcrd.rpchost = localhost:19556 155 dcrd.rpcuser = ${RPCUSER} 156 dcrd.rpcpass = ${RPCPASS} 157 EOF 158 159 160 # Scripts 161 162 cat > "${NODES_ROOT}/dcrd/ctl" <<EOF 163 #!/bin/sh 164 dcrctl -C ../dcrctl.conf \$* 165 EOF 166 chmod +x "${NODES_ROOT}/dcrd/ctl" 167 168 cat > "${NODES_ROOT}/dcrd/mine" <<EOF 169 #!/bin/sh 170 NUM=1 171 case \$1 in 172 ''|*[!0-9]*) ;; 173 *) NUM=\$1 ;; 174 esac 175 176 for i in \$(seq \$NUM) ; do 177 dcrctl -C ../dcrctl.conf generate 1 178 sleep 0.3 179 done 180 EOF 181 chmod +x "${NODES_ROOT}/dcrd/mine" 182 183 cat > "${NODES_ROOT}/wallet/ctl" <<EOF 184 #!/bin/sh 185 dcrctl -C ../dcrctl.conf --wallet -c ./data/rpc.cert \$* 186 EOF 187 chmod +x "${NODES_ROOT}/wallet/ctl" 188 189 cat > "${NODES_ROOT}/wallet/tickets" <<EOF 190 #!/bin/sh 191 NUM=1 192 case \$1 in 193 ''|*[!0-9]*) ;; 194 *) NUM=\$1 ;; 195 esac 196 197 ./ctl purchaseticket default 999999 1 \`./ctl getnewaddress\` \$NUM 198 EOF 199 chmod +x "${NODES_ROOT}/wallet/tickets" 200 201 cat > "${NODES_ROOT}/wallet/xfer" <<EOF 202 #!/bin/sh 203 ./ctl sendtoaddress ${WALLET_XFER_ADDR} 0.1 204 EOF 205 chmod +x "${NODES_ROOT}/wallet/xfer" 206 207 208 cat > "${NODES_ROOT}/dcrlnd0/ctl" <<EOF 209 #!/bin/sh 210 dcrlncli \\ 211 --simnet \\ 212 --chain decred \\ 213 --rpcserver localhost:20000 \\ 214 --lnddir ${NODES_ROOT}/dcrlnd0 \\ 215 --tlscertpath ${NODES_ROOT}/dcrlnd0/tls.cert \\ 216 --macaroonpath ${NODES_ROOT}/dcrlnd0/chain/decred/simnet/admin.macaroon \\ 217 \$* 218 EOF 219 chmod +x "${NODES_ROOT}/dcrlnd0/ctl" 220 221 222 cat > "${NODES_ROOT}/dcrlnd1/ctl" <<EOF 223 #!/bin/sh 224 dcrlncli \\ 225 --simnet \\ 226 --chain decred \\ 227 --rpcserver localhost:20100 \\ 228 --lnddir ${NODES_ROOT}/dcrlnd1 \\ 229 --tlscertpath ${NODES_ROOT}/dcrlnd1/tls.cert \\ 230 --macaroonpath ${NODES_ROOT}/dcrlnd1/chain/decred/simnet/admin.macaroon \\ 231 \$* 232 EOF 233 chmod +x "${NODES_ROOT}/dcrlnd1/ctl" 234 235 cat > "${NODES_ROOT}/dcrlnd2/ctl" <<EOF 236 #!/bin/sh 237 dcrlncli \\ 238 --simnet \\ 239 --chain decred \\ 240 --rpcserver localhost:20200 \\ 241 --lnddir ${NODES_ROOT}/dcrlnd2 \\ 242 --tlscertpath ${NODES_ROOT}/dcrlnd2/tls.cert \\ 243 --macaroonpath ${NODES_ROOT}/dcrlnd2/chain/decred/simnet/admin.macaroon \\ 244 \$* 245 EOF 246 chmod +x "${NODES_ROOT}/dcrlnd2/ctl" 247 248 function countdown { 249 secs=$1 250 while [ $secs -gt 0 ]; do 251 echo -ne "$secs \033[0K\r" 252 sleep 1 253 : $((secs--)) 254 done 255 } 256 257 258 # Start Session. 259 260 cd ${NODES_ROOT} && tmux -2 new-session -d -s $SESSION 261 tmxsend "alias a=${NODES_ROOT}/dcrlnd0/ctl" C-m 262 tmxsend "alias b=${NODES_ROOT}/dcrlnd1/ctl" C-m 263 tmxsend "alias c=${NODES_ROOT}/dcrlnd2/ctl" C-m 264 265 266 # Setup mining node. 267 268 tmux new-window -t $SESSION:1 -n 'network' 269 tmux split-window -h 270 tmux split-window -v 271 tmux select-pane -t 0 272 tmux split-window -v 273 tmux select-pane -t 0 274 275 tmxsend "cd dcrd" C-m 276 tmxsend "dcrd -C ../dcrd.conf" C-m 277 tmux select-pane -t 1 278 tmxsend "cd dcrd" C-m 279 sleep 3 280 tmxsend "./ctl generate 32" C-m 281 sleep 1 282 283 # Setup voting wallet. 284 285 tmux select-pane -t 2 286 tmxsend "cd wallet" C-m 287 tmux send-keys -t $SESSION "echo \"${WALLET_CREATE_CONFIG}\" | dcrwallet -C ../wallet.conf --create; tmux wait-for -S wallet" C-m 288 tmux wait-for "wallet" 289 sleep 1 290 tmxsend "dcrwallet -C ../wallet.conf" C-m 291 tmux select-pane -t 3 292 tmxsend "cd wallet" C-m 293 294 295 # Bring up ln nodes. 296 297 tmux new-window -t $SESSION:2 -n 'dcrlnd0' 298 tmxsend "${DCRLND_BIN} --configfile ${NODES_ROOT}/dcrlnd0.conf" C-m 299 tmux split-window -v 300 tmxsend "cd ${NODES_ROOT}/dcrlnd0" C-m 301 302 tmux new-window -t $SESSION:3 -n 'dcrlnd1' 303 tmxsend "${DCRLND_BIN} --configfile ${NODES_ROOT}/dcrlnd1.conf" C-m 304 tmux split-window -v 305 tmxsend "cd ${NODES_ROOT}/dcrlnd1" C-m 306 307 tmux new-window -t $SESSION:4 -n 'dcrlnd2' 308 tmxsend "${DCRLND_BIN} --configfile ${NODES_ROOT}/dcrlnd2.conf" C-m 309 tmux split-window -v 310 tmxsend "cd ${NODES_ROOT}/dcrlnd2" C-m 311 312 # Wait for nodes to query for pwd. 313 echo "Waiting for dcrlnd nodes to initialize" 314 countdown 5 315 316 # Create lnd wallets. 317 318 tmux select-window -t 2 319 tmxsend "./ctl create" C-m 320 sleep 3 321 tmxsend "12345678" C-m "12345678" C-m 322 323 tmux select-window -t 3 324 tmxsend "./ctl create" C-m 325 sleep 3 326 tmxsend "12345678" C-m "12345678" C-m 327 328 tmux select-window -t 4 329 tmxsend "./ctl create" C-m 330 sleep 3 331 tmxsend "12345678" C-m "12345678" C-m 332 333 # Wait for seed input. 334 echo "Waiting to input seed" 335 countdown 3 336 337 338 # Seed input lnd wallets. 339 tmux select-window -t 2 340 tmxsend "y" C-m 341 sleep 2 342 tmxsend "${NODE0_SEED}" C-m C-m C-m 343 tmux select-window -t 3 344 tmxsend "y" C-m 345 sleep 2 346 tmxsend "${NODE1_SEED}" C-m C-m C-m 347 tmux select-window -t 4 348 tmxsend "y" C-m 349 sleep 2 350 tmxsend "${NODE2_SEED}" C-m C-m C-m 351 352 echo "Waiting for nodes to sync up" 353 countdown 5 354 355 # Send coins to all nodes and mine them. 356 addr0=`${NODES_ROOT}/dcrlnd0/ctl newaddress p2pkh | jq .address` 357 addr1=`${NODES_ROOT}/dcrlnd1/ctl newaddress p2pkh | jq .address` 358 addr2=`${NODES_ROOT}/dcrlnd2/ctl newaddress p2pkh | jq .address` 359 tmux select-window -t 1 360 tmxsend "./ctl sendtoaddress $addr0 10" C-m 361 tmxsend "./ctl sendtoaddress $addr1 10" C-m 362 tmxsend "./ctl sendtoaddress $addr2 10" C-m 363 tmux select-pane -t 1 364 tmxsend "./mine 3" C-m 365 366 echo "Waiting for lnd wallets to catch up" 367 countdown 3 368 369 # Connect nodes and open a channel node0 => node1. 370 tmux select-window -t 2 371 sleep 0.5 372 tmxsend "./ctl connect ${NODE1_PUBID}@127.0.0.1:20102" C-m 373 tmxsend "./ctl openchannel ${NODE1_PUBID} 10000000 5000000" C-m 374 375 # Connect nodes and open a channel node2 => node1. 376 tmux select-window -t 4 377 sleep 0.5 378 tmxsend "./ctl connect ${NODE1_PUBID}@127.0.0.1:20102" C-m 379 tmxsend "./ctl openchannel ${NODE1_PUBID} 10000000 3000000" C-m 380 381 echo "Waiting for funding txs to be broadcast" 382 countdown 3 383 384 # Mine the new channel txs 385 tmux select-window -t 1 386 tmxsend "./mine 8" C-m 387 388 echo "Attaching to session '$SESSION'" 389 tmux attach-session