decred.org/dcrdex@v1.0.5/dex/testing/eth/create-node.sh (about) 1 #!/usr/bin/env bash 2 # Script for creating eth nodes. 3 set -ex 4 5 # The following are required script arguments. 6 TMUX_WIN_ID=$1 7 NAME=$2 8 NODE_PORT=$3 9 CHAIN_ADDRESS=$4 10 CHAIN_PASSWORD=$5 11 CHAIN_ADDRESS_JSON=$6 12 CHAIN_ADDRESS_JSON_FILE_NAME=$7 13 ADDRESS_JSON=$8 14 ADDRESS_JSON_FILE_NAME=$9 15 NODE_KEY=${10} 16 SYNC_MODE=${11} 17 AUTHRPC_PORT=${12} 18 HTTP_PORT=${13} 19 WS_PORT=${14} 20 WS_MODULES=${15} 21 22 GROUP_DIR="${NODES_ROOT}/${NAME}" 23 MINE_JS="${GROUP_DIR}/mine.js" 24 NODE_DIR="${GROUP_DIR}/node" 25 mkdir -p "${NODE_DIR}" 26 mkdir -p "${NODE_DIR}/keystore" 27 mkdir -p "${NODE_DIR}/geth" 28 29 # Write node ctl script. 30 cat > "${NODES_ROOT}/harness-ctl/${NAME}" <<EOF 31 #!/usr/bin/env bash 32 geth --datadir="${NODE_DIR}" \$* 33 EOF 34 chmod +x "${NODES_ROOT}/harness-ctl/${NAME}" 35 36 # Write mine script if CHAIN_ADDRESS is present. 37 if [ "${CHAIN_ADDRESS}" != "_" ]; then 38 # The mining script may end up mining more or less blocks than specified. 39 cat > "${NODES_ROOT}/harness-ctl/mine-${NAME}" <<EOF 40 #!/usr/bin/env bash 41 NUM=2 42 case \$1 in 43 ''|*[!0-9]*|[0-1]) ;; 44 *) NUM=\$1 ;; 45 esac 46 echo "Mining..." 47 BEFORE=\$("${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.blockNumber') 48 "${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'miner.start()' > /dev/null 49 sleep \$(echo "\$NUM-1.8" | bc) 50 "${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'miner.stop()' > /dev/null 51 sleep 1 52 AFTER=\$("${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.blockNumber') 53 DIFF=\$((AFTER-BEFORE)) 54 echo "Mined \$DIFF blocks on ${NAME}. Their hashes:" 55 for i in \$(seq \$((BEFORE+1)) \$AFTER) 56 do 57 echo \$i 58 "${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.getHeaderByNumber('\$i').hash' 59 done 60 EOF 61 chmod +x "${NODES_ROOT}/harness-ctl/mine-${NAME}" 62 63 # Write password file to unlock accounts later. 64 cat > "${GROUP_DIR}/password" <<EOF 65 $CHAIN_PASSWORD 66 EOF 67 68 fi 69 70 cat > "${NODE_DIR}/eth.conf" <<EOF 71 [Eth] 72 NetworkId = 42 73 SyncMode = "${SYNC_MODE}" 74 75 [Node] 76 DataDir = "${NODE_DIR}" 77 AuthPort = ${AUTHRPC_PORT} 78 79 [Node.P2P] 80 NoDiscovery = true 81 BootstrapNodes = [] 82 BootstrapNodesV5 = [] 83 ListenAddr = ":${NODE_PORT}" 84 NetRestrict = [ "127.0.0.1/8", "::1/128" ] 85 EOF 86 87 # Add etherbase if mining. 88 if [ "${CHAIN_ADDRESS}" != "_" ]; then 89 cat >> "${NODE_DIR}/eth.conf" <<EOF 90 91 [Eth.Miner] 92 Etherbase = "0x${CHAIN_ADDRESS}" 93 GasFloor = 30000000 94 GasCeil = 30000000 95 EOF 96 fi 97 98 # Create a tmux window. 99 tmux new-window -t "$TMUX_WIN_ID" -n "${NAME}" "${SHELL}" 100 tmux send-keys -t "$TMUX_WIN_ID" "set +o history" C-m 101 tmux send-keys -t "$TMUX_WIN_ID" "cd ${NODE_DIR}" C-m 102 103 # Create and wait for a node initiated with a predefined genesis json. 104 echo "Creating simnet ${NAME} node" 105 tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} init "\ 106 "$GENESIS_JSON_FILE_LOCATION; tmux wait-for -S ${NAME}" C-m 107 tmux wait-for "${NAME}" 108 109 # Create two accounts. The first is used to mine blocks. The second contains 110 # funds. 111 if [ "${CHAIN_ADDRESS}" != "_" ]; then 112 echo "Creating account" 113 cat > "${NODE_DIR}/keystore/$CHAIN_ADDRESS_JSON_FILE_NAME" <<EOF 114 $CHAIN_ADDRESS_JSON 115 EOF 116 fi 117 118 cat > "${NODE_DIR}/keystore/$ADDRESS_JSON_FILE_NAME" <<EOF 119 $ADDRESS_JSON 120 EOF 121 122 # The node key lets us control the enode address value. 123 echo "Setting node key" 124 cat > "${NODE_DIR}/geth/nodekey" <<EOF 125 $NODE_KEY 126 EOF 127 128 echo "Starting simnet ${NAME} node" 129 if [ "${SYNC_MODE}" = "snap" ]; then 130 # Start the eth node with the chain account unlocked, listening restricted to 131 # localhost, and our custom configuration file. 132 tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} " \ 133 "--config ${NODE_DIR}/eth.conf --unlock ${CHAIN_ADDRESS} " \ 134 "--password ${GROUP_DIR}/password --light.serve 25 --datadir.ancient " \ 135 "${NODE_DIR}/geth-ancient --verbosity 5 --vmdebug --http --http.port " \ 136 "${HTTP_PORT} --ws --ws.port ${WS_PORT} --ws.api " \ 137 "${WS_MODULES} --allow-insecure-unlock --rpc.enabledeprecatedpersonal " \ 138 "2>&1 | tee ${NODE_DIR}/${NAME}.log" C-m 139 140 else 141 # Start the eth node listening restricted to localhost and our custom 142 # configuration file. 143 tmux send-keys -t "$TMUX_WIN_ID" "${NODES_ROOT}/harness-ctl/${NAME} --allow-insecure-unlock --rpc.enabledeprecatedpersonal " \ 144 "--config ${NODE_DIR}/eth.conf --verbosity 5 ${HTTP_OPT} 2>&1 | tee " \ 145 "${NODE_DIR}/${NAME}.log" C-m 146 fi