Skip to content

Instantly share code, notes, and snippets.

@davecgh
Last active November 13, 2018 06:25
Show Gist options
  • Save davecgh/7bb5c995665787811dc6a6ddbb49688d to your computer and use it in GitHub Desktop.
Save davecgh/7bb5c995665787811dc6a6ddbb49688d to your computer and use it in GitHub Desktop.
Script to create a sample 8 node Decred simnet network
#!/bin/sh
set -e
SIMNET_NODES_ROOT=~/dcrdsimnetnodes
MASTERNODE_ADDR=127.0.0.1:19555
NODE1_ADDR=127.0.0.1:19501
NODE2_ADDR=127.0.0.1:19502
NODE3_ADDR=127.0.0.1:19503
NODE4_ADDR=127.0.0.1:19504
NODE5_ADDR=127.0.0.1:19505
NODE6_ADDR=127.0.0.1:19506
NODE7_ADDR=127.0.0.1:19507
RPCUSER="USER"
RPCPASS="PASS"
WALLET_SEED="b280922d2cffda44648346412c5ec97f429938105003730414f10b01e1402eac"
WALLET_MINING_ADDR="SsWKp7wtdTZYabYFYSc9cnxhwFEjA5g4pFc" # NOTE: This must be changed if the seed is changed.
mkdir -p "${SIMNET_NODES_ROOT}/"{master,1,2,3,4,5,6,7,wallet}
# masternode.conf
cat > "${SIMNET_NODES_ROOT}/masternode.conf" <<EOF
rpcuser=${RPCUSER}
rpcpass=${RPCPASS}
simnet=1
logdir=${SIMNET_NODES_ROOT}/master/log
datadir=${SIMNET_NODES_ROOT}/master/data
listen=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE2_ADDR}
connect=${NODE3_ADDR}
connect=${NODE4_ADDR}
connect=${NODE5_ADDR}
connect=${NODE6_ADDR}
connect=${NODE7_ADDR}
miningaddr=${WALLET_MINING_ADDR}
EOF
# node1.conf
cat > "${SIMNET_NODES_ROOT}/node1.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/1/log
datadir=${SIMNET_NODES_ROOT}/1/data
listen=${NODE1_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE2_ADDR}
connect=${NODE3_ADDR}
connect=${NODE4_ADDR}
connect=${NODE5_ADDR}
connect=${NODE6_ADDR}
connect=${NODE7_ADDR}
EOF
# node2.conf
cat > "${SIMNET_NODES_ROOT}/node2.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/2/log
datadir=${SIMNET_NODES_ROOT}/2/data
listen=${NODE2_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE3_ADDR}
connect=${NODE4_ADDR}
connect=${NODE5_ADDR}
connect=${NODE6_ADDR}
connect=${NODE7_ADDR}
EOF
# node3.conf
cat > "${SIMNET_NODES_ROOT}/node3.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/3/log
datadir=${SIMNET_NODES_ROOT}/3/data
listen=${NODE3_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE2_ADDR}
connect=${NODE4_ADDR}
connect=${NODE5_ADDR}
connect=${NODE6_ADDR}
connect=${NODE7_ADDR}
EOF
# node4.conf
cat > "${SIMNET_NODES_ROOT}/node4.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/4/log
datadir=${SIMNET_NODES_ROOT}/4/data
listen=${NODE4_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE2_ADDR}
connect=${NODE3_ADDR}
connect=${NODE5_ADDR}
connect=${NODE6_ADDR}
connect=${NODE7_ADDR}
EOF
# node5.conf
cat > "${SIMNET_NODES_ROOT}/node5.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/5/log
datadir=${SIMNET_NODES_ROOT}/5/data
listen=${NODE5_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE2_ADDR}
connect=${NODE3_ADDR}
connect=${NODE4_ADDR}
connect=${NODE6_ADDR}
connect=${NODE7_ADDR}
EOF
# node6.conf
cat > "${SIMNET_NODES_ROOT}/node6.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/6/log
datadir=${SIMNET_NODES_ROOT}/6/data
listen=${NODE6_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE2_ADDR}
connect=${NODE3_ADDR}
connect=${NODE4_ADDR}
connect=${NODE5_ADDR}
connect=${NODE7_ADDR}
EOF
# node7.conf
cat > "${SIMNET_NODES_ROOT}/node7.conf" <<EOF
simnet=1
logdir=${SIMNET_NODES_ROOT}/7/log
datadir=${SIMNET_NODES_ROOT}/7/data
listen=${NODE7_ADDR}
connect=${MASTERNODE_ADDR}
connect=${NODE1_ADDR}
connect=${NODE2_ADDR}
connect=${NODE3_ADDR}
connect=${NODE4_ADDR}
connect=${NODE5_ADDR}
connect=${NODE6_ADDR}
EOF
# dcrctl.conf
cat > "${SIMNET_NODES_ROOT}/dcrctl.conf" <<EOF
simnet=1
rpcuser=${RPCUSER}
rpcpass=${RPCPASS}
EOF
# dcrwallet.conf
cat > "${SIMNET_NODES_ROOT}/dcrwallet.conf" <<EOF
simnet=1
username=${RPCUSER}
password=${RPCPASS}
appdata=${SIMNET_NODES_ROOT}/wallet
promptpass=1
enablevoting=1
enableticketbuyer=1
ticketbuyer.nospreadticketpurchases=1
ticketbuyer.maxperblock=5
EOF
# dcrctlw.conf
cat > "${SIMNET_NODES_ROOT}/dcrctlw.conf" <<EOF
simnet=1
wallet=1
rpcuser=${RPCUSER}
rpcpass=${RPCPASS}
rpccert=${SIMNET_NODES_ROOT}/wallet/rpc.cert
EOF
echo "Launch the dcrd simnet instances with the following config files:"
echo "dcrd -C ${SIMNET_NODES_ROOT}/masternode.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node1.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node2.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node3.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node4.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node5.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node6.conf"
echo "dcrd -C ${SIMNET_NODES_ROOT}/node7.conf"
echo ""
echo "Create the wallet -- MAKE SURE TO USE THE PRINTED SEED!!!"
echo "dcrwallet -C ${SIMNET_NODES_ROOT}/dcrwallet.conf --create"
echo "Seed: ${WALLET_SEED}"
echo ""
echo "Launch the wallet:"
echo "dcrwallet -C ${SIMNET_NODES_ROOT}/dcrwallet.conf"
echo ""
echo "To interface with the master dcrd node via dcrctl:"
echo "dcrctl -C ${SIMNET_NODES_ROOT}/dcrctl.conf <command>"
echo ""
echo "To interface with the wallet via dcrctl:"
echo "dcrctl -C ${SIMNET_NODES_ROOT}/dcrctlw.conf <command>"
echo ""
echo "To generate blocks with the CPU miner via dcrctl:"
echo "dcrctl -C ${SIMNET_NODES_ROOT}/dcrctl.conf generate 1"
echo ""
echo "NOTE: Because the simnet difficulty is so low, the blocks will be found"
echo "faster than the tickets can be purchased during the initial bringup, so"
echo "it is recommended to generate enough blocks to reach the voting height"
echo "with a script that sleeps after each block is generated as follows:"
echo ""
echo "for i in \$(seq 1 1 144); do"
echo "dcrctl -C ${SIMNET_NODES_ROOT}/dcrctl.conf generate 1"
echo "sleep 1"
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment